jest-image-snapshot 6.1.0 → 6.2.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/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # [6.2.0](https://github.com/americanexpress/jest-image-snapshot/compare/v6.1.1...v6.2.0) (2023-07-25)
2
+
3
+
4
+ ### Features
5
+
6
+ * allow configuration of postfix for received screenshots filename ([#328](https://github.com/americanexpress/jest-image-snapshot/issues/328)) ([bade294](https://github.com/americanexpress/jest-image-snapshot/commit/bade294ec2843c62b1dbcbf894faffd3a5708b98))
7
+
8
+ ## [6.1.1](https://github.com/americanexpress/jest-image-snapshot/compare/v6.1.0...v6.1.1) (2023-07-25)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * only updatePassedSnapshot if updateSnapshot is also true ([#327](https://github.com/americanexpress/jest-image-snapshot/issues/327)) ([b9d9c3f](https://github.com/americanexpress/jest-image-snapshot/commit/b9d9c3f16ab0e10a3e1320d03efb52e81675d2aa)), closes [#320](https://github.com/americanexpress/jest-image-snapshot/issues/320) [#322](https://github.com/americanexpress/jest-image-snapshot/issues/322) [#324](https://github.com/americanexpress/jest-image-snapshot/issues/324)
14
+
1
15
  # [6.1.0](https://github.com/americanexpress/jest-image-snapshot/compare/v6.0.0...v6.1.0) (2022-12-02)
2
16
 
3
17
 
package/CONTRIBUTING.md CHANGED
@@ -47,7 +47,7 @@ Verifies that your code matches the American Express code style defined in [`esl
47
47
 
48
48
  Runs unit tests **and** verifies the format of all commit messages on the current branch.
49
49
 
50
- - **`npm posttest`**
50
+ - **`npm run posttest`**
51
51
 
52
52
  Runs linting on the current branch, checks that the commits follow [conventional commits](https://www.conventionalcommits.org/) and verifies that the `package-lock.json` file includes public NPM registry URLs.
53
53
 
package/README.md CHANGED
@@ -111,6 +111,7 @@ See [the examples](./examples/README.md) for more detailed usage or read about a
111
111
  * `customDiffDir`: A custom absolute path of a directory to keep this diff in
112
112
  * `storeReceivedOnFailure`: (default: `false`) Store the received images seperately from the composed diff images on failure. This can be useful when updating baseline images from CI.
113
113
  * `customReceivedDir`: A custom absolute path of a directory to keep this received image in
114
+ * `customReceivedPostfix`: A custom postfix which is added to the snapshot name of the received image, defaults to `-received`
114
115
  * `customSnapshotIdentifier`: A custom name to give this snapshot. If not provided one is computed automatically. When a function is provided it is called with an object containing `testPath`, `currentTestName`, `counter` and `defaultIdentifier` as its first argument. The function must return an identifier to use for the snapshot. If a path is given, the path will be created inside the snapshot/diff directories.
115
116
  * `diffDirection`: (default: `horizontal`) (options `horizontal` or `vertical`) Changes diff image layout direction
116
117
  * `onlyDiff`: (default: `false`) Either only include the difference between the baseline and the received image in the diff image, or include the 3 images (following the direction set by `diffDirection`).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jest-image-snapshot",
3
- "version": "6.1.0",
3
+ "version": "6.2.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": {
@@ -64,7 +64,6 @@
64
64
  "get-stdin": "^5.0.1",
65
65
  "glur": "^1.1.2",
66
66
  "lodash": "^4.17.4",
67
- "mkdirp": "^0.5.1",
68
67
  "pixelmatch": "^5.1.0",
69
68
  "pngjs": "^3.4.0",
70
69
  "rimraf": "^2.6.2",
@@ -73,6 +72,11 @@
73
72
  "peerDependencies": {
74
73
  "jest": ">=20 <=29"
75
74
  },
75
+ "peerDependenciesMeta": {
76
+ "jest": {
77
+ "optional": true
78
+ }
79
+ },
76
80
  "husky": {
77
81
  "hooks": {
78
82
  "pre-commit": "npm test",
@@ -15,7 +15,6 @@
15
15
  const childProcess = require('child_process');
16
16
  const fs = require('fs');
17
17
  const path = require('path');
18
- const mkdirp = require('mkdirp');
19
18
  const pixelmatch = require('pixelmatch');
20
19
  const ssim = require('ssim.js');
21
20
  const { PNG } = require('pngjs');
@@ -148,9 +147,8 @@ const alignImagesToSameSize = (firstImage, secondImage) => {
148
147
 
149
148
  const isFailure = ({ pass, updateSnapshot }) => !pass && !updateSnapshot;
150
149
 
151
- const shouldUpdate = ({ pass, updateSnapshot, updatePassedSnapshot }) => (
152
- (!pass && updateSnapshot) || (pass && updatePassedSnapshot)
153
- );
150
+ const shouldUpdate = ({ pass, updateSnapshot, updatePassedSnapshot }) =>
151
+ updateSnapshot && (!pass || (pass && updatePassedSnapshot));
154
152
 
155
153
  const shouldFail = ({
156
154
  totalPixels,
@@ -208,6 +206,7 @@ function diffImageToSnapshot(options) {
208
206
  snapshotIdentifier,
209
207
  snapshotsDir,
210
208
  storeReceivedOnFailure,
209
+ receivedPostfix = '-received',
211
210
  receivedDir = path.join(options.snapshotsDir, '__received_output__'),
212
211
  diffDir = path.join(options.snapshotsDir, '__diff_output__'),
213
212
  diffDirection,
@@ -226,11 +225,11 @@ function diffImageToSnapshot(options) {
226
225
  let result = {};
227
226
  const baselineSnapshotPath = path.join(snapshotsDir, `${snapshotIdentifier}.png`);
228
227
  if (!fs.existsSync(baselineSnapshotPath)) {
229
- mkdirp.sync(path.dirname(baselineSnapshotPath));
228
+ fs.mkdirSync(path.dirname(baselineSnapshotPath), { recursive: true });
230
229
  fs.writeFileSync(baselineSnapshotPath, receivedImageBuffer);
231
230
  result = { added: true };
232
231
  } else {
233
- const receivedSnapshotPath = path.join(receivedDir, `${snapshotIdentifier}-received.png`);
232
+ const receivedSnapshotPath = path.join(receivedDir, `${snapshotIdentifier}${receivedPostfix}.png`);
234
233
  rimraf.sync(receivedSnapshotPath);
235
234
 
236
235
  const diffOutputPath = path.join(diffDir, `${snapshotIdentifier}-diff.png`);
@@ -294,12 +293,12 @@ function diffImageToSnapshot(options) {
294
293
 
295
294
  if (isFailure({ pass, updateSnapshot })) {
296
295
  if (storeReceivedOnFailure) {
297
- mkdirp.sync(path.dirname(receivedSnapshotPath));
296
+ fs.mkdirSync(path.dirname(receivedSnapshotPath), { recursive: true });
298
297
  fs.writeFileSync(receivedSnapshotPath, receivedImageBuffer);
299
298
  result = { receivedSnapshotPath };
300
299
  }
301
300
 
302
- mkdirp.sync(path.dirname(diffOutputPath));
301
+ fs.mkdirSync(path.dirname(diffOutputPath), { recursive: true });
303
302
  const composer = composeDiff({
304
303
  diffDirection, baselineImage, diffImage, receivedImage, imageWidth, imageHeight, onlyDiff,
305
304
  });
@@ -334,7 +333,7 @@ function diffImageToSnapshot(options) {
334
333
  imgSrcString: `data:image/png;base64,${pngBuffer.toString('base64')}`,
335
334
  };
336
335
  } else if (shouldUpdate({ pass, updateSnapshot, updatePassedSnapshot })) {
337
- mkdirp.sync(path.dirname(baselineSnapshotPath));
336
+ fs.mkdirSync(path.dirname(baselineSnapshotPath), { recursive: true });
338
337
  fs.writeFileSync(baselineSnapshotPath, receivedImageBuffer);
339
338
  result = { updated: true };
340
339
  } else {
package/src/index.js CHANGED
@@ -137,6 +137,7 @@ function configureToMatchImageSnapshot({
137
137
  customSnapshotsDir: commonCustomSnapshotsDir,
138
138
  storeReceivedOnFailure: commonStoreReceivedOnFailure = false,
139
139
  customReceivedDir: commonCustomReceivedDir,
140
+ customReceivedPostfix: commonCustomReceivedPostfix,
140
141
  customDiffDir: commonCustomDiffDir,
141
142
  onlyDiff: commonOnlyDiff = false,
142
143
  diffDirection: commonDiffDirection = 'horizontal',
@@ -156,6 +157,7 @@ function configureToMatchImageSnapshot({
156
157
  customSnapshotsDir = commonCustomSnapshotsDir,
157
158
  storeReceivedOnFailure = commonStoreReceivedOnFailure,
158
159
  customReceivedDir = commonCustomReceivedDir,
160
+ customReceivedPostfix = commonCustomReceivedPostfix,
159
161
  customDiffDir = commonCustomDiffDir,
160
162
  onlyDiff = commonOnlyDiff,
161
163
  diffDirection = commonDiffDirection,
@@ -197,6 +199,7 @@ function configureToMatchImageSnapshot({
197
199
 
198
200
  const snapshotsDir = customSnapshotsDir || path.join(path.dirname(testPath), SNAPSHOTS_DIR);
199
201
  const receivedDir = customReceivedDir;
202
+ const receivedPostfix = customReceivedPostfix;
200
203
  const diffDir = customDiffDir;
201
204
  const baselineSnapshotPath = path.join(snapshotsDir, `${snapshotIdentifier}.png`);
202
205
  OutdatedSnapshotReporter.markTouchedFile(baselineSnapshotPath);
@@ -218,6 +221,7 @@ function configureToMatchImageSnapshot({
218
221
  snapshotsDir,
219
222
  storeReceivedOnFailure,
220
223
  receivedDir,
224
+ receivedPostfix,
221
225
  diffDir,
222
226
  diffDirection,
223
227
  onlyDiff,