diff --git a/package-lock.json b/package-lock.json index a852af0a6d..2dce5769d3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3650,9 +3650,9 @@ } }, "folio": { - "version": "0.3.6", - "resolved": "https://registry.npmjs.org/folio/-/folio-0.3.6.tgz", - "integrity": "sha512-LPi0B9HHxdqCAvwgZOdcmPufJX4PjWbS2VN1QbN3mzapMoM1j+OI30YV5fU3e+4krJn50rKuki5WL6gdRIcJlQ==", + "version": "0.3.8", + "resolved": "https://registry.npmjs.org/folio/-/folio-0.3.8.tgz", + "integrity": "sha512-7dD6dJJ/oJBQXoFo4Xui7rrmF/FUW/UIgGBYSdpk5luYcCP26TsYBWz2mF+fJGwuIajbipoeieT+9NWsHz+iQA==", "dev": true, "requires": { "@babel/code-frame": "^7.10.4", diff --git a/package.json b/package.json index 0e97ee6d93..8f394205c3 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ "electron": "^9.2.1", "eslint": "^7.7.0", "eslint-plugin-notice": "^0.9.10", - "folio": "=0.3.6", + "folio": "=0.3.8", "formidable": "^1.2.2", "ncp": "^2.0.0", "node-stream-zip": "^1.11.3", diff --git a/test/channels.spec.ts b/test/channels.spec.ts index b1bdd0eec8..43ce011251 100644 --- a/test/channels.spec.ts +++ b/test/channels.spec.ts @@ -19,8 +19,8 @@ import domain from 'domain'; import { folio } from './fixtures'; import type { ChromiumBrowser } from '..'; -const fixtures = folio.extend<{ domain: any }, {}>(); -fixtures.domain.initWorker(async ({ }, run) => { +const fixtures = folio.extend<{ domain: any }>(); +fixtures.domain.init(async ({ }, run) => { const local = domain.create(); local.run(() => { }); let err; @@ -28,7 +28,7 @@ fixtures.domain.initWorker(async ({ }, run) => { await run(null); if (err) throw err; -}); +}, { scope: 'worker' }); const { it, expect } = fixtures.build(); it('should work', async ({browser}) => { diff --git a/test/chromium/oopif.spec.ts b/test/chromium/oopif.spec.ts index ca930d3968..4fb1c212bf 100644 --- a/test/chromium/oopif.spec.ts +++ b/test/chromium/oopif.spec.ts @@ -17,7 +17,7 @@ import { folio } from '../fixtures'; const fixtures = folio.extend(); -fixtures.browser.overrideWorker(async ({browserType, defaultBrowserOptions}, run) => { +fixtures.browser.override(async ({browserType, defaultBrowserOptions}, run) => { const browser = await browserType.launch({ ...defaultBrowserOptions, args: (defaultBrowserOptions.args || []).concat(['--site-per-process']) diff --git a/test/chromium/tracing.spec.ts b/test/chromium/tracing.spec.ts index e97aa365a9..66eff19e13 100644 --- a/test/chromium/tracing.spec.ts +++ b/test/chromium/tracing.spec.ts @@ -23,7 +23,7 @@ type TestState = { outputTraceFile: string; }; const fixtures = folio.extend<{}, TestState>(); -fixtures.outputTraceFile.initTest(async ({ testInfo }, run) => { +fixtures.outputTraceFile.init(async ({ testInfo }, run) => { await run(testInfo.outputPath(path.join(`trace.json`))); }); const { it, expect, describe } = fixtures.build(); diff --git a/test/downloads-path.spec.ts b/test/downloads-path.spec.ts index 17948d4910..029b0713de 100644 --- a/test/downloads-path.spec.ts +++ b/test/downloads-path.spec.ts @@ -25,7 +25,7 @@ type TestState = { }; const fixtures = folio.extend<{}, TestState>(); -fixtures.downloadsBrowser.initTest(async ({ server, browserType, defaultBrowserOptions, testInfo }, test) => { +fixtures.downloadsBrowser.init(async ({ server, browserType, defaultBrowserOptions, testInfo }, test) => { server.setRoute('/download', (req, res) => { res.setHeader('Content-Type', 'application/octet-stream'); res.setHeader('Content-Disposition', 'attachment; filename=file.txt'); @@ -39,7 +39,7 @@ fixtures.downloadsBrowser.initTest(async ({ server, browserType, defaultBrowserO await browser.close(); }); -fixtures.persistentDownloadsContext.initTest(async ({ server, launchPersistent, testInfo }, test) => { +fixtures.persistentDownloadsContext.init(async ({ server, launchPersistent, testInfo }, test) => { server.setRoute('/download', (req, res) => { res.setHeader('Content-Type', 'application/octet-stream'); res.setHeader('Content-Disposition', 'attachment; filename=file.txt'); diff --git a/test/electron/electron.fixture.ts b/test/electron/electron.fixture.ts index b555a401f7..bd331d6569 100644 --- a/test/electron/electron.fixture.ts +++ b/test/electron/electron.fixture.ts @@ -26,7 +26,7 @@ type TestState = { }; const fixtures = base.extend<{}, TestState>(); -fixtures.application.initTest(async ({ playwright }, run) => { +fixtures.application.init(async ({ playwright }, run) => { const electronPath = path.join(__dirname, '..', '..', 'node_modules', '.bin', electronName); const application = await playwright.electron.launch(electronPath, { args: [path.join(__dirname, 'testApp.js')], @@ -35,7 +35,7 @@ fixtures.application.initTest(async ({ playwright }, run) => { await application.close(); }); -fixtures.window.initTest(async ({ application }, run) => { +fixtures.window.init(async ({ application }, run) => { const page = await application.newBrowserWindow({ width: 800, height: 600 }); await run(page); await page.close(); diff --git a/test/fixtures.spec.ts b/test/fixtures.spec.ts index 4985998ae1..5584790b9b 100644 --- a/test/fixtures.spec.ts +++ b/test/fixtures.spec.ts @@ -25,7 +25,7 @@ type FixturesFixtures = { }; const fixtures = folio.extend<{}, FixturesFixtures>(); -fixtures.connectedRemoteServer.initTest(async ({browserType, remoteServer, server}, run) => { +fixtures.connectedRemoteServer.init(async ({browserType, remoteServer, server}, run) => { const browser = await browserType.connect({ wsEndpoint: remoteServer.wsEndpoint() }); const page = await browser.newPage(); await page.goto(server.EMPTY_PAGE); @@ -33,7 +33,7 @@ fixtures.connectedRemoteServer.initTest(async ({browserType, remoteServer, serve await browser.close(); }); -fixtures.stallingConnectedRemoteServer.initTest(async ({browserType, stallingRemoteServer, server}, run) => { +fixtures.stallingConnectedRemoteServer.init(async ({browserType, stallingRemoteServer, server}, run) => { const browser = await browserType.connect({ wsEndpoint: stallingRemoteServer.wsEndpoint() }); const page = await browser.newPage(); await page.goto(server.EMPTY_PAGE); diff --git a/test/fixtures.ts b/test/fixtures.ts index 407b3fd882..a8cc1bc319 100644 --- a/test/fixtures.ts +++ b/test/fixtures.ts @@ -55,7 +55,7 @@ const fixtures = playwrightFolio.union(httpFolio).extend { +fixtures.createUserDataDir.init(async ({ }, run) => { const dirs: string[] = []; async function createUserDataDir() { // We do not put user data dir in testOutputPath, @@ -72,7 +72,7 @@ fixtures.createUserDataDir.initTest(async ({ }, run) => { await Promise.all(dirs.map(dir => removeFolderAsync(dir).catch(e => { }))); }); -fixtures.launchPersistent.initTest(async ({ createUserDataDir, defaultBrowserOptions, browserType }, run) => { +fixtures.launchPersistent.init(async ({ createUserDataDir, defaultBrowserOptions, browserType }, run) => { let context; async function launchPersistent(options) { if (context) @@ -87,7 +87,7 @@ fixtures.launchPersistent.initTest(async ({ createUserDataDir, defaultBrowserOpt await context.close(); }); -fixtures.defaultBrowserOptions.overrideWorker(async ({ browserName, headful, slowMo }, run) => { +fixtures.defaultBrowserOptions.override(async ({ browserName, headful, slowMo }, run) => { const executablePath = getExecutablePath(browserName); if (executablePath) console.error(`Using executable at ${executablePath}`); @@ -99,7 +99,7 @@ fixtures.defaultBrowserOptions.overrideWorker(async ({ browserName, headful, slo }); }); -fixtures.playwright.overrideWorker(async ({ browserName, testWorkerIndex, platform, wire }, run) => { +fixtures.playwright.override(async ({ browserName, testWorkerIndex, platform, wire }, run) => { assert(platform); // Depend on platform to generate all tests. const { coverage, uninstall } = installCoverageHooks(browserName); if (wire) { @@ -139,11 +139,11 @@ fixtures.playwright.overrideWorker(async ({ browserName, testWorkerIndex, platfo } }); -fixtures.toImpl.initWorker(async ({ playwright }, run) => { +fixtures.toImpl.init(async ({ playwright }, run) => { await run((playwright as any)._toImpl); -}); +}, { scope: 'worker' }); -fixtures.testParametersPathSegment.overrideTest(async ({ browserName }, run) => { +fixtures.testParametersPathSegment.override(async ({ browserName }, run) => { await run(browserName); }); @@ -155,6 +155,7 @@ folio.generateParametrizedTests( export const it = folio.it; export const fit = folio.fit; +export const test = folio.test; export const xit = folio.xit; export const describe = folio.describe; export const fdescribe = folio.fdescribe; diff --git a/test/http.fixtures.ts b/test/http.fixtures.ts index cc5f38b6a8..75b91b4acb 100644 --- a/test/http.fixtures.ts +++ b/test/http.fixtures.ts @@ -29,7 +29,7 @@ type HttpTestFixtures = { }; const fixtures = base.extend(); -fixtures.httpService.initWorker(async ({ testWorkerIndex }, test) => { +fixtures.httpService.init(async ({ testWorkerIndex }, test) => { const assetsPath = path.join(__dirname, 'assets'); const cachedPath = path.join(__dirname, 'assets', 'cached'); @@ -47,18 +47,18 @@ fixtures.httpService.initWorker(async ({ testWorkerIndex }, test) => { server.stop(), httpsServer.stop(), ]); -}); +}, { scope: 'worker' }); -fixtures.asset.initWorker(async ({ }, test) => { +fixtures.asset.init(async ({ }, test) => { await test(p => path.join(__dirname, `assets`, p)); -}); +}, { scope: 'worker' }); -fixtures.server.initTest(async ({ httpService }, test) => { +fixtures.server.init(async ({ httpService }, test) => { httpService.server.reset(); await test(httpService.server); }); -fixtures.httpsServer.initTest(async ({ httpService }, test) => { +fixtures.httpsServer.init(async ({ httpService }, test) => { httpService.httpsServer.reset(); await test(httpService.httpsServer); }); diff --git a/test/playwright.fixtures.ts b/test/playwright.fixtures.ts index d422e95688..94e4f12d97 100644 --- a/test/playwright.fixtures.ts +++ b/test/playwright.fixtures.ts @@ -14,9 +14,17 @@ * limitations under the License. */ -import { config, folio as base } from 'folio'; +/** + * ============================================================================= + * DO NOT EDIT THIS FILE + * EDIT THE ONE IN @playwright/test and copy it over here. + * ============================================================================= + */ + +import { config, folio as baseFolio } from 'folio'; import type { Browser, BrowserContext, BrowserContextOptions, BrowserType, LaunchOptions, Page } from '../index'; import * as path from 'path'; +export { expect, config } from 'folio'; // Parameters ------------------------------------------------------------------ // ... these can be used to run tests in different modes. @@ -77,7 +85,7 @@ type PlaywrightTestFixtures = { page: Page; }; -const fixtures = base.extend(); +const fixtures = baseFolio.extend(); fixtures.browserName.initParameter('Browser type name', (process.env.BROWSER || 'chromium') as 'chromium' | 'firefox' | 'webkit'); fixtures.headful.initParameter('Whether to run tests headless or headful', process.env.HEADFUL ? true : false); fixtures.platform.initParameter('Operating system', process.platform as ('win32' | 'linux' | 'darwin')); @@ -85,55 +93,55 @@ fixtures.screenshotOnFailure.initParameter('Generate screenshot on failure', fal fixtures.slowMo.initParameter('Slows down Playwright operations by the specified amount of milliseconds', 0); fixtures.trace.initParameter('Whether to record the execution trace', !!process.env.TRACING); -fixtures.defaultBrowserOptions.initWorker(async ({ headful, slowMo }, run) => { +fixtures.defaultBrowserOptions.init(async ({ headful, slowMo }, run) => { await run({ handleSIGINT: false, slowMo, headless: !headful, }); -}); +}, { scope: 'worker' }); -fixtures.playwright.initWorker(async ({ }, run) => { +fixtures.playwright.init(async ({ }, run) => { const playwright = require('../index'); await run(playwright); -}); +}, { scope: 'worker' }); -fixtures.browserType.initWorker(async ({ playwright, browserName }, run) => { +fixtures.browserType.init(async ({ playwright, browserName }, run) => { const browserType = (playwright as any)[browserName]; await run(browserType); -}); +}, { scope: 'worker' }); -fixtures.browser.initWorker(async ({ browserType, defaultBrowserOptions }, run) => { +fixtures.browser.init(async ({ browserType, defaultBrowserOptions }, run) => { const browser = await browserType.launch(defaultBrowserOptions); await run(browser); await browser.close(); -}); +}, { scope: 'worker' }); -fixtures.isChromium.initWorker(async ({ browserName }, run) => { +fixtures.isChromium.init(async ({ browserName }, run) => { await run(browserName === 'chromium'); -}); +}, { scope: 'worker' }); -fixtures.isFirefox.initWorker(async ({ browserName }, run) => { +fixtures.isFirefox.init(async ({ browserName }, run) => { await run(browserName === 'firefox'); -}); +}, { scope: 'worker' }); -fixtures.isWebKit.initWorker(async ({ browserName }, run) => { +fixtures.isWebKit.init(async ({ browserName }, run) => { await run(browserName === 'webkit'); -}); +}, { scope: 'worker' }); -fixtures.isWindows.initWorker(async ({ platform }, run) => { +fixtures.isWindows.init(async ({ platform }, run) => { await run(platform === 'win32'); -}); +}, { scope: 'worker' }); -fixtures.isMac.initWorker(async ({ platform }, run) => { +fixtures.isMac.init(async ({ platform }, run) => { await run(platform === 'darwin'); -}); +}, { scope: 'worker' }); -fixtures.isLinux.initWorker(async ({ platform }, run) => { +fixtures.isLinux.init(async ({ platform }, run) => { await run(platform === 'linux'); -}); +}, { scope: 'worker' }); -fixtures.defaultContextOptions.initTest(async ({ trace, testInfo }, run) => { +fixtures.defaultContextOptions.init(async ({ trace, testInfo }, run) => { if (trace || testInfo.retry) { await run({ _traceResourcesPath: path.join(config.outputDir, 'trace-resources'), @@ -145,7 +153,7 @@ fixtures.defaultContextOptions.initTest(async ({ trace, testInfo }, run) => { } }); -fixtures.contextFactory.initTest(async ({ browser, defaultContextOptions, testInfo, screenshotOnFailure }, run) => { +fixtures.contextFactory.init(async ({ browser, defaultContextOptions, testInfo, screenshotOnFailure }, run) => { const contexts: BrowserContext[] = []; async function contextFactory(options: BrowserContextOptions = {}) { const context = await browser.newContext({ ...defaultContextOptions, ...options }); @@ -165,26 +173,38 @@ fixtures.contextFactory.initTest(async ({ browser, defaultContextOptions, testIn await context.close(); }); -fixtures.context.initTest(async ({ contextFactory }, run) => { +fixtures.context.init(async ({ contextFactory }, run) => { const context = await contextFactory(); await run(context); // Context factory is taking care of closing the context, // so that it could capture a screenshot on failure. }); -fixtures.page.initTest(async ({ context }, run) => { +fixtures.page.init(async ({ context }, run) => { // Always create page off context so that they matched. await run(await context.newPage()); // Context fixture is taking care of closing the page. }); -fixtures.testParametersPathSegment.overrideTest(async ({ browserName, platform }, run) => { +fixtures.testParametersPathSegment.override(async ({ browserName, platform }, run) => { await run(browserName + '-' + platform); }); export const folio = fixtures.build(); +export const it = folio.it; +export const fit = folio.fit; +export const xit = folio.xit; +export const test = folio.test; +export const describe = folio.describe; +export const fdescribe = folio.fdescribe; +export const xdescribe = folio.xdescribe; +export const beforeEach = folio.beforeEach; +export const afterEach = folio.afterEach; +export const beforeAll = folio.beforeAll; +export const afterAll = folio.afterAll; // If browser is not specified, we are running tests against all three browsers. + folio.generateParametrizedTests( 'browserName', process.env.BROWSER ? [process.env.BROWSER] as any : ['chromium', 'webkit', 'firefox']); diff --git a/test/remoteServer.fixture.ts b/test/remoteServer.fixture.ts index b5b4c571bd..348c5fa535 100644 --- a/test/remoteServer.fixture.ts +++ b/test/remoteServer.fixture.ts @@ -26,14 +26,14 @@ type ServerFixtures = { }; const fixtures = base.extend<{}, ServerFixtures>(); -fixtures.remoteServer.initTest(async ({ browserType, defaultBrowserOptions }, run) => { +fixtures.remoteServer.init(async ({ browserType, defaultBrowserOptions }, run) => { const remoteServer = new RemoteServer(); await remoteServer._start(browserType, defaultBrowserOptions); await run(remoteServer); await remoteServer.close(); }); -fixtures.stallingRemoteServer.initTest(async ({ browserType, defaultBrowserOptions }, run) => { +fixtures.stallingRemoteServer.init(async ({ browserType, defaultBrowserOptions }, run) => { const remoteServer = new RemoteServer(); await remoteServer._start(browserType, defaultBrowserOptions, { stallOnClose: true }); await run(remoteServer); diff --git a/utils/doclint/check_public_api/test/test.js b/utils/doclint/check_public_api/test/test.js index 8edf7ba376..f72411ee5e 100644 --- a/utils/doclint/check_public_api/test/test.js +++ b/utils/doclint/check_public_api/test/test.js @@ -24,12 +24,12 @@ const jsBuilder = require('../JSBuilder'); const { folio } = require('folio'); const fixtures = folio.extend(); -fixtures.setWorkerFixture('page', async({}, test) => { +fixtures.page.init(async({}, test) => { const browser = await playwright.chromium.launch(); const page = await browser.newPage(); await test(page); await browser.close(); -}); +}, { scope: 'worker' }); const { describe, it, expect } = fixtures.build(); describe('checkPublicAPI', function() {