jest-image-snapshot 5.0.0 → 5.1.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,10 @@
1
+ # [5.1.0](https://github.com/americanexpress/jest-image-snapshot/compare/v5.0.0...v5.1.0) (2022-05-30)
2
+
3
+
4
+ ### Features
5
+
6
+ * allow storing received screenshot on failure ([#298](https://github.com/americanexpress/jest-image-snapshot/issues/298)) ([cfb81c9](https://github.com/americanexpress/jest-image-snapshot/commit/cfb81c99e1465420f007e180a59559c5d62d1c67))
7
+
1
8
  # [5.0.0](https://github.com/americanexpress/jest-image-snapshot/compare/v4.5.1...v5.0.0) (2022-05-30)
2
9
 
3
10
 
package/README.md CHANGED
@@ -109,6 +109,8 @@ See [the examples](./examples/README.md) for more detailed usage or read about a
109
109
  * `comparisonMethod`: (default: `pixelmatch`) (options `pixelmatch` or `ssim`) The method by which images are compared. `pixelmatch` does a pixel by pixel comparison, whereas `ssim` does a structural similarity comparison. `ssim` is a new experimental feature for jest-image-snapshot, but may become the default comparison method in the future. For a better understanding of how to use SSIM, see [Recommendations when using SSIM Comparison](#recommendations-when-using-ssim-comparison).
110
110
  * `customSnapshotsDir`: A custom absolute path of a directory to keep this snapshot in
111
111
  * `customDiffDir`: A custom absolute path of a directory to keep this diff in
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
+ * `customReceivedDir`: A custom absolute path of a directory to keep this received image in
112
114
  * `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.
113
115
  * `diffDirection`: (default: `horizontal`) (options `horizontal` or `vertical`) Changes diff image layout direction
114
116
  * `noColors`: Removes coloring from console output, useful if storing the results in a file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jest-image-snapshot",
3
- "version": "5.0.0",
3
+ "version": "5.1.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": {
@@ -189,6 +189,8 @@ function diffImageToSnapshot(options) {
189
189
  receivedImageBuffer,
190
190
  snapshotIdentifier,
191
191
  snapshotsDir,
192
+ storeReceivedOnFailure,
193
+ receivedDir,
192
194
  diffDir,
193
195
  diffDirection,
194
196
  updateSnapshot = false,
@@ -209,6 +211,9 @@ function diffImageToSnapshot(options) {
209
211
  fs.writeFileSync(baselineSnapshotPath, receivedImageBuffer);
210
212
  result = { added: true };
211
213
  } else {
214
+ const receivedSnapshotPath = path.join(receivedDir, `${snapshotIdentifier}-received.png`);
215
+ rimraf.sync(receivedSnapshotPath);
216
+
212
217
  const diffOutputPath = path.join(diffDir, `${snapshotIdentifier}-diff.png`);
213
218
  rimraf.sync(diffOutputPath);
214
219
 
@@ -269,6 +274,12 @@ function diffImageToSnapshot(options) {
269
274
  });
270
275
 
271
276
  if (isFailure({ pass, updateSnapshot })) {
277
+ if (storeReceivedOnFailure) {
278
+ mkdirp.sync(path.dirname(receivedSnapshotPath));
279
+ fs.writeFileSync(receivedSnapshotPath, receivedImageBuffer);
280
+ result = { receivedSnapshotPath };
281
+ }
282
+
272
283
  mkdirp.sync(path.dirname(diffOutputPath));
273
284
  const composer = new ImageComposer({
274
285
  direction: diffDirection,
@@ -298,6 +309,7 @@ function diffImageToSnapshot(options) {
298
309
  fs.writeFileSync(diffOutputPath, pngBuffer);
299
310
 
300
311
  result = {
312
+ ...result,
301
313
  pass: false,
302
314
  diffSize,
303
315
  imageDimensions,
package/src/index.js CHANGED
@@ -135,6 +135,8 @@ function configureToMatchImageSnapshot({
135
135
  customDiffConfig: commonCustomDiffConfig = {},
136
136
  customSnapshotIdentifier: commonCustomSnapshotIdentifier,
137
137
  customSnapshotsDir: commonCustomSnapshotsDir,
138
+ storeReceivedOnFailure: commonStoreReceivedOnFailure = false,
139
+ customReceivedDir: commonCustomReceivedDir,
138
140
  customDiffDir: commonCustomDiffDir,
139
141
  diffDirection: commonDiffDirection = 'horizontal',
140
142
  noColors: commonNoColors,
@@ -151,6 +153,8 @@ function configureToMatchImageSnapshot({
151
153
  return function toMatchImageSnapshot(received, {
152
154
  customSnapshotIdentifier = commonCustomSnapshotIdentifier,
153
155
  customSnapshotsDir = commonCustomSnapshotsDir,
156
+ storeReceivedOnFailure = commonStoreReceivedOnFailure,
157
+ customReceivedDir = commonCustomReceivedDir,
154
158
  customDiffDir = commonCustomDiffDir,
155
159
  diffDirection = commonDiffDirection,
156
160
  customDiffConfig = {},
@@ -189,6 +193,7 @@ function configureToMatchImageSnapshot({
189
193
  });
190
194
 
191
195
  const snapshotsDir = customSnapshotsDir || path.join(path.dirname(testPath), SNAPSHOTS_DIR);
196
+ const receivedDir = customReceivedDir || path.join(snapshotsDir, '__received_output__');
192
197
  const diffDir = customDiffDir || path.join(snapshotsDir, '__diff_output__');
193
198
  const baselineSnapshotPath = path.join(snapshotsDir, `${snapshotIdentifier}-snap.png`);
194
199
  OutdatedSnapshotReporter.markTouchedFile(baselineSnapshotPath);
@@ -208,6 +213,8 @@ function configureToMatchImageSnapshot({
208
213
  imageToSnapshot({
209
214
  receivedImageBuffer: received,
210
215
  snapshotsDir,
216
+ storeReceivedOnFailure,
217
+ receivedDir,
211
218
  diffDir,
212
219
  diffDirection,
213
220
  snapshotIdentifier,