jest-image-snapshot 6.0.0 → 6.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
+ # [6.1.0](https://github.com/americanexpress/jest-image-snapshot/compare/v6.0.0...v6.1.0) (2022-12-02)
2
+
3
+
4
+ ### Features
5
+
6
+ * add onlyDiff in options ([#317](https://github.com/americanexpress/jest-image-snapshot/issues/317)) ([4bad752](https://github.com/americanexpress/jest-image-snapshot/commit/4bad752571bb567861ddfa2cc9073f33c4239352))
7
+
1
8
  # [6.0.0](https://github.com/americanexpress/jest-image-snapshot/compare/v5.2.0...v6.0.0) (2022-11-03)
2
9
 
3
10
 
package/README.md CHANGED
@@ -113,6 +113,7 @@ See [the examples](./examples/README.md) for more detailed usage or read about a
113
113
  * `customReceivedDir`: A custom absolute path of a directory to keep this received image in
114
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.
115
115
  * `diffDirection`: (default: `horizontal`) (options `horizontal` or `vertical`) Changes diff image layout direction
116
+ * `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`).
116
117
  * `noColors`: Removes coloring from console output, useful if storing the results in a file
117
118
  * `failureThreshold`: (default `0`) Sets the threshold that would trigger a test failure based on the `failureThresholdType` selected. This is different to the `customDiffConfig.threshold` above, that is the per pixel failure threshold, this is the failure threshold for the entire comparison.
118
119
  * `failureThresholdType`: (default `pixel`) (options `percent` or `pixel`) Sets the type of threshold that would trigger a failure.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jest-image-snapshot",
3
- "version": "6.0.0",
3
+ "version": "6.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": {
@@ -184,6 +184,24 @@ const shouldFail = ({
184
184
  };
185
185
  };
186
186
 
187
+ function composeDiff(options) {
188
+ const {
189
+ diffDirection, baselineImage, diffImage, receivedImage, imageWidth, imageHeight, onlyDiff,
190
+ } = options;
191
+ const composer = new ImageComposer({
192
+ direction: diffDirection,
193
+ });
194
+
195
+ if (onlyDiff) {
196
+ composer.addImage(diffImage, imageWidth, imageHeight);
197
+ } else {
198
+ composer.addImage(baselineImage, imageWidth, imageHeight);
199
+ composer.addImage(diffImage, imageWidth, imageHeight);
200
+ composer.addImage(receivedImage, imageWidth, imageHeight);
201
+ }
202
+ return composer;
203
+ }
204
+
187
205
  function diffImageToSnapshot(options) {
188
206
  const {
189
207
  receivedImageBuffer,
@@ -193,6 +211,7 @@ function diffImageToSnapshot(options) {
193
211
  receivedDir = path.join(options.snapshotsDir, '__received_output__'),
194
212
  diffDir = path.join(options.snapshotsDir, '__diff_output__'),
195
213
  diffDirection,
214
+ onlyDiff = false,
196
215
  updateSnapshot = false,
197
216
  updatePassedSnapshot = false,
198
217
  customDiffConfig = {},
@@ -281,14 +300,10 @@ function diffImageToSnapshot(options) {
281
300
  }
282
301
 
283
302
  mkdirp.sync(path.dirname(diffOutputPath));
284
- const composer = new ImageComposer({
285
- direction: diffDirection,
303
+ const composer = composeDiff({
304
+ diffDirection, baselineImage, diffImage, receivedImage, imageWidth, imageHeight, onlyDiff,
286
305
  });
287
306
 
288
- composer.addImage(baselineImage, imageWidth, imageHeight);
289
- composer.addImage(diffImage, imageWidth, imageHeight);
290
- composer.addImage(receivedImage, imageWidth, imageHeight);
291
-
292
307
  const composerParams = composer.getParams();
293
308
 
294
309
  const compositeResultImage = new PNG({
@@ -335,6 +350,7 @@ function diffImageToSnapshot(options) {
335
350
  return result;
336
351
  }
337
352
 
353
+
338
354
  function runDiffImageToSnapshot(options) {
339
355
  options.receivedImageBuffer = options.receivedImageBuffer.toString('base64');
340
356
 
package/src/index.js CHANGED
@@ -138,6 +138,7 @@ function configureToMatchImageSnapshot({
138
138
  storeReceivedOnFailure: commonStoreReceivedOnFailure = false,
139
139
  customReceivedDir: commonCustomReceivedDir,
140
140
  customDiffDir: commonCustomDiffDir,
141
+ onlyDiff: commonOnlyDiff = false,
141
142
  diffDirection: commonDiffDirection = 'horizontal',
142
143
  noColors: commonNoColors,
143
144
  failureThreshold: commonFailureThreshold = 0,
@@ -156,6 +157,7 @@ function configureToMatchImageSnapshot({
156
157
  storeReceivedOnFailure = commonStoreReceivedOnFailure,
157
158
  customReceivedDir = commonCustomReceivedDir,
158
159
  customDiffDir = commonCustomDiffDir,
160
+ onlyDiff = commonOnlyDiff,
159
161
  diffDirection = commonDiffDirection,
160
162
  customDiffConfig = {},
161
163
  noColors = commonNoColors,
@@ -218,6 +220,7 @@ function configureToMatchImageSnapshot({
218
220
  receivedDir,
219
221
  diffDir,
220
222
  diffDirection,
223
+ onlyDiff,
221
224
  snapshotIdentifier,
222
225
  updateSnapshot: snapshotState._updateSnapshot === 'all',
223
226
  customDiffConfig: Object.assign({}, commonCustomDiffConfig, customDiffConfig),