@blazediff/jest 1.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.
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Teimur Gasanov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,277 @@
1
+ # @blazediff/jest
2
+
3
+ <div align="center">
4
+
5
+ [![npm bundle size](https://img.shields.io/bundlephobia/min/%40blazediff%2Fjest)](https://www.npmjs.com/package/@blazediff/jest)
6
+ [![NPM Downloads](https://img.shields.io/npm/dy/%40blazediff%2Fjest)](https://www.npmjs.com/package/@blazediff/jest)
7
+
8
+ </div>
9
+
10
+ Jest matcher for visual regression testing with blazediff. Powered by @blazediff/matcher with Jest-specific snapshot state integration.
11
+
12
+ ## Features
13
+
14
+ - **Native Jest matcher**: `toMatchImageSnapshot()` extends Jest's expect
15
+ - **Snapshot state tracking**: Jest reports accurate snapshot counts (added/matched/updated/failed)
16
+ - **Multiple comparison algorithms**: `core`, `bin`, `ssim`, `msssim`, `hitchhikers-ssim`, `gmsd`
17
+ - **Auto-setup**: Imports and registers automatically
18
+ - **Update mode**: Works with Jest's `-u` flag
19
+ - **TypeScript support**: Full type definitions included
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ npm install --save-dev @blazediff/jest
25
+ ```
26
+
27
+ **Peer dependencies**: Jest >= 27.0.0
28
+
29
+ ## Quick Start
30
+
31
+ ```typescript
32
+ import '@blazediff/jest';
33
+
34
+ describe('Visual Regression Tests', () => {
35
+ it('should match screenshot', async () => {
36
+ const screenshot = await takeScreenshot();
37
+
38
+ await expect(screenshot).toMatchImageSnapshot({
39
+ method: 'core',
40
+ });
41
+ });
42
+ });
43
+ ```
44
+
45
+ ## API Reference
46
+
47
+ ### toMatchImageSnapshot(options?)
48
+
49
+ Jest matcher for image snapshot comparison.
50
+
51
+ <table>
52
+ <tr>
53
+ <th width="500">Parameter</th>
54
+ <th width="500">Type</th>
55
+ <th width="500">Description</th>
56
+ </tr>
57
+ <tr>
58
+ <td><code>options</code></td>
59
+ <td>Partial&lt;MatcherOptions&gt;</td>
60
+ <td>Optional comparison options (see below)</td>
61
+ </tr>
62
+ </table>
63
+
64
+ #### Options
65
+
66
+ <table>
67
+ <tr>
68
+ <th width="500">Option</th>
69
+ <th width="500">Type</th>
70
+ <th width="500">Default</th>
71
+ <th width="500">Description</th>
72
+ </tr>
73
+ <tr>
74
+ <td><code>method</code></td>
75
+ <td>'core' | 'bin' | 'ssim' | 'msssim' | 'hitchhikers-ssim' | 'gmsd'</td>
76
+ <td>'core'</td>
77
+ <td>Comparison algorithm to use</td>
78
+ </tr>
79
+ <tr>
80
+ <td><code>failureThreshold</code></td>
81
+ <td>number</td>
82
+ <td>0</td>
83
+ <td>Number of pixels or percentage difference allowed</td>
84
+ </tr>
85
+ <tr>
86
+ <td><code>failureThresholdType</code></td>
87
+ <td>'pixel' | 'percent'</td>
88
+ <td>'pixel'</td>
89
+ <td>How to interpret failureThreshold</td>
90
+ </tr>
91
+ <tr>
92
+ <td><code>snapshotsDir</code></td>
93
+ <td>string</td>
94
+ <td>'__snapshots__'</td>
95
+ <td>Directory to store snapshots relative to test file</td>
96
+ </tr>
97
+ <tr>
98
+ <td><code>snapshotIdentifier</code></td>
99
+ <td>string</td>
100
+ <td>auto-generated</td>
101
+ <td>Custom identifier for the snapshot file</td>
102
+ </tr>
103
+ <tr>
104
+ <td><code>updateSnapshots</code></td>
105
+ <td>boolean</td>
106
+ <td>false</td>
107
+ <td>Force update snapshots</td>
108
+ </tr>
109
+ <tr>
110
+ <td><code>threshold</code></td>
111
+ <td>number</td>
112
+ <td>0.1</td>
113
+ <td>Color difference threshold (0-1) for core/bin methods</td>
114
+ </tr>
115
+ </table>
116
+
117
+ See [@blazediff/matcher](https://www.npmjs.com/package/@blazediff/matcher) for full options documentation.
118
+
119
+ ## Usage Patterns
120
+
121
+ ### Basic Snapshot Test
122
+
123
+ ```typescript
124
+ import '@blazediff/jest';
125
+
126
+ it('renders correctly', async () => {
127
+ const screenshot = await page.screenshot();
128
+
129
+ await expect(screenshot).toMatchImageSnapshot({
130
+ method: 'core',
131
+ });
132
+ });
133
+ ```
134
+
135
+ ### Different Comparison Methods
136
+
137
+ ```typescript
138
+ // Fast Rust-native comparison (file paths only)
139
+ await expect('/path/to/image.png').toMatchImageSnapshot({
140
+ method: 'bin',
141
+ });
142
+
143
+ // Pure JavaScript comparison
144
+ await expect(imageBuffer).toMatchImageSnapshot({
145
+ method: 'core',
146
+ });
147
+
148
+ // Perceptual similarity (SSIM)
149
+ await expect(imageBuffer).toMatchImageSnapshot({
150
+ method: 'ssim',
151
+ });
152
+
153
+ // Gradient-based comparison
154
+ await expect(imageBuffer).toMatchImageSnapshot({
155
+ method: 'gmsd',
156
+ });
157
+ ```
158
+
159
+ ### Update Snapshots
160
+
161
+ ```bash
162
+ # Update all snapshots
163
+ jest -u
164
+
165
+ # Update snapshots for specific test
166
+ jest -u path/to/test.spec.ts
167
+ ```
168
+
169
+ Or programmatically:
170
+
171
+ ```typescript
172
+ await expect(screenshot).toMatchImageSnapshot({
173
+ method: 'core',
174
+ updateSnapshots: true,
175
+ });
176
+ ```
177
+
178
+ ### Custom Thresholds
179
+
180
+ ```typescript
181
+ // Allow up to 100 pixels difference
182
+ await expect(screenshot).toMatchImageSnapshot({
183
+ method: 'core',
184
+ failureThreshold: 100,
185
+ failureThresholdType: 'pixel',
186
+ });
187
+
188
+ // Allow up to 0.1% difference
189
+ await expect(screenshot).toMatchImageSnapshot({
190
+ method: 'core',
191
+ failureThreshold: 0.1,
192
+ failureThresholdType: 'percent',
193
+ });
194
+ ```
195
+
196
+ ### Custom Snapshot Directory
197
+
198
+ ```typescript
199
+ await expect(screenshot).toMatchImageSnapshot({
200
+ method: 'core',
201
+ snapshotsDir: '__image_snapshots__',
202
+ });
203
+ ```
204
+
205
+ ### Custom Snapshot Identifier
206
+
207
+ ```typescript
208
+ await expect(screenshot).toMatchImageSnapshot({
209
+ method: 'core',
210
+ snapshotIdentifier: 'homepage-desktop-chrome',
211
+ });
212
+ ```
213
+
214
+ ### With Playwright
215
+
216
+ ```typescript
217
+ import { test, expect as playwrightExpect } from '@playwright/test';
218
+ import { expect as jestExpect } from '@jest/globals';
219
+ import '@blazediff/jest';
220
+
221
+ test('visual regression with Playwright', async ({ page }) => {
222
+ await page.goto('https://example.com');
223
+ const screenshot = await page.screenshot();
224
+
225
+ await jestExpect(screenshot).toMatchImageSnapshot({
226
+ method: 'core',
227
+ });
228
+ });
229
+ ```
230
+
231
+ ### Negation
232
+
233
+ ```typescript
234
+ // Assert images are different
235
+ await expect(screenshot).not.toMatchImageSnapshot({
236
+ method: 'core',
237
+ });
238
+ ```
239
+
240
+ ## Snapshot State Tracking
241
+
242
+ This matcher integrates with Jest's snapshot state tracking system. Jest will report accurate counts in test summaries:
243
+
244
+ ```
245
+ Snapshots: 2 added, 1 updated, 5 passed, 8 total
246
+ ```
247
+
248
+ The matcher updates Jest's internal counters:
249
+ - **Added**: New snapshots created
250
+ - **Updated**: Snapshots updated with `-u` flag
251
+ - **Passed**: Existing snapshots matched
252
+ - **Failed**: Snapshot comparisons failed
253
+
254
+ ## TypeScript
255
+
256
+ TypeScript types are included. To use the matcher with TypeScript:
257
+
258
+ ```typescript
259
+ import '@blazediff/jest';
260
+
261
+ declare global {
262
+ namespace jest {
263
+ interface Matchers<R> {
264
+ toMatchImageSnapshot(options?: Partial<import('@blazediff/matcher').MatcherOptions>): Promise<R>;
265
+ }
266
+ }
267
+ }
268
+ ```
269
+
270
+ The type augmentation is automatically included when you import the package.
271
+
272
+ ## Links
273
+
274
+ - [GitHub Repository](https://github.com/teimurjan/blazediff)
275
+ - [Documentation](https://blazediff.dev/docs/jest)
276
+ - [NPM Package](https://www.npmjs.com/package/@blazediff/jest)
277
+ - [@blazediff/matcher](https://www.npmjs.com/package/@blazediff/matcher) - Core matcher logic
@@ -0,0 +1,59 @@
1
+ import { MatcherOptions } from '@blazediff/matcher';
2
+ export { ComparisonResult, ImageInput, MatcherOptions } from '@blazediff/matcher';
3
+
4
+ declare global {
5
+ namespace jest {
6
+ interface Matchers<R> {
7
+ /**
8
+ * Compare an image against a stored snapshot.
9
+ *
10
+ * On first run, creates a new snapshot.
11
+ * On subsequent runs, compares against the stored snapshot.
12
+ *
13
+ * @param options - Matcher options including comparison method and thresholds
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * // Compare file path
18
+ * await expect('/path/to/screenshot.png').toMatchImageSnapshot({
19
+ * method: 'bin',
20
+ * failureThreshold: 100,
21
+ * failureThresholdType: 'pixel',
22
+ * });
23
+ *
24
+ * // Compare image buffer
25
+ * await expect({
26
+ * data: imageBuffer,
27
+ * width: 800,
28
+ * height: 600
29
+ * }).toMatchImageSnapshot({
30
+ * method: 'ssim',
31
+ * failureThreshold: 0.01,
32
+ * failureThresholdType: 'percent',
33
+ * });
34
+ * ```
35
+ */
36
+ toMatchImageSnapshot(options?: Partial<MatcherOptions>): Promise<R>;
37
+ }
38
+ interface Expect {
39
+ toMatchImageSnapshot(options?: Partial<MatcherOptions>): void;
40
+ }
41
+ }
42
+ }
43
+
44
+ /**
45
+ * Setup blazediff matchers for Jest
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * // In your jest setup file
50
+ * import { setupBlazediffMatchers } from '@blazediff/jest';
51
+ * setupBlazediffMatchers();
52
+ *
53
+ * // Or just import the package (auto-setup)
54
+ * import '@blazediff/jest';
55
+ * ```
56
+ */
57
+ declare function setupBlazediffMatchers(): void;
58
+
59
+ export { setupBlazediffMatchers as default, setupBlazediffMatchers };
@@ -0,0 +1,59 @@
1
+ import { MatcherOptions } from '@blazediff/matcher';
2
+ export { ComparisonResult, ImageInput, MatcherOptions } from '@blazediff/matcher';
3
+
4
+ declare global {
5
+ namespace jest {
6
+ interface Matchers<R> {
7
+ /**
8
+ * Compare an image against a stored snapshot.
9
+ *
10
+ * On first run, creates a new snapshot.
11
+ * On subsequent runs, compares against the stored snapshot.
12
+ *
13
+ * @param options - Matcher options including comparison method and thresholds
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * // Compare file path
18
+ * await expect('/path/to/screenshot.png').toMatchImageSnapshot({
19
+ * method: 'bin',
20
+ * failureThreshold: 100,
21
+ * failureThresholdType: 'pixel',
22
+ * });
23
+ *
24
+ * // Compare image buffer
25
+ * await expect({
26
+ * data: imageBuffer,
27
+ * width: 800,
28
+ * height: 600
29
+ * }).toMatchImageSnapshot({
30
+ * method: 'ssim',
31
+ * failureThreshold: 0.01,
32
+ * failureThresholdType: 'percent',
33
+ * });
34
+ * ```
35
+ */
36
+ toMatchImageSnapshot(options?: Partial<MatcherOptions>): Promise<R>;
37
+ }
38
+ interface Expect {
39
+ toMatchImageSnapshot(options?: Partial<MatcherOptions>): void;
40
+ }
41
+ }
42
+ }
43
+
44
+ /**
45
+ * Setup blazediff matchers for Jest
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * // In your jest setup file
50
+ * import { setupBlazediffMatchers } from '@blazediff/jest';
51
+ * setupBlazediffMatchers();
52
+ *
53
+ * // Or just import the package (auto-setup)
54
+ * import '@blazediff/jest';
55
+ * ```
56
+ */
57
+ declare function setupBlazediffMatchers(): void;
58
+
59
+ export { setupBlazediffMatchers as default, setupBlazediffMatchers };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ 'use strict';Object.defineProperty(exports,'__esModule',{value:true});var matcher=require('@blazediff/matcher');async function u(r,a){let{testPath:n,currentTestName:o,snapshotState:t}=this,p=a?.updateSnapshots||process.env.UPDATE_SNAPSHOTS==="true"||process.argv.includes("-u")||process.argv.includes("--updateSnapshot"),e=await matcher.getOrCreateSnapshot(r,{method:"core",...a,updateSnapshots:p},{testPath:n||"",testName:o||"unknown"});if(t&&e.snapshotStatus)switch(e.snapshotStatus){case "added":t.added++,t._dirty=true;break;case "updated":t.updated++,t._dirty=true;break;case "matched":t.matched++;break;case "failed":t.unmatched++;break}return {pass:e.pass,message:()=>e.message}}function s(){expect.extend({toMatchImageSnapshot:u});}s();var h=s;exports.default=h;exports.setupBlazediffMatchers=s;
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ import {getOrCreateSnapshot}from'@blazediff/matcher';async function u(r,a){let{testPath:n,currentTestName:o,snapshotState:t}=this,p=a?.updateSnapshots||process.env.UPDATE_SNAPSHOTS==="true"||process.argv.includes("-u")||process.argv.includes("--updateSnapshot"),e=await getOrCreateSnapshot(r,{method:"core",...a,updateSnapshots:p},{testPath:n||"",testName:o||"unknown"});if(t&&e.snapshotStatus)switch(e.snapshotStatus){case "added":t.added++,t._dirty=true;break;case "updated":t.updated++,t._dirty=true;break;case "matched":t.matched++;break;case "failed":t.unmatched++;break}return {pass:e.pass,message:()=>e.message}}function s(){expect.extend({toMatchImageSnapshot:u});}s();var h=s;export{h as default,s as setupBlazediffMatchers};
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@blazediff/jest",
3
+ "version": "1.0.1",
4
+ "description": "Jest matcher for visual regression testing with blazediff",
5
+ "private": false,
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "main": "dist/index.js",
10
+ "module": "dist/index.mjs",
11
+ "types": "dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.mjs",
16
+ "require": "./dist/index.js"
17
+ }
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "keywords": [
23
+ "jest",
24
+ "image",
25
+ "comparison",
26
+ "diff",
27
+ "visual-testing",
28
+ "matcher",
29
+ "snapshot"
30
+ ],
31
+ "author": "Teimur Gasanov <me@teimurjan.dev> (https://github.com/teimurjan)",
32
+ "repository": "https://github.com/teimurjan/blazediff",
33
+ "homepage": "https://blazediff.dev",
34
+ "license": "MIT",
35
+ "dependencies": {
36
+ "@blazediff/matcher": "1.0.1"
37
+ },
38
+ "devDependencies": {
39
+ "@types/jest": "^29.5.14",
40
+ "@types/node": "^24.3.0",
41
+ "jest": "^29.7.0",
42
+ "ts-jest": "^29.2.6",
43
+ "tsup": "8.5.0",
44
+ "typescript": "5.9.2"
45
+ },
46
+ "peerDependencies": {
47
+ "jest": ">=27.0.0"
48
+ },
49
+ "scripts": {
50
+ "typecheck": "tsc --noEmit",
51
+ "build": "tsup",
52
+ "dev": "tsup --watch",
53
+ "clean": "rm -rf dist",
54
+ "test": "jest"
55
+ }
56
+ }