chore: split playwright.fixtures into files (#3982)
This commit is contained in:
parent
59daaab1c6
commit
5b9f489e55
70
test/http.fixtures.ts
Normal file
70
test/http.fixtures.ts
Normal file
|
|
@ -0,0 +1,70 @@
|
||||||
|
/**
|
||||||
|
* Copyright Microsoft Corporation. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { fixtures as baseFixtures } from '@playwright/test-runner';
|
||||||
|
import path from 'path';
|
||||||
|
import { TestServer } from '../utils/testserver';
|
||||||
|
export { expect } from '@playwright/test';
|
||||||
|
export { config } from '@playwright/test-runner';
|
||||||
|
|
||||||
|
type HttpWorkerFixtures = {
|
||||||
|
asset: (path: string) => string;
|
||||||
|
httpService: { server: TestServer, httpsServer: TestServer };
|
||||||
|
};
|
||||||
|
|
||||||
|
type HttpTestFixtures = {
|
||||||
|
server: TestServer;
|
||||||
|
httpsServer: TestServer;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const fixtures = baseFixtures
|
||||||
|
.declareWorkerFixtures<HttpWorkerFixtures>()
|
||||||
|
.declareTestFixtures<HttpTestFixtures>();
|
||||||
|
const { defineTestFixture, defineWorkerFixture } = fixtures;
|
||||||
|
|
||||||
|
defineWorkerFixture('httpService', async ({ testWorkerIndex }, test) => {
|
||||||
|
const assetsPath = path.join(__dirname, 'assets');
|
||||||
|
const cachedPath = path.join(__dirname, 'assets', 'cached');
|
||||||
|
|
||||||
|
const port = 8907 + testWorkerIndex * 2;
|
||||||
|
const server = await TestServer.create(assetsPath, port);
|
||||||
|
server.enableHTTPCache(cachedPath);
|
||||||
|
|
||||||
|
const httpsPort = port + 1;
|
||||||
|
const httpsServer = await TestServer.createHTTPS(assetsPath, httpsPort);
|
||||||
|
httpsServer.enableHTTPCache(cachedPath);
|
||||||
|
|
||||||
|
await test({server, httpsServer});
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
server.stop(),
|
||||||
|
httpsServer.stop(),
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
defineTestFixture('server', async ({httpService}, test) => {
|
||||||
|
httpService.server.reset();
|
||||||
|
await test(httpService.server);
|
||||||
|
});
|
||||||
|
|
||||||
|
defineTestFixture('httpsServer', async ({httpService}, test) => {
|
||||||
|
httpService.httpsServer.reset();
|
||||||
|
await test(httpService.httpsServer);
|
||||||
|
});
|
||||||
|
|
||||||
|
defineWorkerFixture('asset', async ({}, test) => {
|
||||||
|
await test(p => path.join(__dirname, `assets`, p));
|
||||||
|
});
|
||||||
|
|
@ -14,19 +14,19 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import fs from 'fs';
|
import { expect } from '@playwright/test';
|
||||||
import path from 'path';
|
import { config } from '@playwright/test-runner';
|
||||||
import os from 'os';
|
import { fixtures as httpFixtures } from './http.fixtures';
|
||||||
import util from 'util';
|
import assert from 'assert';
|
||||||
import childProcess from 'child_process';
|
import childProcess from 'child_process';
|
||||||
import type { LaunchOptions, BrowserType, Browser, BrowserContext, Page, Frame, BrowserServer, BrowserContextOptions } from '../index';
|
import fs from 'fs';
|
||||||
import { TestServer } from '../utils/testserver';
|
import os from 'os';
|
||||||
|
import path from 'path';
|
||||||
|
import util from 'util';
|
||||||
|
import type { Browser, BrowserContext, BrowserContextOptions, BrowserServer, BrowserType, Frame, LaunchOptions, Page } from '../index';
|
||||||
import { Connection } from '../lib/client/connection';
|
import { Connection } from '../lib/client/connection';
|
||||||
import { Transport } from '../lib/protocol/transport';
|
import { Transport } from '../lib/protocol/transport';
|
||||||
import { installCoverageHooks } from './coverage';
|
import { installCoverageHooks } from './coverage';
|
||||||
import { fixtures as baseFixtures, config } from '@playwright/test-runner';
|
|
||||||
import assert from 'assert';
|
|
||||||
import { expect } from '@playwright/test';
|
|
||||||
export { expect } from '@playwright/test';
|
export { expect } from '@playwright/test';
|
||||||
export { config } from '@playwright/test-runner';
|
export { config } from '@playwright/test-runner';
|
||||||
|
|
||||||
|
|
@ -39,13 +39,11 @@ type PlaywrightParameters = {
|
||||||
};
|
};
|
||||||
|
|
||||||
type PlaywrightWorkerFixtures = {
|
type PlaywrightWorkerFixtures = {
|
||||||
asset: (path: string) => string;
|
|
||||||
defaultBrowserOptions: LaunchOptions;
|
defaultBrowserOptions: LaunchOptions;
|
||||||
golden: (path: string) => string;
|
golden: (path: string) => string;
|
||||||
playwright: typeof import('../index');
|
playwright: typeof import('../index');
|
||||||
browserType: BrowserType<Browser>;
|
browserType: BrowserType<Browser>;
|
||||||
browser: Browser;
|
browser: Browser;
|
||||||
httpService: {server: TestServer, httpsServer: TestServer}
|
|
||||||
domain: void;
|
domain: void;
|
||||||
toImpl: (rpcObject: any) => any;
|
toImpl: (rpcObject: any) => any;
|
||||||
isChromium: boolean;
|
isChromium: boolean;
|
||||||
|
|
@ -59,9 +57,7 @@ type PlaywrightWorkerFixtures = {
|
||||||
|
|
||||||
type PlaywrightTestFixtures = {
|
type PlaywrightTestFixtures = {
|
||||||
context: BrowserContext;
|
context: BrowserContext;
|
||||||
server: TestServer;
|
|
||||||
page: Page;
|
page: Page;
|
||||||
httpsServer: TestServer;
|
|
||||||
browserServer: BrowserServer;
|
browserServer: BrowserServer;
|
||||||
testOutputDir: string;
|
testOutputDir: string;
|
||||||
tmpDir: string;
|
tmpDir: string;
|
||||||
|
|
@ -69,7 +65,7 @@ type PlaywrightTestFixtures = {
|
||||||
launchPersistent: (options?: Parameters<BrowserType<Browser>['launchPersistentContext']>[1]) => Promise<{context: BrowserContext, page: Page}>;
|
launchPersistent: (options?: Parameters<BrowserType<Browser>['launchPersistentContext']>[1]) => Promise<{context: BrowserContext, page: Page}>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const fixtures = baseFixtures
|
const fixtures = httpFixtures
|
||||||
.declareParameters<PlaywrightParameters>()
|
.declareParameters<PlaywrightParameters>()
|
||||||
.declareWorkerFixtures<PlaywrightWorkerFixtures>()
|
.declareWorkerFixtures<PlaywrightWorkerFixtures>()
|
||||||
.declareTestFixtures<PlaywrightTestFixtures>();
|
.declareTestFixtures<PlaywrightTestFixtures>();
|
||||||
|
|
@ -100,26 +96,6 @@ export const options = {
|
||||||
TRACING: valueFromEnv('TRACING', false),
|
TRACING: valueFromEnv('TRACING', false),
|
||||||
};
|
};
|
||||||
|
|
||||||
defineWorkerFixture('httpService', async ({ testWorkerIndex }, test) => {
|
|
||||||
const assetsPath = path.join(__dirname, 'assets');
|
|
||||||
const cachedPath = path.join(__dirname, 'assets', 'cached');
|
|
||||||
|
|
||||||
const port = 8907 + testWorkerIndex * 2;
|
|
||||||
const server = await TestServer.create(assetsPath, port);
|
|
||||||
server.enableHTTPCache(cachedPath);
|
|
||||||
|
|
||||||
const httpsPort = port + 1;
|
|
||||||
const httpsServer = await TestServer.createHTTPS(assetsPath, httpsPort);
|
|
||||||
httpsServer.enableHTTPCache(cachedPath);
|
|
||||||
|
|
||||||
await test({server, httpsServer});
|
|
||||||
|
|
||||||
await Promise.all([
|
|
||||||
server.stop(),
|
|
||||||
httpsServer.stop(),
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
const getExecutablePath = browserName => {
|
const getExecutablePath = browserName => {
|
||||||
if (browserName === 'chromium' && process.env.CRPATH)
|
if (browserName === 'chromium' && process.env.CRPATH)
|
||||||
return process.env.CRPATH;
|
return process.env.CRPATH;
|
||||||
|
|
@ -237,15 +213,11 @@ defineWorkerFixture('browser', async ({browserType, defaultBrowserOptions}, test
|
||||||
await browser.close();
|
await browser.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
defineWorkerFixture('asset', async ({}, test) => {
|
|
||||||
await test(p => path.join(__dirname, `assets`, p));
|
|
||||||
});
|
|
||||||
|
|
||||||
defineWorkerFixture('golden', async ({browserName}, test) => {
|
defineWorkerFixture('golden', async ({browserName}, test) => {
|
||||||
await test(p => path.join(browserName, p));
|
await test(p => path.join(browserName, p));
|
||||||
});
|
});
|
||||||
|
|
||||||
defineWorkerFixture('expectedSSLError', async ({browserName, platform}, runTest) => {
|
defineWorkerFixture('expectedSSLError', async ({ browserName, platform }, runTest) => {
|
||||||
let expectedSSLError: string;
|
let expectedSSLError: string;
|
||||||
if (browserName === 'chromium') {
|
if (browserName === 'chromium') {
|
||||||
expectedSSLError = 'net::ERR_CERT_AUTHORITY_INVALID';
|
expectedSSLError = 'net::ERR_CERT_AUTHORITY_INVALID';
|
||||||
|
|
@ -325,16 +297,6 @@ defineTestFixture('launchPersistent', async ({createUserDataDir, defaultBrowserO
|
||||||
await context.close();
|
await context.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
defineTestFixture('server', async ({httpService}, test) => {
|
|
||||||
httpService.server.reset();
|
|
||||||
await test(httpService.server);
|
|
||||||
});
|
|
||||||
|
|
||||||
defineTestFixture('httpsServer', async ({httpService}, test) => {
|
|
||||||
httpService.httpsServer.reset();
|
|
||||||
await test(httpService.httpsServer);
|
|
||||||
});
|
|
||||||
|
|
||||||
defineTestFixture('tmpDir', async ({}, test) => {
|
defineTestFixture('tmpDir', async ({}, test) => {
|
||||||
const tmpDir = await mkdtempAsync(path.join(os.tmpdir(), 'playwright-test-'));
|
const tmpDir = await mkdtempAsync(path.join(os.tmpdir(), 'playwright-test-'));
|
||||||
await test(tmpDir);
|
await test(tmpDir);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue