vitest-screenshot 3.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +66 -13
  2. package/package.json +10 -2
package/README.md CHANGED
@@ -3,24 +3,69 @@
3
3
  [![npm version][npm-badge]][npm-url]
4
4
  [![npm downloads][downloads-badge]][npm-url]
5
5
  [![Tests][tests-badge]][tests-url]
6
+ [![Coverage][coverage-badge]][coverage-url]
6
7
  [![Discord][discord-badge]][discord-url]
7
8
 
8
- `await expect(image).toMatchScreenshot(reference)`: compare an image against a baseline committed next to your
9
- tests, with the same options as Vitest browser mode's `toMatchScreenshot`. Pair it with a native GPU
10
- environment and tests run up to 2.4x faster than in a browser — see the
11
- [blog post](https://ben3d.ca/blog/native-gpu-testing-for-vitest-and-jest) for details.
12
- Backend-agnostic: feed it a canvas from
13
- [`vitest-environment-webgl-node`](../vitest-environment-webgl-node) or
14
- [`vitest-environment-webgpu-node`](../vitest-environment-webgpu-node), an `ImageData`, a WebGPU texture
15
- readback, or pixels from a real browser.
16
-
17
- ## Install
9
+ Image snapshot testing for WebGL and WebGPU in Vitest on Node, without a browser or Playwright.
10
+ `await expect(image).toMatchScreenshot(reference)` compares a canvas, `ImageData` or raw pixels against a
11
+ baseline committed next to your tests, with the same options as Vitest browser mode's `toMatchScreenshot`.
12
+ Pair it with a native GPU environment and tests run up to 2.4x faster than in a browser, see the
13
+ [blog post](https://ben3d.ca/blog/native-gpu-testing-for-vitest-and-jest).
18
14
 
19
15
  ```sh
20
- pnpm add -D vitest vitest-screenshot
16
+ pnpm add -D vitest vitest-screenshot vitest-environment-webgl-node
17
+ ```
18
+
19
+ ```ts
20
+ // vitest.config.ts
21
+ import { defineConfig } from 'vitest/config';
22
+
23
+ export default defineConfig({ test: { environment: 'webgl-node' } });
21
24
  ```
22
25
 
23
- Requires Vitest 4 or 5. Vitest 3 is not supported.
26
+ ```ts
27
+ // clear.test.ts
28
+ import { expect, it } from 'vitest';
29
+ import { extendMatchers } from 'vitest-screenshot';
30
+
31
+ extendMatchers();
32
+
33
+ it('clears to red', async () => {
34
+ const canvas = document.createElement('canvas');
35
+ canvas.width = canvas.height = 16;
36
+ const gl = canvas.getContext('webgl2')!;
37
+ gl.clearColor(1, 0, 0, 1);
38
+ gl.clear(gl.COLOR_BUFFER_BIT);
39
+ await expect(canvas).toMatchScreenshot('red.png');
40
+ });
41
+ ```
42
+
43
+ The first local run writes `__screenshots__/red.png`; commit it, and CI fails if it is missing or differs.
44
+ Backend-agnostic: feed it a canvas from
45
+ [`vitest-environment-webgl-node`](https://github.com/bhouston/vitest-gpu/tree/main/packages/vitest-environment-webgl-node) or
46
+ [`vitest-environment-webgpu-node`](https://github.com/bhouston/vitest-gpu/tree/main/packages/vitest-environment-webgpu-node) (`createCanvas()` there), an `ImageData`,
47
+ a WebGPU texture readback, or pixels from a real browser. With WebGPU, use `environment: 'webgpu-node'` and
48
+ `createCanvas()`; the same assertion works.
49
+
50
+ ## Compared to alternatives
51
+
52
+ | Approach | Notes |
53
+ | --------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
54
+ | Vitest browser mode `toMatchScreenshot` | Screenshots a real browser page. This package offers the same matcher options for pixels you already have in Node. |
55
+ | `toMatchSnapshot` on a pixel buffer | Exact text comparison of data: no image baseline files, no tolerance, no diff image. |
56
+ | `vitest-screenshot` | Image baselines (png, jpg, gif, webp, ...), pixelmatch and ImageMagick-style metric comparators, diff images on failure. |
57
+
58
+ ## Supported versions
59
+
60
+ Vitest 4 and 5 (CI tests both; Vitest 3 is not supported) and Node 22 or later. Image decoding uses
61
+ [sharp](https://sharp.pixelplumbing.com), which ships prebuilt binaries for common platforms. Baselines
62
+ rendered on different GPUs or drivers can differ slightly: use `allowedMismatchedPixelRatio` or the `metrics`
63
+ comparator for baselines shared across machines.
64
+
65
+ ## Useful for
66
+
67
+ Visual regression tests of anything rendered to a canvas or pixel buffer: three.js, Babylon.js, regl, PixiJS and
68
+ raw WebGL or WebGPU scenes. These are compatible use cases, not endorsements.
24
69
 
25
70
  ## Usage
26
71
 
@@ -159,7 +204,13 @@ await expect(image).toMatchScreenshot('baseline.png', {
159
204
  });
160
205
  ```
161
206
 
162
- See [`demo/test/screenshots`](../../demo/test/screenshots) for every source, format and comparator combination.
207
+ See [`demo/test/screenshots`](https://github.com/bhouston/vitest-gpu/tree/main/demo/test/screenshots) for every source, format and comparator combination.
208
+
209
+ ## See also
210
+
211
+ - [`vitest-environment-webgl-node`](https://github.com/bhouston/vitest-gpu/tree/main/packages/vitest-environment-webgl-node) and
212
+ [`vitest-environment-webgpu-node`](https://github.com/bhouston/vitest-gpu/tree/main/packages/vitest-environment-webgpu-node) provide the canvases to compare.
213
+ - [`demo/test/screenshots`](https://github.com/bhouston/vitest-gpu/tree/main/demo/test/screenshots) and the [repository README](https://github.com/bhouston/vitest-gpu#readme).
163
214
 
164
215
  ## Author
165
216
 
@@ -176,3 +227,5 @@ MIT
176
227
  [tests-url]: https://github.com/bhouston/vitest-gpu/actions/workflows/ci.yml
177
228
  [discord-badge]: https://img.shields.io/badge/Discord-Join%20Chat-5865F2?logo=discord&logoColor=white
178
229
  [discord-url]: https://discord.gg/fwupDN493R
230
+ [coverage-badge]: https://codecov.io/gh/bhouston/vitest-gpu/branch/main/graph/badge.svg
231
+ [coverage-url]: https://codecov.io/gh/bhouston/vitest-gpu
package/package.json CHANGED
@@ -1,13 +1,21 @@
1
1
  {
2
2
  "name": "vitest-screenshot",
3
- "version": "3.0.0",
4
- "description": "toMatchScreenshot(): pixel-diff a canvas, Image or ImageData against a committed png/jpg/gif/webp baseline in Vitest",
3
+ "version": "3.0.1",
4
+ "description": "toMatchScreenshot() for Vitest: image-snapshot a WebGL/WebGPU canvas, Image or ImageData against a committed png/jpg/gif/webp baseline",
5
5
  "keywords": [
6
+ "canvas",
7
+ "headless",
8
+ "image-snapshot",
6
9
  "matcher",
7
10
  "pixelmatch",
8
11
  "screenshot",
12
+ "snapshot",
13
+ "testing",
14
+ "toMatchScreenshot",
9
15
  "visual-regression",
16
+ "visual-testing",
10
17
  "vitest",
18
+ "vitest-matcher",
11
19
  "webgl",
12
20
  "webgpu"
13
21
  ],