chore: mark comparator option back as experimental (#20816)

This reverts commit 303c5998f8.

Reason for revert: I tried enabling `ssim-cie94` by default on
ionic-framework test suite, and it proves to be overly strict for their
usecase.
This commit is contained in:
Andrey Lushnikov 2023-02-13 11:11:44 -08:00 committed by GitHub
parent ecc2e4aa57
commit fdcd7b549d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 42 additions and 117 deletions

View file

@ -1385,9 +1385,6 @@ Snapshot name.
### option: LocatorAssertions.toHaveScreenshot#1.scale = %%-screenshot-option-scale-default-css-%% ### option: LocatorAssertions.toHaveScreenshot#1.scale = %%-screenshot-option-scale-default-css-%%
* since: v1.23 * since: v1.23
### option: LocatorAssertions.toHaveScreenshot#1.comparator = %%-assertions-comparator-%%
* since: v1.31
### option: LocatorAssertions.toHaveScreenshot#1.maxDiffPixels = %%-assertions-max-diff-pixels-%% ### option: LocatorAssertions.toHaveScreenshot#1.maxDiffPixels = %%-assertions-max-diff-pixels-%%
* since: v1.23 * since: v1.23
@ -1431,9 +1428,6 @@ Note that screenshot assertions only work with Playwright test runner.
### option: LocatorAssertions.toHaveScreenshot#2.scale = %%-screenshot-option-scale-default-css-%% ### option: LocatorAssertions.toHaveScreenshot#2.scale = %%-screenshot-option-scale-default-css-%%
* since: v1.23 * since: v1.23
### option: LocatorAssertions.toHaveScreenshot#2.comparator = %%-assertions-comparator-%%
* since: v1.31
### option: LocatorAssertions.toHaveScreenshot#2.maxDiffPixels = %%-assertions-max-diff-pixels-%% ### option: LocatorAssertions.toHaveScreenshot#2.maxDiffPixels = %%-assertions-max-diff-pixels-%%
* since: v1.23 * since: v1.23

View file

@ -164,9 +164,6 @@ Snapshot name.
### option: PageAssertions.toHaveScreenshot#1.scale = %%-screenshot-option-scale-default-css-%% ### option: PageAssertions.toHaveScreenshot#1.scale = %%-screenshot-option-scale-default-css-%%
* since: v1.23 * since: v1.23
### option: PageAssertions.toHaveScreenshot#1.comparator = %%-assertions-comparator-%%
* since: v1.29
### option: PageAssertions.toHaveScreenshot#1.maxDiffPixels = %%-assertions-max-diff-pixels-%% ### option: PageAssertions.toHaveScreenshot#1.maxDiffPixels = %%-assertions-max-diff-pixels-%%
* since: v1.23 * since: v1.23
@ -215,9 +212,6 @@ Note that screenshot assertions only work with Playwright test runner.
### option: PageAssertions.toHaveScreenshot#2.scale = %%-screenshot-option-scale-default-css-%% ### option: PageAssertions.toHaveScreenshot#2.scale = %%-screenshot-option-scale-default-css-%%
* since: v1.23 * since: v1.23
### option: PageAssertions.toHaveScreenshot#2.comparator = %%-assertions-comparator-%%
* since: v1.29
### option: PageAssertions.toHaveScreenshot#2.maxDiffPixels = %%-assertions-max-diff-pixels-%% ### option: PageAssertions.toHaveScreenshot#2.maxDiffPixels = %%-assertions-max-diff-pixels-%%
* since: v1.23 * since: v1.23

View file

@ -43,9 +43,6 @@ Note that matching snapshots only work with Playwright test runner.
Snapshot name. Snapshot name.
### option: SnapshotAssertions.toMatchSnapshot#1.comparator = %%-assertions-comparator-%%
* since: v1.29
### option: SnapshotAssertions.toMatchSnapshot#1.maxDiffPixels = %%-assertions-max-diff-pixels-%% ### option: SnapshotAssertions.toMatchSnapshot#1.maxDiffPixels = %%-assertions-max-diff-pixels-%%
* since: v1.22 * since: v1.22
@ -82,9 +79,6 @@ Learn more about [visual comparisons](../test-snapshots.md).
Note that matching snapshots only work with Playwright test runner. Note that matching snapshots only work with Playwright test runner.
### option: SnapshotAssertions.toMatchSnapshot#2.comparator = %%-assertions-comparator-%%
* since: v1.29
### option: SnapshotAssertions.toMatchSnapshot#2.maxDiffPixels = %%-assertions-max-diff-pixels-%% ### option: SnapshotAssertions.toMatchSnapshot#2.maxDiffPixels = %%-assertions-max-diff-pixels-%%
* since: v1.22 * since: v1.22

View file

@ -812,12 +812,6 @@ Time to retry the assertion for.
An acceptable amount of pixels that could be different. Default is configurable with `TestConfig.expect`. Unset by default. An acceptable amount of pixels that could be different. Default is configurable with `TestConfig.expect`. Unset by default.
## assertions-comparator
* langs: js
- `comparator` <[string]> Either `"pixelmatch"` or `"ssim-cie94"`.
A comparator function to use when comparing images. Defaults to `"pixelmatch"`.
## assertions-max-diff-pixel-ratio ## assertions-max-diff-pixel-ratio
* langs: js * langs: js
- `maxDiffPixelRatio` <[float]> - `maxDiffPixelRatio` <[float]>
@ -830,7 +824,7 @@ An acceptable ratio of pixels that are different to the total amount of pixels,
An acceptable perceived color difference in the [YIQ color space](https://en.wikipedia.org/wiki/YIQ) 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), default is configurable with between the same pixel in compared images, between zero (strict) and one (lax), default is configurable with
`TestConfig.expect`. Defaults to `0.2`. This option is used by "pixelmatch" image comparator. `TestConfig.expect`. Defaults to `0.2`.
## shared-context-params-list-v1.8 ## shared-context-params-list-v1.8
- %%-context-option-acceptdownloads-%% - %%-context-option-acceptdownloads-%%

View file

@ -37,16 +37,14 @@ export default defineConfig({
- type: ?<[Object]> - type: ?<[Object]>
- `timeout` ?<[int]> Default timeout for async expect matchers in milliseconds, defaults to 5000ms. - `timeout` ?<[int]> Default timeout for async expect matchers in milliseconds, defaults to 5000ms.
- `toHaveScreenshot` ?<[Object]> Configuration for the [`method: PageAssertions.toHaveScreenshot#1`] method. - `toHaveScreenshot` ?<[Object]> Configuration for the [`method: PageAssertions.toHaveScreenshot#1`] method.
- `comparator` ?<[string]> a comparator function to use, either `"pixelmatch"` or `"ssim-cie94"`. Defaults to `"pixelmatch"`. - `threshold` ?<[float]> an acceptable perceived color difference between the same pixel in compared images, ranging from `0` (strict) and `1` (lax). `"pixelmatch"` comparator computes color difference in [YIQ color space](https://en.wikipedia.org/wiki/YIQ) and defaults `threshold` value to `0.2`.
- `threshold` ?<[float]> an acceptable perceived color difference between the same pixel in compared images, ranging from `0` (strict) and `1` (lax). `"pixelmatch"` comparator computes color difference in [YIQ color space](https://en.wikipedia.org/wiki/YIQ) and defaults `threshold` value to `0.2`. This option is used by `pixelmatch` image comparator.
- `maxDiffPixels` ?<[int]> an acceptable amount of pixels that could be different, unset by default. - `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. - `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"|"disabled">> See [`option: animations`] in [`method: Page.screenshot`]. Defaults to `"disabled"`. - `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"`. - `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"`. - `scale` ?<[ScreenshotScale]<"css"|"device">> See [`option: scale`] in [`method: Page.screenshot`]. Defaults to `"css"`.
- `toMatchSnapshot` ?<[Object]> Configuration for the [`method: SnapshotAssertions.toMatchSnapshot#1`] method. - `toMatchSnapshot` ?<[Object]> Configuration for the [`method: SnapshotAssertions.toMatchSnapshot#1`] method.
- `comparator` ?<[string]> a comparator function to use, either `"pixelmatch"` or `"ssim-cie94"`. Defaults to `"pixelmatch"`. - `threshold` ?<[float]> an acceptable perceived color difference between the same pixel in compared images, ranging from `0` (strict) and `1` (lax). `"pixelmatch"` comparator computes color difference in [YIQ color space](https://en.wikipedia.org/wiki/YIQ) and defaults `threshold` value to `0.2`.
- `threshold` ?<[float]> an acceptable perceived color difference between the same pixel in compared images, ranging from `0` (strict) and `1` (lax). `"pixelmatch"` comparator computes color difference in [YIQ color space](https://en.wikipedia.org/wiki/YIQ) and defaults `threshold` value to `0.2`. This option is used by `pixelmatch` image comparator.
- `maxDiffPixels` ?<[int]> an acceptable amount of pixels that could be different, unset by default. - `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. - `maxDiffPixelRatio` ?<[float]> an acceptable ratio of pixels that are different to the total amount of pixels, between `0` and `1` , unset by default.

View file

@ -133,16 +133,14 @@ export default defineConfig({
- type: ?<[Object]> - type: ?<[Object]>
- `timeout` ?<[int]> Default timeout for async expect matchers in milliseconds, defaults to 5000ms. - `timeout` ?<[int]> Default timeout for async expect matchers in milliseconds, defaults to 5000ms.
- `toHaveScreenshot` ?<[Object]> Configuration for the [`method: PageAssertions.toHaveScreenshot#1`] method. - `toHaveScreenshot` ?<[Object]> Configuration for the [`method: PageAssertions.toHaveScreenshot#1`] method.
- `comparator` ?<[string]> a comparator function to use, either `"pixelmatch"` or `"ssim-cie94"`. Defaults to `"pixelmatch"`. - `threshold` ?<[float]> an acceptable perceived color difference between the same pixel in compared images, ranging from `0` (strict) and `1` (lax). `"pixelmatch"` comparator computes color difference in [YIQ color space](https://en.wikipedia.org/wiki/YIQ) and defaults `threshold` value to `0.2`.
- `threshold` ?<[float]> an acceptable perceived color difference between the same pixel in compared images, ranging from `0` (strict) and `1` (lax). `"pixelmatch"` comparator computes color difference in [YIQ color space](https://en.wikipedia.org/wiki/YIQ) and defaults `threshold` value to `0.2`. This option is used by `pixelmatch` image comparator.
- `maxDiffPixels` ?<[int]> an acceptable amount of pixels that could be different, unset by default. - `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. - `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"|"disabled">> See [`option: animations`] in [`method: Page.screenshot`]. Defaults to `"disabled"`. - `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"`. - `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"`. - `scale` ?<[ScreenshotScale]<"css"|"device">> See [`option: scale`] in [`method: Page.screenshot`]. Defaults to `"css"`.
- `toMatchSnapshot` ?<[Object]> Configuration for the [`method: SnapshotAssertions.toMatchSnapshot#1`] method. - `toMatchSnapshot` ?<[Object]> Configuration for the [`method: SnapshotAssertions.toMatchSnapshot#1`] method.
- `comparator` ?<[string]> a comparator function to use, either `"pixelmatch"` or `"ssim-cie94"`. Defaults to `"pixelmatch"`. - `threshold` ?<[float]> an acceptable perceived color difference between the same pixel in compared images, ranging from `0` (strict) and `1` (lax). `"pixelmatch"` comparator computes color difference in [YIQ color space](https://en.wikipedia.org/wiki/YIQ) and defaults `threshold` value to `0.2`.
- `threshold` ?<[float]> an acceptable perceived color difference between the same pixel in compared images, ranging from `0` (strict) and `1` (lax). `"pixelmatch"` comparator computes color difference in [YIQ color space](https://en.wikipedia.org/wiki/YIQ) and defaults `threshold` value to `0.2`. This option is used by `pixelmatch` image comparator.
- `maxDiffPixels` ?<[int]> an acceptable amount of pixels that could be different, unset by default. - `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. - `maxDiffPixelRatio` ?<[float]> an acceptable ratio of pixels that are different to the total amount of pixels, between `0` and `1` , unset by default.

View file

@ -181,6 +181,10 @@ export class PageDispatcher extends Dispatcher<Page, channels.PageChannel, Brows
return await this._page.expectScreenshot(metadata, { return await this._page.expectScreenshot(metadata, {
...params, ...params,
locator, locator,
comparatorOptions: {
...params.comparatorOptions,
_comparator: params.comparatorOptions?.comparator,
},
screenshotOptions: { screenshotOptions: {
...params.screenshotOptions, ...params.screenshotOptions,
mask, mask,

View file

@ -21,7 +21,7 @@ import { compare } from '../image_tools/compare';
const { diff_match_patch, DIFF_INSERT, DIFF_DELETE, DIFF_EQUAL } = require('../third_party/diff_match_patch'); const { diff_match_patch, DIFF_INSERT, DIFF_DELETE, DIFF_EQUAL } = require('../third_party/diff_match_patch');
import { PNG } from '../utilsBundle'; import { PNG } from '../utilsBundle';
export type ImageComparatorOptions = { threshold?: number, maxDiffPixels?: number, maxDiffPixelRatio?: number, comparator?: string }; export type ImageComparatorOptions = { threshold?: number, maxDiffPixels?: number, maxDiffPixelRatio?: number, _comparator?: string };
export type ComparatorResult = { diff?: Buffer; errorMessage: string; } | null; export type ComparatorResult = { diff?: Buffer; errorMessage: string; } | null;
export type Comparator = (actualBuffer: Buffer | string, expectedBuffer: Buffer, options?: any) => ComparatorResult; export type Comparator = (actualBuffer: Buffer | string, expectedBuffer: Buffer, options?: any) => ComparatorResult;
@ -64,18 +64,18 @@ function compareImages(mimeType: string, actualBuffer: Buffer | string, expected
} }
const diff = new PNG({ width: size.width, height: size.height }); const diff = new PNG({ width: size.width, height: size.height });
let count; let count;
if (options.comparator === 'ssim-cie94') { if (options._comparator === 'ssim-cie94') {
count = compare(expected.data, actual.data, diff.data, size.width, size.height, { count = compare(expected.data, actual.data, diff.data, size.width, size.height, {
// All ΔE* formulae are originally designed to have the difference of 1.0 stand for a "just noticeable difference" (JND). // All ΔE* formulae are originally designed to have the difference of 1.0 stand for a "just noticeable difference" (JND).
// See https://en.wikipedia.org/wiki/Color_difference#CIELAB_%CE%94E* // See https://en.wikipedia.org/wiki/Color_difference#CIELAB_%CE%94E*
maxColorDeltaE94: 1.0, maxColorDeltaE94: 1.0,
}); });
} else if ((options.comparator ?? 'pixelmatch') === 'pixelmatch') { } else if ((options._comparator ?? 'pixelmatch') === 'pixelmatch') {
count = pixelmatch(expected.data, actual.data, diff.data, size.width, size.height, { count = pixelmatch(expected.data, actual.data, diff.data, size.width, size.height, {
threshold: options.threshold ?? 0.2, threshold: options.threshold ?? 0.2,
}); });
} else { } else {
throw new Error(`Configuration specifies unknown comparator "${options.comparator}"`); throw new Error(`Configuration specifies unknown comparator "${options._comparator}"`);
} }
const maxDiffPixels1 = options.maxDiffPixels; const maxDiffPixels1 = options.maxDiffPixels;

View file

@ -145,7 +145,7 @@ class SnapshotHelper<T extends ImageComparatorOptions> {
maxDiffPixels: options.maxDiffPixels, maxDiffPixels: options.maxDiffPixels,
maxDiffPixelRatio: options.maxDiffPixelRatio, maxDiffPixelRatio: options.maxDiffPixelRatio,
threshold: options.threshold, threshold: options.threshold,
comparator: options.comparator, _comparator: options._comparator,
}; };
this.kind = this.mimeType.startsWith('image/') ? 'Screenshot' : 'Snapshot'; this.kind = this.mimeType.startsWith('image/') ? 'Screenshot' : 'Snapshot';
} }
@ -306,7 +306,7 @@ export async function toHaveScreenshot(
const helper = new SnapshotHelper( const helper = new SnapshotHelper(
testInfo, snapshotPathResolver, 'png', testInfo, snapshotPathResolver, 'png',
{ {
comparator: config?.comparator, _comparator: config?._comparator,
maxDiffPixels: config?.maxDiffPixels, maxDiffPixels: config?.maxDiffPixels,
maxDiffPixelRatio: config?.maxDiffPixelRatio, maxDiffPixelRatio: config?.maxDiffPixelRatio,
threshold: config?.threshold, threshold: config?.threshold,
@ -342,7 +342,10 @@ export async function toHaveScreenshot(
expected: await fs.promises.readFile(helper.snapshotPath), expected: await fs.promises.readFile(helper.snapshotPath),
isNot: true, isNot: true,
locator, locator,
comparatorOptions: helper.comparatorOptions, comparatorOptions: {
...helper.comparatorOptions,
comparator: helper.comparatorOptions._comparator,
},
screenshotOptions, screenshotOptions,
timeout: currentExpectTimeout(helper.allOptions), timeout: currentExpectTimeout(helper.allOptions),
})).errorMessage; })).errorMessage;
@ -360,7 +363,7 @@ export async function toHaveScreenshot(
expected: undefined, expected: undefined,
isNot: false, isNot: false,
locator, locator,
comparatorOptions: helper.comparatorOptions, comparatorOptions: { ...helper.comparatorOptions, comparator: helper.comparatorOptions._comparator },
screenshotOptions, screenshotOptions,
timeout, timeout,
}); });
@ -382,7 +385,7 @@ export async function toHaveScreenshot(
expected, expected,
isNot: false, isNot: false,
locator, locator,
comparatorOptions: helper.comparatorOptions, comparatorOptions: { ...helper.comparatorOptions, comparator: helper.comparatorOptions._comparator },
screenshotOptions, screenshotOptions,
timeout: currentExpectTimeout(helper.allOptions), timeout: currentExpectTimeout(helper.allOptions),
}); });

View file

@ -551,16 +551,10 @@ interface TestConfig {
* method. * method.
*/ */
toHaveScreenshot?: { toHaveScreenshot?: {
/**
* a comparator function to use, either `"pixelmatch"` or `"ssim-cie94"`. Defaults to `"pixelmatch"`.
*/
comparator?: string;
/** /**
* an acceptable perceived color difference between the same pixel in compared images, ranging from `0` (strict) and * an acceptable perceived color difference between the same pixel in compared images, ranging from `0` (strict) and
* `1` (lax). `"pixelmatch"` comparator computes color difference in * `1` (lax). `"pixelmatch"` comparator computes color difference in
* [YIQ color space](https://en.wikipedia.org/wiki/YIQ) and defaults `threshold` value to `0.2`. This option is used * [YIQ color space](https://en.wikipedia.org/wiki/YIQ) and defaults `threshold` value to `0.2`.
* by `pixelmatch` image comparator.
*/ */
threshold?: number; threshold?: number;
@ -600,16 +594,10 @@ interface TestConfig {
* method. * method.
*/ */
toMatchSnapshot?: { toMatchSnapshot?: {
/**
* a comparator function to use, either `"pixelmatch"` or `"ssim-cie94"`. Defaults to `"pixelmatch"`.
*/
comparator?: string;
/** /**
* an acceptable perceived color difference between the same pixel in compared images, ranging from `0` (strict) and * an acceptable perceived color difference between the same pixel in compared images, ranging from `0` (strict) and
* `1` (lax). `"pixelmatch"` comparator computes color difference in * `1` (lax). `"pixelmatch"` comparator computes color difference in
* [YIQ color space](https://en.wikipedia.org/wiki/YIQ) and defaults `threshold` value to `0.2`. This option is used * [YIQ color space](https://en.wikipedia.org/wiki/YIQ) and defaults `threshold` value to `0.2`.
* by `pixelmatch` image comparator.
*/ */
threshold?: number; threshold?: number;
@ -4767,11 +4755,6 @@ interface LocatorAssertions {
*/ */
caret?: "hide"|"initial"; caret?: "hide"|"initial";
/**
* A comparator function to use when comparing images. Defaults to `"pixelmatch"`.
*/
comparator?: string;
/** /**
* Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink * Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink
* box `#FF00FF` that completely covers its bounding box. * box `#FF00FF` that completely covers its bounding box.
@ -4808,7 +4791,7 @@ interface LocatorAssertions {
/** /**
* An acceptable perceived color difference in the [YIQ color space](https://en.wikipedia.org/wiki/YIQ) between the * 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), default is configurable with * same pixel in compared images, between zero (strict) and one (lax), default is configurable with
* `TestConfig.expect`. Defaults to `0.2`. This option is used by "pixelmatch" image comparator. * `TestConfig.expect`. Defaults to `0.2`.
*/ */
threshold?: number; threshold?: number;
@ -4849,11 +4832,6 @@ interface LocatorAssertions {
*/ */
caret?: "hide"|"initial"; caret?: "hide"|"initial";
/**
* A comparator function to use when comparing images. Defaults to `"pixelmatch"`.
*/
comparator?: string;
/** /**
* Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink * Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink
* box `#FF00FF` that completely covers its bounding box. * box `#FF00FF` that completely covers its bounding box.
@ -4890,7 +4868,7 @@ interface LocatorAssertions {
/** /**
* An acceptable perceived color difference in the [YIQ color space](https://en.wikipedia.org/wiki/YIQ) between the * 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), default is configurable with * same pixel in compared images, between zero (strict) and one (lax), default is configurable with
* `TestConfig.expect`. Defaults to `0.2`. This option is used by "pixelmatch" image comparator. * `TestConfig.expect`. Defaults to `0.2`.
*/ */
threshold?: number; threshold?: number;
@ -5102,11 +5080,6 @@ interface PageAssertions {
height: number; height: number;
}; };
/**
* A comparator function to use when comparing images. Defaults to `"pixelmatch"`.
*/
comparator?: string;
/** /**
* When true, takes a screenshot of the full scrollable page, instead of the currently visible viewport. Defaults to * When true, takes a screenshot of the full scrollable page, instead of the currently visible viewport. Defaults to
* `false`. * `false`.
@ -5149,7 +5122,7 @@ interface PageAssertions {
/** /**
* An acceptable perceived color difference in the [YIQ color space](https://en.wikipedia.org/wiki/YIQ) between the * 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), default is configurable with * same pixel in compared images, between zero (strict) and one (lax), default is configurable with
* `TestConfig.expect`. Defaults to `0.2`. This option is used by "pixelmatch" image comparator. * `TestConfig.expect`. Defaults to `0.2`.
*/ */
threshold?: number; threshold?: number;
@ -5214,11 +5187,6 @@ interface PageAssertions {
height: number; height: number;
}; };
/**
* A comparator function to use when comparing images. Defaults to `"pixelmatch"`.
*/
comparator?: string;
/** /**
* When true, takes a screenshot of the full scrollable page, instead of the currently visible viewport. Defaults to * When true, takes a screenshot of the full scrollable page, instead of the currently visible viewport. Defaults to
* `false`. * `false`.
@ -5261,7 +5229,7 @@ interface PageAssertions {
/** /**
* An acceptable perceived color difference in the [YIQ color space](https://en.wikipedia.org/wiki/YIQ) between the * 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), default is configurable with * same pixel in compared images, between zero (strict) and one (lax), default is configurable with
* `TestConfig.expect`. Defaults to `0.2`. This option is used by "pixelmatch" image comparator. * `TestConfig.expect`. Defaults to `0.2`.
*/ */
threshold?: number; threshold?: number;
@ -5360,11 +5328,6 @@ interface SnapshotAssertions {
* @param options * @param options
*/ */
toMatchSnapshot(name: string|Array<string>, options?: { toMatchSnapshot(name: string|Array<string>, options?: {
/**
* A comparator function to use when comparing images. Defaults to `"pixelmatch"`.
*/
comparator?: string;
/** /**
* An acceptable ratio of pixels that are different to the total amount of pixels, between `0` and `1`. Default is * An acceptable ratio of pixels that are different to the total amount of pixels, between `0` and `1`. Default is
* configurable with `TestConfig.expect`. Unset by default. * configurable with `TestConfig.expect`. Unset by default.
@ -5380,7 +5343,7 @@ interface SnapshotAssertions {
/** /**
* An acceptable perceived color difference in the [YIQ color space](https://en.wikipedia.org/wiki/YIQ) between the * 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), default is configurable with * same pixel in compared images, between zero (strict) and one (lax), default is configurable with
* `TestConfig.expect`. Defaults to `0.2`. This option is used by "pixelmatch" image comparator. * `TestConfig.expect`. Defaults to `0.2`.
*/ */
threshold?: number; threshold?: number;
}): void; }): void;
@ -5413,11 +5376,6 @@ interface SnapshotAssertions {
* @param options * @param options
*/ */
toMatchSnapshot(options?: { toMatchSnapshot(options?: {
/**
* A comparator function to use when comparing images. Defaults to `"pixelmatch"`.
*/
comparator?: string;
/** /**
* An acceptable ratio of pixels that are different to the total amount of pixels, between `0` and `1`. Default is * An acceptable ratio of pixels that are different to the total amount of pixels, between `0` and `1`. Default is
* configurable with `TestConfig.expect`. Unset by default. * configurable with `TestConfig.expect`. Unset by default.
@ -5438,7 +5396,7 @@ interface SnapshotAssertions {
/** /**
* An acceptable perceived color difference in the [YIQ color space](https://en.wikipedia.org/wiki/YIQ) between the * 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), default is configurable with * same pixel in compared images, between zero (strict) and one (lax), default is configurable with
* `TestConfig.expect`. Defaults to `0.2`. This option is used by "pixelmatch" image comparator. * `TestConfig.expect`. Defaults to `0.2`.
*/ */
threshold?: number; threshold?: number;
}): void; }): void;
@ -5575,16 +5533,10 @@ interface TestProject {
* method. * method.
*/ */
toHaveScreenshot?: { toHaveScreenshot?: {
/**
* a comparator function to use, either `"pixelmatch"` or `"ssim-cie94"`. Defaults to `"pixelmatch"`.
*/
comparator?: string;
/** /**
* an acceptable perceived color difference between the same pixel in compared images, ranging from `0` (strict) and * an acceptable perceived color difference between the same pixel in compared images, ranging from `0` (strict) and
* `1` (lax). `"pixelmatch"` comparator computes color difference in * `1` (lax). `"pixelmatch"` comparator computes color difference in
* [YIQ color space](https://en.wikipedia.org/wiki/YIQ) and defaults `threshold` value to `0.2`. This option is used * [YIQ color space](https://en.wikipedia.org/wiki/YIQ) and defaults `threshold` value to `0.2`.
* by `pixelmatch` image comparator.
*/ */
threshold?: number; threshold?: number;
@ -5624,16 +5576,10 @@ interface TestProject {
* method. * method.
*/ */
toMatchSnapshot?: { toMatchSnapshot?: {
/**
* a comparator function to use, either `"pixelmatch"` or `"ssim-cie94"`. Defaults to `"pixelmatch"`.
*/
comparator?: string;
/** /**
* an acceptable perceived color difference between the same pixel in compared images, ranging from `0` (strict) and * an acceptable perceived color difference between the same pixel in compared images, ranging from `0` (strict) and
* `1` (lax). `"pixelmatch"` comparator computes color difference in * `1` (lax). `"pixelmatch"` comparator computes color difference in
* [YIQ color space](https://en.wikipedia.org/wiki/YIQ) and defaults `threshold` value to `0.2`. This option is used * [YIQ color space](https://en.wikipedia.org/wiki/YIQ) and defaults `threshold` value to `0.2`.
* by `pixelmatch` image comparator.
*/ */
threshold?: number; threshold?: number;

View file

@ -22,5 +22,5 @@ type ImageComparatorOptions = { threshold?: number, maxDiffPixels?: number, maxD
export function comparePNGs(actual: Buffer, expected: Buffer, options: ImageComparatorOptions = {}): ComparatorResult { export function comparePNGs(actual: Buffer, expected: Buffer, options: ImageComparatorOptions = {}): ComparatorResult {
// Strict threshold by default in our tests. // Strict threshold by default in our tests.
return pngComparator(actual, expected, { comparator: 'ssim-cie94', threshold: 0, ...options }); return pngComparator(actual, expected, { _comparator: 'ssim-cie94', threshold: 0, ...options });
} }

View file

@ -47,8 +47,8 @@ const config: Config<CoverageWorkerOptions & PlaywrightWorkerOptions & Playwrigh
outputDir, outputDir,
expect: { expect: {
timeout: 10000, timeout: 10000,
toHaveScreenshot: { comparator: 'ssim-cie94' } as any, toHaveScreenshot: { _comparator: 'ssim-cie94' } as any,
toMatchSnapshot: { comparator: 'ssim-cie94' } as any, toMatchSnapshot: { _comparator: 'ssim-cie94' } as any,
}, },
maxFailures: 100, maxFailures: 100,
timeout: video ? 60000 : 30000, timeout: video ? 60000 : 30000,

View file

@ -631,13 +631,13 @@ test('should respect comparator name', async ({ runInlineTest }) => {
test('should pass', ({}) => { test('should pass', ({}) => {
expect(Buffer.from('${actual.toString('base64')}', 'base64')).toMatchSnapshot('snapshot.png', { expect(Buffer.from('${actual.toString('base64')}', 'base64')).toMatchSnapshot('snapshot.png', {
threshold: 0, threshold: 0,
comparator: 'ssim-cie94', _comparator: 'ssim-cie94',
}); });
}); });
test('should fail', ({}) => { test('should fail', ({}) => {
expect(Buffer.from('${actual.toString('base64')}', 'base64')).toMatchSnapshot('snapshot.png', { expect(Buffer.from('${actual.toString('base64')}', 'base64')).toMatchSnapshot('snapshot.png', {
threshold: 0, threshold: 0,
comparator: 'pixelmatch', _comparator: 'pixelmatch',
}); });
}); });
` `
@ -662,7 +662,7 @@ test('should respect comparator in config', async ({ runInlineTest }) => {
name: 'should-pass', name: 'should-pass',
expect: { expect: {
toMatchSnapshot: { toMatchSnapshot: {
comparator: 'ssim-cie94', _comparator: 'ssim-cie94',
} }
}, },
}, },
@ -670,7 +670,7 @@ test('should respect comparator in config', async ({ runInlineTest }) => {
name: 'should-fail', name: 'should-fail',
expect: { expect: {
toMatchSnapshot: { toMatchSnapshot: {
comparator: 'pixelmatch', _comparator: 'pixelmatch',
} }
}, },
}, },

View file

@ -1040,14 +1040,14 @@ test('should respect comparator name', async ({ runInlineTest }) => {
await page.goto('${actualURL}'); await page.goto('${actualURL}');
await expect(page.locator('img')).toHaveScreenshot('snapshot.png', { await expect(page.locator('img')).toHaveScreenshot('snapshot.png', {
threshold: 0, threshold: 0,
comparator: 'ssim-cie94', _comparator: 'ssim-cie94',
}); });
}); });
pwt.test('should fail', async ({ page }) => { pwt.test('should fail', async ({ page }) => {
await page.goto('${actualURL}'); await page.goto('${actualURL}');
await expect(page.locator('img')).toHaveScreenshot('snapshot.png', { await expect(page.locator('img')).toHaveScreenshot('snapshot.png', {
threshold: 0, threshold: 0,
comparator: 'pixelmatch', _comparator: 'pixelmatch',
}); });
}); });
` `
@ -1070,7 +1070,7 @@ test('should respect comparator in config', async ({ runInlineTest }) => {
name: 'should-pass', name: 'should-pass',
expect: { expect: {
toHaveScreenshot: { toHaveScreenshot: {
comparator: 'ssim-cie94', _comparator: 'ssim-cie94',
} }
}, },
}, },
@ -1078,7 +1078,7 @@ test('should respect comparator in config', async ({ runInlineTest }) => {
name: 'should-fail', name: 'should-fail',
expect: { expect: {
toHaveScreenshot: { toHaveScreenshot: {
comparator: 'pixelmatch', _comparator: 'pixelmatch',
} }
}, },
}, },