diff --git a/test/platform.fixtures.ts b/test/platform.fixtures.ts new file mode 100644 index 0000000000000..c493e3d485a2b --- /dev/null +++ b/test/platform.fixtures.ts @@ -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() + .declareWorkerFixtures(); +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'); +}); diff --git a/test/playwright.fixtures.ts b/test/playwright.fixtures.ts index 1c50679aa421d..51f02cca3b4d4 100644 --- a/test/playwright.fixtures.ts +++ b/test/playwright.fixtures.ts @@ -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['launchPersistentContext']>[1]) => Promise<{context: BrowserContext, page: Page}>; }; -const fixtures = httpFixtures +const fixtures = httpFixtures.union(platformFixtures) .declareParameters() .declareWorkerFixtures() .declareTestFixtures(); @@ -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);