chore: split playwright.fixtures into files (2) (#3983)

This commit is contained in:
Pavel Feldman 2020-09-25 21:43:52 -07:00 committed by GitHub
parent 5b9f489e55
commit 76be9540d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 59 additions and 26 deletions

56
test/platform.fixtures.ts Normal file
View File

@ -0,0 +1,56 @@
/**
* 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';
type PlatformParameters = {
platform: 'win32' | 'linux' | 'darwin'
};
type PlatformWorkerFixtures = {
isWindows: boolean;
isMac: boolean;
isLinux: boolean;
};
export const fixtures = baseFixtures
.declareParameters<PlatformParameters>()
.declareWorkerFixtures<PlatformWorkerFixtures>();
const { defineWorkerFixture, defineParameter, generateParametrizedTests } = fixtures;
export const options = {
MAC: (parameters: PlatformParameters) => parameters.platform === 'darwin',
LINUX: (parameters: PlatformParameters) => parameters.platform === 'linux',
WIN: (parameters: PlatformParameters) => parameters.platform === 'win32',
};
defineParameter('platform', 'Operating system', process.platform as ('win32' | 'linux' | 'darwin'));
generateParametrizedTests(
'platform',
process.env.PWTESTREPORT ? ['win32', 'darwin', 'linux'] : [process.platform as ('win32' | 'linux' | 'darwin')]);
defineWorkerFixture('isWindows', async ({platform}, test) => {
await test(platform === 'win32');
});
defineWorkerFixture('isMac', async ({platform}, test) => {
await test(platform === 'darwin');
});
defineWorkerFixture('isLinux', async ({platform}, test) => {
await test(platform === 'linux');
});

View File

@ -17,6 +17,7 @@
import { expect } from '@playwright/test';
import { config } from '@playwright/test-runner';
import { fixtures as httpFixtures } from './http.fixtures';
import { fixtures as platformFixtures, options as platformOptions } from './platform.fixtures';
import assert from 'assert';
import childProcess from 'child_process';
import fs from 'fs';
@ -34,7 +35,6 @@ const mkdtempAsync = util.promisify(fs.mkdtemp);
const removeFolderAsync = util.promisify(require('rimraf'));
type PlaywrightParameters = {
platform: 'win32' | 'linux' | 'darwin'
browserName: string;
};
@ -49,9 +49,6 @@ type PlaywrightWorkerFixtures = {
isChromium: boolean;
isFirefox: boolean;
isWebKit: boolean;
isWindows: boolean;
isMac: boolean;
isLinux: boolean;
expectedSSLError: string;
};
@ -65,7 +62,7 @@ type PlaywrightTestFixtures = {
launchPersistent: (options?: Parameters<BrowserType<Browser>['launchPersistentContext']>[1]) => Promise<{context: BrowserContext, page: Page}>;
};
const fixtures = httpFixtures
const fixtures = httpFixtures.union(platformFixtures)
.declareParameters<PlaywrightParameters>()
.declareWorkerFixtures<PlaywrightWorkerFixtures>()
.declareTestFixtures<PlaywrightTestFixtures>();
@ -87,13 +84,11 @@ export const options = {
CHROMIUM: (parameters: PlaywrightParameters) => parameters.browserName === 'chromium',
FIREFOX: (parameters: PlaywrightParameters) => parameters.browserName === 'firefox',
WEBKIT: (parameters: PlaywrightParameters) => parameters.browserName === 'webkit',
MAC: (parameters: PlaywrightParameters) => parameters.platform === 'darwin',
LINUX: (parameters: PlaywrightParameters) => parameters.platform === 'linux',
WIN: (parameters: PlaywrightParameters) => parameters.platform === 'win32',
HEADLESS: !!valueFromEnv('HEADLESS', true),
WIRE: !!process.env.PWWIRE,
SLOW_MO: valueFromEnv('SLOW_MO', 0),
TRACING: valueFromEnv('TRACING', false),
...platformOptions,
};
const getExecutablePath = browserName => {
@ -169,16 +164,10 @@ defineWorkerFixture('browserType', async ({playwright, browserName}, test) => {
defineParameter('browserName', 'Browser type name', '');
defineParameter('platform', 'Operating system', process.platform as ('win32' | 'linux' | 'darwin'));
generateParametrizedTests(
'browserName',
process.env.BROWSER ? [process.env.BROWSER] : ['chromium', 'webkit', 'firefox']);
generateParametrizedTests(
'platform',
process.env.PWTESTREPORT ? ['win32', 'darwin', 'linux'] : [process.platform as ('win32' | 'linux' | 'darwin')]);
defineWorkerFixture('isChromium', async ({browserName}, test) => {
await test(browserName === 'chromium');
});
@ -191,18 +180,6 @@ defineWorkerFixture('isWebKit', async ({browserName}, test) => {
await test(browserName === 'webkit');
});
defineWorkerFixture('isWindows', async ({platform}, test) => {
await test(platform === 'win32');
});
defineWorkerFixture('isMac', async ({platform}, test) => {
await test(platform === 'darwin');
});
defineWorkerFixture('isLinux', async ({platform}, test) => {
await test(platform === 'linux');
});
defineWorkerFixture('browser', async ({browserType, defaultBrowserOptions}, test) => {
const browser = await browserType.launch(defaultBrowserOptions);
await test(browser);