Skip to content

Commit

Permalink
chore: split playwright.fixtures into files (2) (#3983)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman authored Sep 26, 2020
1 parent 5b9f489 commit 76be954
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 26 deletions.
56 changes: 56 additions & 0 deletions test/platform.fixtures.ts
Original file line number Diff line number Diff line change
@@ -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');
});
29 changes: 3 additions & 26 deletions test/playwright.fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -34,7 +35,6 @@ const mkdtempAsync = util.promisify(fs.mkdtemp);
const removeFolderAsync = util.promisify(require('rimraf'));

type PlaywrightParameters = {
platform: 'win32' | 'linux' | 'darwin'
browserName: string;
};

Expand All @@ -49,9 +49,6 @@ type PlaywrightWorkerFixtures = {
isChromium: boolean;
isFirefox: boolean;
isWebKit: boolean;
isWindows: boolean;
isMac: boolean;
isLinux: boolean;
expectedSSLError: string;
};

Expand All @@ -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>();
Expand All @@ -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 => {
Expand Down Expand Up @@ -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');
});
Expand All @@ -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);
Expand Down

0 comments on commit 76be954

Please sign in to comment.