chore: roll folio to 0.3.8 (#4113)

This commit is contained in:
Pavel Feldman 2020-10-12 13:48:56 -07:00 committed by GitHub
parent 46b14bc740
commit c2adc98cb0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 80 additions and 59 deletions

6
package-lock.json generated
View file

@ -3650,9 +3650,9 @@
} }
}, },
"folio": { "folio": {
"version": "0.3.6", "version": "0.3.8",
"resolved": "https://registry.npmjs.org/folio/-/folio-0.3.6.tgz", "resolved": "https://registry.npmjs.org/folio/-/folio-0.3.8.tgz",
"integrity": "sha512-LPi0B9HHxdqCAvwgZOdcmPufJX4PjWbS2VN1QbN3mzapMoM1j+OI30YV5fU3e+4krJn50rKuki5WL6gdRIcJlQ==", "integrity": "sha512-7dD6dJJ/oJBQXoFo4Xui7rrmF/FUW/UIgGBYSdpk5luYcCP26TsYBWz2mF+fJGwuIajbipoeieT+9NWsHz+iQA==",
"dev": true, "dev": true,
"requires": { "requires": {
"@babel/code-frame": "^7.10.4", "@babel/code-frame": "^7.10.4",

View file

@ -68,7 +68,7 @@
"electron": "^9.2.1", "electron": "^9.2.1",
"eslint": "^7.7.0", "eslint": "^7.7.0",
"eslint-plugin-notice": "^0.9.10", "eslint-plugin-notice": "^0.9.10",
"folio": "=0.3.6", "folio": "=0.3.8",
"formidable": "^1.2.2", "formidable": "^1.2.2",
"ncp": "^2.0.0", "ncp": "^2.0.0",
"node-stream-zip": "^1.11.3", "node-stream-zip": "^1.11.3",

View file

@ -19,8 +19,8 @@ import domain from 'domain';
import { folio } from './fixtures'; import { folio } from './fixtures';
import type { ChromiumBrowser } from '..'; import type { ChromiumBrowser } from '..';
const fixtures = folio.extend<{ domain: any }, {}>(); const fixtures = folio.extend<{ domain: any }>();
fixtures.domain.initWorker(async ({ }, run) => { fixtures.domain.init(async ({ }, run) => {
const local = domain.create(); const local = domain.create();
local.run(() => { }); local.run(() => { });
let err; let err;
@ -28,7 +28,7 @@ fixtures.domain.initWorker(async ({ }, run) => {
await run(null); await run(null);
if (err) if (err)
throw err; throw err;
}); }, { scope: 'worker' });
const { it, expect } = fixtures.build(); const { it, expect } = fixtures.build();
it('should work', async ({browser}) => { it('should work', async ({browser}) => {

View file

@ -17,7 +17,7 @@
import { folio } from '../fixtures'; import { folio } from '../fixtures';
const fixtures = folio.extend(); const fixtures = folio.extend();
fixtures.browser.overrideWorker(async ({browserType, defaultBrowserOptions}, run) => { fixtures.browser.override(async ({browserType, defaultBrowserOptions}, run) => {
const browser = await browserType.launch({ const browser = await browserType.launch({
...defaultBrowserOptions, ...defaultBrowserOptions,
args: (defaultBrowserOptions.args || []).concat(['--site-per-process']) args: (defaultBrowserOptions.args || []).concat(['--site-per-process'])

View file

@ -23,7 +23,7 @@ type TestState = {
outputTraceFile: string; outputTraceFile: string;
}; };
const fixtures = folio.extend<{}, TestState>(); 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`))); await run(testInfo.outputPath(path.join(`trace.json`)));
}); });
const { it, expect, describe } = fixtures.build(); const { it, expect, describe } = fixtures.build();

View file

@ -25,7 +25,7 @@ type TestState = {
}; };
const fixtures = folio.extend<{}, 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) => { server.setRoute('/download', (req, res) => {
res.setHeader('Content-Type', 'application/octet-stream'); res.setHeader('Content-Type', 'application/octet-stream');
res.setHeader('Content-Disposition', 'attachment; filename=file.txt'); res.setHeader('Content-Disposition', 'attachment; filename=file.txt');
@ -39,7 +39,7 @@ fixtures.downloadsBrowser.initTest(async ({ server, browserType, defaultBrowserO
await browser.close(); await browser.close();
}); });
fixtures.persistentDownloadsContext.initTest(async ({ server, launchPersistent, testInfo }, test) => { fixtures.persistentDownloadsContext.init(async ({ server, launchPersistent, testInfo }, test) => {
server.setRoute('/download', (req, res) => { server.setRoute('/download', (req, res) => {
res.setHeader('Content-Type', 'application/octet-stream'); res.setHeader('Content-Type', 'application/octet-stream');
res.setHeader('Content-Disposition', 'attachment; filename=file.txt'); res.setHeader('Content-Disposition', 'attachment; filename=file.txt');

View file

@ -26,7 +26,7 @@ type TestState = {
}; };
const fixtures = base.extend<{}, 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 electronPath = path.join(__dirname, '..', '..', 'node_modules', '.bin', electronName);
const application = await playwright.electron.launch(electronPath, { const application = await playwright.electron.launch(electronPath, {
args: [path.join(__dirname, 'testApp.js')], args: [path.join(__dirname, 'testApp.js')],
@ -35,7 +35,7 @@ fixtures.application.initTest(async ({ playwright }, run) => {
await application.close(); await application.close();
}); });
fixtures.window.initTest(async ({ application }, run) => { fixtures.window.init(async ({ application }, run) => {
const page = await application.newBrowserWindow({ width: 800, height: 600 }); const page = await application.newBrowserWindow({ width: 800, height: 600 });
await run(page); await run(page);
await page.close(); await page.close();

View file

@ -25,7 +25,7 @@ type FixturesFixtures = {
}; };
const fixtures = folio.extend<{}, 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 browser = await browserType.connect({ wsEndpoint: remoteServer.wsEndpoint() });
const page = await browser.newPage(); const page = await browser.newPage();
await page.goto(server.EMPTY_PAGE); await page.goto(server.EMPTY_PAGE);
@ -33,7 +33,7 @@ fixtures.connectedRemoteServer.initTest(async ({browserType, remoteServer, serve
await browser.close(); 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 browser = await browserType.connect({ wsEndpoint: stallingRemoteServer.wsEndpoint() });
const page = await browser.newPage(); const page = await browser.newPage();
await page.goto(server.EMPTY_PAGE); await page.goto(server.EMPTY_PAGE);

View file

@ -55,7 +55,7 @@ const fixtures = playwrightFolio.union(httpFolio).extend<WorkerFixtures, TestFix
fixtures.wire.initParameter('Wire testing mode', !!process.env.PWWIRE); fixtures.wire.initParameter('Wire testing mode', !!process.env.PWWIRE);
fixtures.createUserDataDir.initTest(async ({ }, run) => { fixtures.createUserDataDir.init(async ({ }, run) => {
const dirs: string[] = []; const dirs: string[] = [];
async function createUserDataDir() { async function createUserDataDir() {
// We do not put user data dir in testOutputPath, // 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 => { }))); 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; let context;
async function launchPersistent(options) { async function launchPersistent(options) {
if (context) if (context)
@ -87,7 +87,7 @@ fixtures.launchPersistent.initTest(async ({ createUserDataDir, defaultBrowserOpt
await context.close(); await context.close();
}); });
fixtures.defaultBrowserOptions.overrideWorker(async ({ browserName, headful, slowMo }, run) => { fixtures.defaultBrowserOptions.override(async ({ browserName, headful, slowMo }, run) => {
const executablePath = getExecutablePath(browserName); const executablePath = getExecutablePath(browserName);
if (executablePath) if (executablePath)
console.error(`Using executable at ${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. assert(platform); // Depend on platform to generate all tests.
const { coverage, uninstall } = installCoverageHooks(browserName); const { coverage, uninstall } = installCoverageHooks(browserName);
if (wire) { 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); await run((playwright as any)._toImpl);
}); }, { scope: 'worker' });
fixtures.testParametersPathSegment.overrideTest(async ({ browserName }, run) => { fixtures.testParametersPathSegment.override(async ({ browserName }, run) => {
await run(browserName); await run(browserName);
}); });
@ -155,6 +155,7 @@ folio.generateParametrizedTests(
export const it = folio.it; export const it = folio.it;
export const fit = folio.fit; export const fit = folio.fit;
export const test = folio.test;
export const xit = folio.xit; export const xit = folio.xit;
export const describe = folio.describe; export const describe = folio.describe;
export const fdescribe = folio.fdescribe; export const fdescribe = folio.fdescribe;

View file

@ -29,7 +29,7 @@ type HttpTestFixtures = {
}; };
const fixtures = base.extend<HttpWorkerFixtures, HttpTestFixtures>(); const fixtures = base.extend<HttpWorkerFixtures, HttpTestFixtures>();
fixtures.httpService.initWorker(async ({ testWorkerIndex }, test) => { fixtures.httpService.init(async ({ testWorkerIndex }, test) => {
const assetsPath = path.join(__dirname, 'assets'); const assetsPath = path.join(__dirname, 'assets');
const cachedPath = path.join(__dirname, 'assets', 'cached'); const cachedPath = path.join(__dirname, 'assets', 'cached');
@ -47,18 +47,18 @@ fixtures.httpService.initWorker(async ({ testWorkerIndex }, test) => {
server.stop(), server.stop(),
httpsServer.stop(), httpsServer.stop(),
]); ]);
}); }, { scope: 'worker' });
fixtures.asset.initWorker(async ({ }, test) => { fixtures.asset.init(async ({ }, test) => {
await test(p => path.join(__dirname, `assets`, p)); 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(); httpService.server.reset();
await test(httpService.server); await test(httpService.server);
}); });
fixtures.httpsServer.initTest(async ({ httpService }, test) => { fixtures.httpsServer.init(async ({ httpService }, test) => {
httpService.httpsServer.reset(); httpService.httpsServer.reset();
await test(httpService.httpsServer); await test(httpService.httpsServer);
}); });

View file

@ -14,9 +14,17 @@
* limitations under the License. * 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 type { Browser, BrowserContext, BrowserContextOptions, BrowserType, LaunchOptions, Page } from '../index';
import * as path from 'path'; import * as path from 'path';
export { expect, config } from 'folio';
// Parameters ------------------------------------------------------------------ // Parameters ------------------------------------------------------------------
// ... these can be used to run tests in different modes. // ... these can be used to run tests in different modes.
@ -77,7 +85,7 @@ type PlaywrightTestFixtures = {
page: Page; page: Page;
}; };
const fixtures = base.extend<PlaywrightWorkerFixtures, PlaywrightTestFixtures, PlaywrightParameters>(); const fixtures = baseFolio.extend<PlaywrightWorkerFixtures, PlaywrightTestFixtures, PlaywrightParameters>();
fixtures.browserName.initParameter('Browser type name', (process.env.BROWSER || 'chromium') as 'chromium' | 'firefox' | 'webkit'); 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.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')); 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.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.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({ await run({
handleSIGINT: false, handleSIGINT: false,
slowMo, slowMo,
headless: !headful, headless: !headful,
}); });
}); }, { scope: 'worker' });
fixtures.playwright.initWorker(async ({ }, run) => { fixtures.playwright.init(async ({ }, run) => {
const playwright = require('../index'); const playwright = require('../index');
await run(playwright); 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]; const browserType = (playwright as any)[browserName];
await run(browserType); 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); const browser = await browserType.launch(defaultBrowserOptions);
await run(browser); await run(browser);
await browser.close(); await browser.close();
}); }, { scope: 'worker' });
fixtures.isChromium.initWorker(async ({ browserName }, run) => { fixtures.isChromium.init(async ({ browserName }, run) => {
await run(browserName === 'chromium'); await run(browserName === 'chromium');
}); }, { scope: 'worker' });
fixtures.isFirefox.initWorker(async ({ browserName }, run) => { fixtures.isFirefox.init(async ({ browserName }, run) => {
await run(browserName === 'firefox'); await run(browserName === 'firefox');
}); }, { scope: 'worker' });
fixtures.isWebKit.initWorker(async ({ browserName }, run) => { fixtures.isWebKit.init(async ({ browserName }, run) => {
await run(browserName === 'webkit'); await run(browserName === 'webkit');
}); }, { scope: 'worker' });
fixtures.isWindows.initWorker(async ({ platform }, run) => { fixtures.isWindows.init(async ({ platform }, run) => {
await run(platform === 'win32'); await run(platform === 'win32');
}); }, { scope: 'worker' });
fixtures.isMac.initWorker(async ({ platform }, run) => { fixtures.isMac.init(async ({ platform }, run) => {
await run(platform === 'darwin'); await run(platform === 'darwin');
}); }, { scope: 'worker' });
fixtures.isLinux.initWorker(async ({ platform }, run) => { fixtures.isLinux.init(async ({ platform }, run) => {
await run(platform === 'linux'); await run(platform === 'linux');
}); }, { scope: 'worker' });
fixtures.defaultContextOptions.initTest(async ({ trace, testInfo }, run) => { fixtures.defaultContextOptions.init(async ({ trace, testInfo }, run) => {
if (trace || testInfo.retry) { if (trace || testInfo.retry) {
await run({ await run({
_traceResourcesPath: path.join(config.outputDir, 'trace-resources'), _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[] = []; const contexts: BrowserContext[] = [];
async function contextFactory(options: BrowserContextOptions = {}) { async function contextFactory(options: BrowserContextOptions = {}) {
const context = await browser.newContext({ ...defaultContextOptions, ...options }); const context = await browser.newContext({ ...defaultContextOptions, ...options });
@ -165,26 +173,38 @@ fixtures.contextFactory.initTest(async ({ browser, defaultContextOptions, testIn
await context.close(); await context.close();
}); });
fixtures.context.initTest(async ({ contextFactory }, run) => { fixtures.context.init(async ({ contextFactory }, run) => {
const context = await contextFactory(); const context = await contextFactory();
await run(context); await run(context);
// Context factory is taking care of closing the context, // Context factory is taking care of closing the context,
// so that it could capture a screenshot on failure. // 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. // Always create page off context so that they matched.
await run(await context.newPage()); await run(await context.newPage());
// Context fixture is taking care of closing the page. // 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); await run(browserName + '-' + platform);
}); });
export const folio = fixtures.build(); 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. // If browser is not specified, we are running tests against all three browsers.
folio.generateParametrizedTests( folio.generateParametrizedTests(
'browserName', 'browserName',
process.env.BROWSER ? [process.env.BROWSER] as any : ['chromium', 'webkit', 'firefox']); process.env.BROWSER ? [process.env.BROWSER] as any : ['chromium', 'webkit', 'firefox']);

View file

@ -26,14 +26,14 @@ type ServerFixtures = {
}; };
const fixtures = base.extend<{}, ServerFixtures>(); const fixtures = base.extend<{}, ServerFixtures>();
fixtures.remoteServer.initTest(async ({ browserType, defaultBrowserOptions }, run) => { fixtures.remoteServer.init(async ({ browserType, defaultBrowserOptions }, run) => {
const remoteServer = new RemoteServer(); const remoteServer = new RemoteServer();
await remoteServer._start(browserType, defaultBrowserOptions); await remoteServer._start(browserType, defaultBrowserOptions);
await run(remoteServer); await run(remoteServer);
await remoteServer.close(); await remoteServer.close();
}); });
fixtures.stallingRemoteServer.initTest(async ({ browserType, defaultBrowserOptions }, run) => { fixtures.stallingRemoteServer.init(async ({ browserType, defaultBrowserOptions }, run) => {
const remoteServer = new RemoteServer(); const remoteServer = new RemoteServer();
await remoteServer._start(browserType, defaultBrowserOptions, { stallOnClose: true }); await remoteServer._start(browserType, defaultBrowserOptions, { stallOnClose: true });
await run(remoteServer); await run(remoteServer);

View file

@ -24,12 +24,12 @@ const jsBuilder = require('../JSBuilder');
const { folio } = require('folio'); const { folio } = require('folio');
const fixtures = folio.extend(); const fixtures = folio.extend();
fixtures.setWorkerFixture('page', async({}, test) => { fixtures.page.init(async({}, test) => {
const browser = await playwright.chromium.launch(); const browser = await playwright.chromium.launch();
const page = await browser.newPage(); const page = await browser.newPage();
await test(page); await test(page);
await browser.close(); await browser.close();
}); }, { scope: 'worker' });
const { describe, it, expect } = fixtures.build(); const { describe, it, expect } = fixtures.build();
describe('checkPublicAPI', function() { describe('checkPublicAPI', function() {