diff --git a/docs/api/browser/assertions.md b/docs/api/browser/assertions.md index 953bb93a6065..3db9c6d3397d 100644 --- a/docs/api/browser/assertions.md +++ b/docs/api/browser/assertions.md @@ -1152,10 +1152,9 @@ await expect.element(getByTestId('button')).toMatchScreenshot('fancy-button', { - `comparatorName: "pixelmatch" = "pixelmatch"` - The name of the algorithm/library used for comparing images. + The algorithm/library used for comparing images. - Currently, [`"pixelmatch"`](https://github.com/mapbox/pixelmatch) is the only - supported comparator. + `"pixelmatch"` is the only built-in comparator, but you can use custom ones by [registering them in the config file](/config/browser/expect#browser-expect-tomatchscreenshot-comparators). - `comparatorOptions: object` @@ -1210,7 +1209,7 @@ await expect.element(getByTestId('button')).toMatchScreenshot('fancy-button', { #### `"pixelmatch"` comparator options -The following options are available when using the `"pixelmatch"` comparator: +The `"pixelmatch"` comparator uses [`@blazediff/core`](https://blazediff.dev/docs/core) under the hood. The following options are available when using it: - `allowedMismatchedPixelRatio: number | undefined = undefined` diff --git a/packages/browser/package.json b/packages/browser/package.json index 6e4235375445..87f4baa9cf0c 100644 --- a/packages/browser/package.json +++ b/packages/browser/package.json @@ -64,10 +64,10 @@ "vitest": "workspace:*" }, "dependencies": { + "@blazediff/core": "1.9.1", "@vitest/mocker": "workspace:*", "@vitest/utils": "workspace:*", "magic-string": "catalog:", - "pixelmatch": "7.1.0", "pngjs": "^7.0.0", "sirv": "catalog:", "tinyrainbow": "catalog:", diff --git a/packages/browser/src/node/commands/screenshotMatcher/comparators/pixelmatch.ts b/packages/browser/src/node/commands/screenshotMatcher/comparators/pixelmatch.ts index 0d9a905c3368..5c8b29c4d06f 100644 --- a/packages/browser/src/node/commands/screenshotMatcher/comparators/pixelmatch.ts +++ b/packages/browser/src/node/commands/screenshotMatcher/comparators/pixelmatch.ts @@ -1,6 +1,6 @@ import type { ScreenshotComparatorRegistry } from '../../../../../context' import type { Comparator } from '../types' -import pm from 'pixelmatch' +import { diff } from '@blazediff/core' const defaultOptions = { allowedMismatchedPixelRatio: undefined, @@ -36,7 +36,7 @@ export const pixelmatch: Comparator ? new Uint8Array(reference.data.length) : undefined - const mismatchedPixels = pm( + const mismatchedPixels = diff( reference.data, actual.data, diffBuffer, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6201105c9113..f626ac513716 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -493,6 +493,9 @@ importers: packages/browser: dependencies: + '@blazediff/core': + specifier: 1.9.1 + version: 1.9.1 '@vitest/mocker': specifier: workspace:* version: link:../mocker @@ -502,9 +505,6 @@ importers: magic-string: specifier: 'catalog:' version: 0.30.21 - pixelmatch: - specifier: 7.1.0 - version: 7.1.0 pngjs: specifier: ^7.0.0 version: 7.0.0 @@ -2271,6 +2271,9 @@ packages: resolution: {integrity: sha512-6zABk/ECA/QYSCQ1NGiVwwbQerUCZ+TQbp64Q3AgmfNvurHH0j8TtXa1qbShXA6qqkpAj4V5W8pP6mLe1mcMqA==} engines: {node: '>=18'} + '@blazediff/core@1.9.1': + resolution: {integrity: sha512-ehg3jIkYKulZh+8om/O25vkvSsXXwC+skXmyA87FFx6A/45eqOkZsBltMw/TVteb0mloiGT8oGRTcjRAz66zaA==} + '@bomb.sh/tab@0.0.12': resolution: {integrity: sha512-dYRwg4MqfHR5/BcTy285XOGRhjQFmNpaJBZ0tl2oU+RY595MQ5ApTF6j3OvauPAooHL6cfoOZMySQrOQztT8RQ==} hasBin: true @@ -8322,10 +8325,6 @@ packages: resolution: {integrity: sha512-o8mkY4E/+LNUf6LzX96ht6k6CEDi65k9G2rjMtBe9Oo+VPKSvl+0GKHuH/AlG+GA5LPG/i5hrekkxUc3s2HU+Q==} hasBin: true - pixelmatch@7.1.0: - resolution: {integrity: sha512-1wrVzJ2STrpmONHKBy228LM1b84msXDUoAzVEl0R8Mz4Ce6EPr+IVtxm8+yvrqLYMHswREkjYFaMxnyGnaY3Ng==} - hasBin: true - pkg-types@1.3.1: resolution: {integrity: sha512-/Jm5M4RvtBFVkKWRu2BLUTNP8/M2a+UwuAX+ae4770q1qVGtfjG+WTCupoZixokjmHiry8uI+dlY8KXYV5HVVQ==} @@ -10951,6 +10950,8 @@ snapshots: '@bcoe/v8-coverage@1.0.2': {} + '@blazediff/core@1.9.1': {} + '@bomb.sh/tab@0.0.12(cac@6.7.14(patch_hash=a8f0f3517a47ce716ed90c0cfe6ae382ab763b021a664ada2a608477d0621588))(citty@0.1.6)': optionalDependencies: cac: 6.7.14(patch_hash=a8f0f3517a47ce716ed90c0cfe6ae382ab763b021a664ada2a608477d0621588) @@ -17221,10 +17222,6 @@ snapshots: dependencies: pngjs: 6.0.0 - pixelmatch@7.1.0: - dependencies: - pngjs: 7.0.0 - pkg-types@1.3.1: dependencies: confbox: 0.1.8