jest-image-snapshot 6.1.0 → 6.1.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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [6.1.1](https://github.com/americanexpress/jest-image-snapshot/compare/v6.1.0...v6.1.1) (2023-07-25)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * 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)
7
+
1
8
  # [6.1.0](https://github.com/americanexpress/jest-image-snapshot/compare/v6.0.0...v6.1.0) (2022-12-02)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jest-image-snapshot",
3
- "version": "6.1.0",
3
+ "version": "6.1.1",
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,
@@ -226,7 +224,7 @@ function diffImageToSnapshot(options) {
226
224
  let result = {};
227
225
  const baselineSnapshotPath = path.join(snapshotsDir, `${snapshotIdentifier}.png`);
228
226
  if (!fs.existsSync(baselineSnapshotPath)) {
229
- mkdirp.sync(path.dirname(baselineSnapshotPath));
227
+ fs.mkdirSync(path.dirname(baselineSnapshotPath), { recursive: true });
230
228
  fs.writeFileSync(baselineSnapshotPath, receivedImageBuffer);
231
229
  result = { added: true };
232
230
  } else {
@@ -294,12 +292,12 @@ function diffImageToSnapshot(options) {
294
292
 
295
293
  if (isFailure({ pass, updateSnapshot })) {
296
294
  if (storeReceivedOnFailure) {
297
- mkdirp.sync(path.dirname(receivedSnapshotPath));
295
+ fs.mkdirSync(path.dirname(receivedSnapshotPath), { recursive: true });
298
296
  fs.writeFileSync(receivedSnapshotPath, receivedImageBuffer);
299
297
  result = { receivedSnapshotPath };
300
298
  }
301
299
 
302
- mkdirp.sync(path.dirname(diffOutputPath));
300
+ fs.mkdirSync(path.dirname(diffOutputPath), { recursive: true });
303
301
  const composer = composeDiff({
304
302
  diffDirection, baselineImage, diffImage, receivedImage, imageWidth, imageHeight, onlyDiff,
305
303
  });
@@ -334,7 +332,7 @@ function diffImageToSnapshot(options) {
334
332
  imgSrcString: `data:image/png;base64,${pngBuffer.toString('base64')}`,
335
333
  };
336
334
  } else if (shouldUpdate({ pass, updateSnapshot, updatePassedSnapshot })) {
337
- mkdirp.sync(path.dirname(baselineSnapshotPath));
335
+ fs.mkdirSync(path.dirname(baselineSnapshotPath), { recursive: true });
338
336
  fs.writeFileSync(baselineSnapshotPath, receivedImageBuffer);
339
337
  result = { updated: true };
340
338
  } else {