From bb1da5ec1efc4804f261f6d1e2ba4bbc2ec33f90 Mon Sep 17 00:00:00 2001 From: Ross Wollman Date: Tue, 24 May 2022 11:34:29 -0700 Subject: [PATCH] fix: expect.toHaveScreenshot.animations types (#14387) This makes the docs/types match the code which has already been released. Relevant code to traverse up from: - https://github.com/microsoft/playwright/blob/3e084829c00bda73b45fa22ecc0c31d6c057e87b/packages/playwright-core/src/server/screenshotter.ts#L89 - https://github.com/microsoft/playwright/blob/3e084829c00bda73b45fa22ecc0c31d6c057e87b/packages/playwright-core/src/server/screenshotter.ts#L118 Fixes #14385 --- docs/src/test-api/class-testconfig.md | 2 +- docs/src/test-api/class-testproject.md | 2 +- packages/playwright-test/types/test.d.ts | 8 ++--- tests/config/experimental.d.ts | 8 ++--- .../to-have-screenshot.spec.ts | 36 +++++++++++++++++++ 5 files changed, 46 insertions(+), 10 deletions(-) diff --git a/docs/src/test-api/class-testconfig.md b/docs/src/test-api/class-testconfig.md index 88142dc48f..388cc0f543 100644 --- a/docs/src/test-api/class-testconfig.md +++ b/docs/src/test-api/class-testconfig.md @@ -40,7 +40,7 @@ export default config; - `threshold` ?<[float]> an acceptable perceived color difference in the [YIQ color space](https://en.wikipedia.org/wiki/YIQ) between the same pixel in compared images, between zero (strict) and one (lax). Defaults to `0.2`. - `maxDiffPixels` ?<[int]> an acceptable amount of pixels that could be different, unset by default. - `maxDiffPixelRatio` ?<[float]> an acceptable ratio of pixels that are different to the total amount of pixels, between `0` and `1` , unset by default. - - `animations` ?<[ScreenshotAnimations]<"allow"|"disable">> See [`option: animations`] in [`method: Page.screenshot`]. Defaults to `"disable"`. + - `animations` ?<[ScreenshotAnimations]<"allow"|"disabled">> See [`option: animations`] in [`method: Page.screenshot`]. Defaults to `"disabled"`. - `caret` ?<[ScreenshotCaret]<"hide"|"initial">> See [`option: caret`] in [`method: Page.screenshot`]. Defaults to `"hide"`. - `scale` ?<[ScreenshotScale]<"css"|"device">> See [`option: scale`] in [`method: Page.screenshot`]. Defaults to `"css"`. - `toMatchSnapshot` ?<[Object]> Configuration for the [`method: ScreenshotAssertions.toMatchSnapshot#1`] method. diff --git a/docs/src/test-api/class-testproject.md b/docs/src/test-api/class-testproject.md index 04a7842a23..f5ec00dda4 100644 --- a/docs/src/test-api/class-testproject.md +++ b/docs/src/test-api/class-testproject.md @@ -111,7 +111,7 @@ export default config; - `threshold` ?<[float]> an acceptable perceived color difference in the [YIQ color space](https://en.wikipedia.org/wiki/YIQ) between the same pixel in compared images, between zero (strict) and one (lax). Defaults to `0.2`. - `maxDiffPixels` ?<[int]> an acceptable amount of pixels that could be different, unset by default. - `maxDiffPixelRatio` ?<[float]> an acceptable ratio of pixels that are different to the total amount of pixels, between `0` and `1` , unset by default. - - `animations` ?<[ScreenshotAnimations]<"allow"|"disable">> See [`option: animations`] in [`method: Page.screenshot`]. Defaults to `"disable"`. + - `animations` ?<[ScreenshotAnimations]<"allow"|"disabled">> See [`option: animations`] in [`method: Page.screenshot`]. Defaults to `"disabled"`. - `caret` ?<[ScreenshotCaret]<"hide"|"initial">> See [`option: caret`] in [`method: Page.screenshot`]. Defaults to `"hide"`. - `scale` ?<[ScreenshotScale]<"css"|"device">> See [`option: scale`] in [`method: Page.screenshot`]. Defaults to `"css"`. - `toMatchSnapshot` ?<[Object]> Configuration for the [`method: ScreenshotAssertions.toMatchSnapshot#1`] method. diff --git a/packages/playwright-test/types/test.d.ts b/packages/playwright-test/types/test.d.ts index 0471a948a1..5fdc4ea041 100644 --- a/packages/playwright-test/types/test.d.ts +++ b/packages/playwright-test/types/test.d.ts @@ -508,9 +508,9 @@ interface TestConfig { /** * See `animations` in [page.screenshot([options])](https://playwright.dev/docs/api/class-page#page-screenshot). Defaults - * to `"disable"`. + * to `"disabled"`. */ - animations?: "allow"|"disable"; + animations?: "allow"|"disabled"; /** * See `caret` in [page.screenshot([options])](https://playwright.dev/docs/api/class-page#page-screenshot). Defaults to @@ -4020,9 +4020,9 @@ interface TestProject { /** * See `animations` in [page.screenshot([options])](https://playwright.dev/docs/api/class-page#page-screenshot). Defaults - * to `"disable"`. + * to `"disabled"`. */ - animations?: "allow"|"disable"; + animations?: "allow"|"disabled"; /** * See `caret` in [page.screenshot([options])](https://playwright.dev/docs/api/class-page#page-screenshot). Defaults to diff --git a/tests/config/experimental.d.ts b/tests/config/experimental.d.ts index a625fd1eca..4077ff0882 100644 --- a/tests/config/experimental.d.ts +++ b/tests/config/experimental.d.ts @@ -16690,9 +16690,9 @@ interface TestConfig { /** * See `animations` in [page.screenshot([options])](https://playwright.dev/docs/api/class-page#page-screenshot). Defaults - * to `"disable"`. + * to `"disabled"`. */ - animations?: "allow"|"disable"; + animations?: "allow"|"disabled"; /** * See `caret` in [page.screenshot([options])](https://playwright.dev/docs/api/class-page#page-screenshot). Defaults to @@ -20232,9 +20232,9 @@ interface TestProject { /** * See `animations` in [page.screenshot([options])](https://playwright.dev/docs/api/class-page#page-screenshot). Defaults - * to `"disable"`. + * to `"disabled"`. */ - animations?: "allow"|"disable"; + animations?: "allow"|"disabled"; /** * See `caret` in [page.screenshot([options])](https://playwright.dev/docs/api/class-page#page-screenshot). Defaults to diff --git a/tests/playwright-test/to-have-screenshot.spec.ts b/tests/playwright-test/to-have-screenshot.spec.ts index db718ac093..b848864af8 100644 --- a/tests/playwright-test/to-have-screenshot.spec.ts +++ b/tests/playwright-test/to-have-screenshot.spec.ts @@ -74,6 +74,42 @@ test('should disable animations by default', async ({ runInlineTest }, testInfo) expect(result.exitCode).toBe(0); }); +test.describe('expect config animations option', () => { + test('disabled', async ({ runInlineTest }, testInfo) => { + const cssTransitionURL = pathToFileURL(path.join(__dirname, '../assets/css-transition.html')); + const result = await runInlineTest({ + ...playwrightConfig({ + expect: { toHaveScreenshot: { animations: 'disabled' } }, + }), + 'a.spec.js': ` + pwt.test('is a test', async ({ page }) => { + await page.goto('${cssTransitionURL}'); + await expect(page).toHaveScreenshot({ timeout: 2000 }); + }); + ` + }, { 'update-snapshots': true }); + expect(result.exitCode).toBe(0); + }); + + test('allow', async ({ runInlineTest }, testInfo) => { + const cssTransitionURL = pathToFileURL(path.join(__dirname, '../assets/css-transition.html')); + const result = await runInlineTest({ + ...playwrightConfig({ + expect: { toHaveScreenshot: { animations: 'allow' } }, + }), + 'a.spec.js': ` + pwt.test('is a test', async ({ page }) => { + await page.goto('${cssTransitionURL}'); + await expect(page).toHaveScreenshot({ timeout: 2000 }); + }); + ` + }, { 'update-snapshots': true }); + expect(result.exitCode).toBe(1); + expect(result.output).toContain('is-a-test-1-diff.png'); + }); +}); + + test('should fail with proper error when unsupported argument is given', async ({ runInlineTest }, testInfo) => { const cssTransitionURL = pathToFileURL(path.join(__dirname, '../assets/css-transition.html')); const result = await runInlineTest({