jest-image-snapshot 6.3.0 → 6.5.0

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/.nvmrc ADDED
@@ -0,0 +1 @@
1
+ 20
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # [6.5.0](https://github.com/americanexpress/jest-image-snapshot/compare/v6.4.0...v6.5.0) (2025-05-12)
2
+
3
+
4
+ ### Features
5
+
6
+ * work with TypedArray / Array / ArrayBuffer ([b419a4d](https://github.com/americanexpress/jest-image-snapshot/commit/b419a4dfbd6a34470f2833073f4f714d98a871c9))
7
+
8
+ # [6.4.0](https://github.com/americanexpress/jest-image-snapshot/compare/v6.3.0...v6.4.0) (2023-12-11)
9
+
10
+
11
+ ### Features
12
+
13
+ * add configurable maxBuffer option to runDiffImageToSnapshot ([#344](https://github.com/americanexpress/jest-image-snapshot/issues/344)) ([befad8b](https://github.com/americanexpress/jest-image-snapshot/commit/befad8ba6080be6b0a94d098334ea05258afab2e))
14
+
1
15
  # [6.3.0](https://github.com/americanexpress/jest-image-snapshot/compare/v6.2.0...v6.3.0) (2023-11-28)
2
16
 
3
17
 
package/CONTRIBUTING.md CHANGED
@@ -29,13 +29,19 @@ This project adheres to the American Express [Code of Conduct](./CODE_OF_CONDUCT
29
29
 
30
30
  > replace `your-github-username` with your github username
31
31
 
32
- 3. Install the dependencies by running
32
+ 3. Install and use the correct version of node (specified in `.nvmrc`)
33
+
34
+ ```bash
35
+ $ nvm use
36
+ ```
37
+
38
+ 4. Install the dependencies by running
33
39
 
34
40
  ```bash
35
41
  $ npm install
36
42
  ```
37
43
 
38
- 4. You can now run any of these scripts from the root folder.
44
+ 5. You can now run any of these scripts from the root folder.
39
45
 
40
46
  #### Running tests
41
47
 
@@ -112,4 +118,4 @@ Please review our [Security Policy](./SECURITY.md). Please follow the instructio
112
118
 
113
119
  ### Git Commit Guidelines
114
120
 
115
- We follow [conventional commits](https://www.conventionalcommits.org/) for git commit message formatting. These rules make it easier to review commit logs and improve contextual understanding of code changes. This also allows us to auto-generate the CHANGELOG from commit messages.
121
+ We follow [conventional commits](https://www.conventionalcommits.org/) for git commit message formatting. These rules make it easier to review commit logs and improve contextual understanding of code changes. This also allows us to auto-generate the CHANGELOG from commit messages.
package/README.md CHANGED
@@ -124,6 +124,7 @@ See [the examples](./examples/README.md) for more detailed usage or read about a
124
124
  * `dumpDiffToConsole`: (default `false`) Will output base64 string of a diff image to console in case of failed tests (in addition to creating a diff image). This string can be copy-pasted to a browser address string to preview the diff for a failed test.
125
125
  * `dumpInlineDiffToConsole`: (default `false`) Will output the image to the terminal using iTerm's [Inline Images Protocol](https://iterm2.com/documentation-images.html). If the term is not compatible, it does the same thing as `dumpDiffToConsole`.
126
126
  * `allowSizeMismatch`: (default `false`) If set to true, the build will not fail when the screenshots to compare have different sizes.
127
+ * `maxChildProcessBufferSizeInBytes`: (default `10 * 1024 * 1024`) Sets the max number of bytes for stdout/stderr when running `diff-snapshot` in a child process.
127
128
  * `runtimeHooksPath`: (default `undefined`) This needs to be set to a existing file, like `require.resolve('./runtimeHooksPath.cjs')`. This file can expose a few hooks:
128
129
  * `onBeforeWriteToDisc`: before saving any image to the disc, this function will be called (can be used to write EXIF data to images for instance)
129
130
  `onBeforeWriteToDisc: (arguments: { buffer: Buffer; destination: string; testPath: string; currentTestName: string }) => Buffer`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jest-image-snapshot",
3
- "version": "6.3.0",
3
+ "version": "6.5.0",
4
4
  "description": "Jest matcher for image comparisons. Most commonly used for visual regression testing.",
5
5
  "main": "src/index.js",
6
6
  "engines": {
@@ -53,10 +53,11 @@
53
53
  "eslint-config-amex": "^7.0.0",
54
54
  "husky": "^4.2.1",
55
55
  "image-size": "^0.8.3",
56
- "jest": "^29.0.0",
56
+ "jest": "^29.7.0",
57
57
  "jest-snapshot": "^29.0.0",
58
- "lockfile-lint": "^4.0.0",
58
+ "lockfile-lint": "^4.14.0",
59
59
  "mock-spawn": "^0.2.6",
60
+ "rimraf": "^5.0.10",
60
61
  "semantic-release": "^17.0.4"
61
62
  },
62
63
  "dependencies": {
@@ -66,7 +67,6 @@
66
67
  "lodash": "^4.17.4",
67
68
  "pixelmatch": "^5.1.0",
68
69
  "pngjs": "^3.4.0",
69
- "rimraf": "^2.6.2",
70
70
  "ssim.js": "^3.1.1"
71
71
  },
72
72
  "peerDependencies": {
@@ -106,5 +106,10 @@
106
106
  "@semantic-release/git",
107
107
  "@semantic-release/github"
108
108
  ]
109
+ },
110
+ "overrides": {
111
+ "eslint-config-amex": {
112
+ "eslint": "$eslint"
113
+ }
109
114
  }
110
115
  }
@@ -18,7 +18,6 @@ const path = require('path');
18
18
  const pixelmatch = require('pixelmatch');
19
19
  const ssim = require('ssim.js');
20
20
  const { PNG } = require('pngjs');
21
- const rimraf = require('rimraf');
22
21
  const glur = require('glur');
23
22
  const ImageComposer = require('./image-composer');
24
23
 
@@ -271,10 +270,10 @@ function diffImageToSnapshot(options) {
271
270
  result = { added: true };
272
271
  } else {
273
272
  const receivedSnapshotPath = path.join(receivedDir, `${snapshotIdentifier}${receivedPostfix}.png`);
274
- rimraf.sync(receivedSnapshotPath);
273
+ fs.rmSync(receivedSnapshotPath, { recursive: true, force: true });
275
274
 
276
275
  const diffOutputPath = path.join(diffDir, `${snapshotIdentifier}-diff.png`);
277
- rimraf.sync(diffOutputPath);
276
+ fs.rmSync(diffOutputPath, { recursive: true, force: true });
278
277
 
279
278
  const defaultDiffConfig = comparisonMethod !== 'ssim' ? defaultPixelmatchDiffConfig : defaultSSIMDiffConfig;
280
279
 
@@ -421,7 +420,7 @@ function runDiffImageToSnapshot(options) {
421
420
  {
422
421
  input: Buffer.from(serializedInput),
423
422
  stdio: ['pipe', 'inherit', 'inherit', 'pipe'],
424
- maxBuffer: 10 * 1024 * 1024, // 10 MB
423
+ maxBuffer: options.maxChildProcessBufferSizeInBytes,
425
424
  }
426
425
  );
427
426
 
package/src/index.js CHANGED
@@ -24,6 +24,14 @@ const timesCalled = new Map();
24
24
 
25
25
  const SNAPSHOTS_DIR = '__image_snapshots__';
26
26
 
27
+ function toBuffer(data) {
28
+ if (data == null || Buffer.isBuffer(data)) {
29
+ return data;
30
+ }
31
+
32
+ return Buffer.from(data);
33
+ }
34
+
27
35
  function updateSnapshotState(originalSnapshotState, partialSnapshotState) {
28
36
  if (global.UNSTABLE_SKIP_REPORTING) {
29
37
  return originalSnapshotState;
@@ -151,6 +159,10 @@ function configureToMatchImageSnapshot({
151
159
  dumpDiffToConsole: commonDumpDiffToConsole = false,
152
160
  dumpInlineDiffToConsole: commonDumpInlineDiffToConsole = false,
153
161
  allowSizeMismatch: commonAllowSizeMismatch = false,
162
+ // Default to 10 MB instead of node's default 1 MB
163
+ // See https://nodejs.org/api/child_process.html#child_processspawnsynccommand-args-options
164
+ maxChildProcessBufferSizeInBytes:
165
+ commonMaxChildProcessBufferSizeInBytes = 10 * 1024 * 1024, // 10 MB
154
166
  comparisonMethod: commonComparisonMethod = 'pixelmatch',
155
167
  } = {}) {
156
168
  return function toMatchImageSnapshot(received, {
@@ -173,6 +185,7 @@ function configureToMatchImageSnapshot({
173
185
  dumpDiffToConsole = commonDumpDiffToConsole,
174
186
  dumpInlineDiffToConsole = commonDumpInlineDiffToConsole,
175
187
  allowSizeMismatch = commonAllowSizeMismatch,
188
+ maxChildProcessBufferSizeInBytes = commonMaxChildProcessBufferSizeInBytes,
176
189
  comparisonMethod = commonComparisonMethod,
177
190
  } = {}) {
178
191
  const {
@@ -219,7 +232,7 @@ function configureToMatchImageSnapshot({
219
232
 
220
233
  const result =
221
234
  imageToSnapshot({
222
- receivedImageBuffer: received,
235
+ receivedImageBuffer: toBuffer(received),
223
236
  snapshotsDir,
224
237
  storeReceivedOnFailure,
225
238
  receivedDir,
@@ -237,6 +250,7 @@ function configureToMatchImageSnapshot({
237
250
  updatePassedSnapshot,
238
251
  blur,
239
252
  allowSizeMismatch,
253
+ maxChildProcessBufferSizeInBytes,
240
254
  comparisonMethod,
241
255
  runtimeHooksPath,
242
256
  });