Skip to content

Commit

Permalink
test: roll to [email protected] (#6918)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgozman authored Jun 5, 2021
1 parent f441755 commit 82041b2
Show file tree
Hide file tree
Showing 138 changed files with 38 additions and 40 deletions.
18 changes: 9 additions & 9 deletions docs/src/test-snapshots.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ id: test-snapshots
title: "Visual comparisons"
---

Playwright Test includes the ability to produce and visually compare screenshots using `expect(value).toMatchSnapshot()`. On first execution, Playwright test will generate reference screenshots. Subsequent runs will compare against the reference.
Playwright Test includes the ability to produce and visually compare screenshots using `expect(value).toMatchSnapshot(snapshotName)`. On first execution, Playwright test will generate reference screenshots. Subsequent runs will compare against the reference.

```js js-flavor=js
// example.spec.js
const { test, expect } = require('@playwright/test');

test('example test', async ({ page }) => {
await page.goto('https://playwright.dev');
expect(await page.screenshot()).toMatchSnapshot('optional-snapshot-name.png');
expect(await page.screenshot()).toMatchSnapshot('snapshot-name.png');
});
```

Expand All @@ -21,7 +21,7 @@ import { test, expect } from '@playwright/test';

test('example test', async ({ page }) => {
await page.goto('https://playwright.dev');
expect(await page.screenshot()).toMatchSnapshot('optional-snapshot-name.png');
expect(await page.screenshot()).toMatchSnapshot('snapshot-name.png');
});
```

Expand All @@ -39,7 +39,7 @@ const { test, expect } = require('@playwright/test');

test('example test', async ({ page }) => {
await page.goto('https://playwright.dev');
expect(await page.screenshot()).toMatchSnapshot({ threshold: 0.2 });
expect(await page.screenshot()).toMatchSnapshot('home.png', { threshold: 0.2 });
});
```

Expand All @@ -49,11 +49,11 @@ import { test, expect } from '@playwright/test';

test('example test', async ({ page }) => {
await page.goto('https://playwright.dev');
expect(await page.screenshot()).toMatchSnapshot({ threshold: 0.2 });
expect(await page.screenshot()).toMatchSnapshot('home.png', { threshold: 0.2 });
});
```

Apart from screenshots, `expect(value).toMatchSnapshot()` can also be used to compare text, png and jpeg images, or arbitrary binary data. Playwright Test auto-detects the content type and uses the appropriate comparison algorithm.
Apart from screenshots, `expect(value).toMatchSnapshot(snapshotName)` can also be used to compare text, png and jpeg images, or arbitrary binary data. Playwright Test auto-detects the content type and uses the appropriate comparison algorithm.

Here we compare text content against the reference.

Expand All @@ -63,7 +63,7 @@ const { test, expect } = require('@playwright/test');

test('example test', async ({ page }) => {
await page.goto('https://playwright.dev');
expect(await page.textContent('.hero__title')).toMatchSnapshot();
expect(await page.textContent('.hero__title')).toMatchSnapshot('hero.txt');
});
```

Expand All @@ -73,8 +73,8 @@ import { test, expect } from '@playwright/test';

test('example test', async ({ page }) => {
await page.goto('https://playwright.dev');
expect(await page.textContent('.hero__title')).toMatchSnapshot();
expect(await page.textContent('.hero__title')).toMatchSnapshot('hero.txt');
});
```

Snapshots are stored next to the test file, in a separate directory. For example, `my.spec.js` file will produce and store snapshots in the `my.spec.js-snapshots` directory. You should commit this directory to your version control (e.g. `git`), and review any changes to it.
Snapshots are stored next to the test file, in a separate directory. For example, `my.spec.ts` file will produce and store snapshots in the `my.spec.ts-snapshots` directory. You should commit this directory to your version control (e.g. `git`), and review any changes to it.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"eslint-plugin-notice": "^0.9.10",
"eslint-plugin-react-hooks": "^4.2.0",
"file-loader": "^6.1.0",
"folio": "=0.4.0-alpha27",
"folio": "=0.4.0-alpha28",
"formidable": "^1.2.2",
"html-webpack-plugin": "^4.4.1",
"ncp": "^2.0.0",
Expand Down
9 changes: 6 additions & 3 deletions src/cli/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import type { PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, P

export * from 'folio';
export const test = folio.test.extend<PlaywrightTestArgs & PlaywrightTestOptions, PlaywrightWorkerArgs & PlaywrightWorkerOptions>({
browserName: [ 'chromium', { scope: 'worker' } ],
defaultBrowserType: [ 'chromium', { scope: 'worker' } ],
browserName: [ ({ defaultBrowserType }, use) => use(defaultBrowserType), { scope: 'worker' } ],
playwright: [ require('../inprocess'), { scope: 'worker' } ],
headless: [ undefined, { scope: 'worker' } ],
channel: [ undefined, { scope: 'worker' } ],
Expand Down Expand Up @@ -66,8 +67,8 @@ export const test = folio.test.extend<PlaywrightTestArgs & PlaywrightTestOptions
viewport: undefined,
contextOptions: {},

context: async ({ browserName, browser, screenshot, video, acceptDownloads, bypassCSP, colorScheme, deviceScaleFactor, extraHTTPHeaders, hasTouch, geolocation, httpCredentials, ignoreHTTPSErrors, isMobile, javaScriptEnabled, locale, offline, permissions, proxy, storageState, viewport, timezoneId, userAgent, contextOptions }, use, testInfo) => {
testInfo.snapshotSuffix = browserName + '-' + process.platform;
context: async ({ browser, screenshot, video, acceptDownloads, bypassCSP, colorScheme, deviceScaleFactor, extraHTTPHeaders, hasTouch, geolocation, httpCredentials, ignoreHTTPSErrors, isMobile, javaScriptEnabled, locale, offline, permissions, proxy, storageState, viewport, timezoneId, userAgent, contextOptions }, use, testInfo) => {
testInfo.snapshotSuffix = process.platform;
if (process.env.PWDEBUG)
testInfo.setTimeout(0);

Expand Down Expand Up @@ -148,3 +149,5 @@ export const test = folio.test.extend<PlaywrightTestArgs & PlaywrightTestOptions
},
});
export default test;

export const __baseTest = folio.test;
22 changes: 10 additions & 12 deletions src/cli/testRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,16 @@ export function addTestCommand(program: commander.CommanderStatic) {
}

async function runTests(Runner: RunnerType, args: string[], opts: { [key: string]: any }) {
if (opts.browser) {
const browserOpt = opts.browser.toLowerCase();
if (!['all', 'chromium', 'firefox', 'webkit'].includes(browserOpt))
throw new Error(`Unsupported browser "${opts.browser}", must be one of "all", "chromium", "firefox" or "webkit"`);
const browserNames = browserOpt === 'all' ? ['chromium', 'firefox', 'webkit'] : [browserOpt];
defaultConfig.projects = browserNames.map(browserName => {
return {
name: browserName,
use: { browserName },
};
});
}
const browserOpt = opts.browser ? opts.browser.toLowerCase() : 'chromium';
if (!['all', 'chromium', 'firefox', 'webkit'].includes(browserOpt))
throw new Error(`Unsupported browser "${opts.browser}", must be one of "all", "chromium", "firefox" or "webkit"`);
const browserNames = browserOpt === 'all' ? ['chromium', 'firefox', 'webkit'] : [browserOpt];
defaultConfig.projects = browserNames.map(browserName => {
return {
name: browserName,
use: { browserName },
};
});

const overrides = overridesFromOptions(opts);
if (opts.headed)
Expand Down
6 changes: 1 addition & 5 deletions tests/config/baseTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class DefaultMode {
}
}

const baseFixtures: folio.Fixtures<{ __baseSetup: void }, BaseOptions & BaseFixtures> = {
const baseFixtures: folio.Fixtures<{}, BaseOptions & BaseFixtures> = {
mode: [ 'default', { scope: 'worker' } ],
browserName: [ 'chromium' , { scope: 'worker' } ],
channel: [ undefined, { scope: 'worker' } ],
Expand All @@ -123,10 +123,6 @@ const baseFixtures: folio.Fixtures<{ __baseSetup: void }, BaseOptions & BaseFixt
isWindows: [ process.platform === 'win32', { scope: 'worker' } ],
isMac: [ process.platform === 'darwin', { scope: 'worker' } ],
isLinux: [ process.platform === 'linux', { scope: 'worker' } ],
__baseSetup: [ async ({ browserName }, run, testInfo) => {
testInfo.snapshotSuffix = browserName;
await run();
}, { auto: true } ],
};

type ServerOptions = {
Expand Down
4 changes: 2 additions & 2 deletions tests/config/electron.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const metadata = {
};

config.projects.push({
name: 'electron',
name: 'chromium', // We use 'chromium' here to share screenshots with chromium.
use: {
mode: 'default',
browserName: 'chromium',
Expand All @@ -59,7 +59,7 @@ config.projects.push({
});

config.projects.push({
name: 'electron',
name: 'chromium', // We use 'chromium' here to share screenshots with chromium.
use: {
mode: 'default',
browserName: 'chromium',
Expand Down
2 changes: 1 addition & 1 deletion tests/headful.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ it('focused input should produce the same screenshot', async ({browserType, brow
it.skip(browserName === 'webkit' && platform === 'linux', 'gtk vs wpe');
it.skip(!!process.env.CRPATH);

testInfo.snapshotSuffix = browserName + '-' + platform;
testInfo.snapshotSuffix = platform;

const headful = await browserType.launch({...browserOptions, headless: false });
const headfulPage = await headful.newPage();
Expand Down
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
1 change: 1 addition & 0 deletions types/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export type PlaywrightWorkerOptions = {
* Name of the browser (`chromium`, `firefox`, `webkit`) that runs tests.
*/
browserName: BrowserName;
defaultBrowserType: BrowserName;

/**
* Whether to run browser in headless mode. Takes priority over `launchOptions`.
Expand Down

0 comments on commit 82041b2

Please sign in to comment.