jest-image-snapshot 5.2.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 +26 -0
- package/README.md +2 -1
- package/package.json +6 -6
- package/src/diff-snapshot.js +22 -6
- package/src/index.js +6 -2
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,29 @@
|
|
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
|
+
|
8
|
+
# [6.0.0](https://github.com/americanexpress/jest-image-snapshot/compare/v5.2.0...v6.0.0) (2022-11-03)
|
9
|
+
|
10
|
+
|
11
|
+
* chore(jest)!: add support for jest v29 (#309) ([79e53fc](https://github.com/americanexpress/jest-image-snapshot/commit/79e53fc010793f574cd9da783ced895af6987712)), closes [#309](https://github.com/americanexpress/jest-image-snapshot/issues/309)
|
12
|
+
|
13
|
+
|
14
|
+
### BREAKING CHANGES
|
15
|
+
|
16
|
+
* Drop support for Node v12 and Node v17,
|
17
|
+
as Jest v29 does not support these versions.
|
18
|
+
|
19
|
+
* ci(release): use Node v16 for release action
|
20
|
+
|
21
|
+
Node v16 is the current active LTS release of Node.JS
|
22
|
+
|
23
|
+
Co-authored-by: Jamie King <hello@jamieking.me>
|
24
|
+
|
25
|
+
Co-authored-by: Jamie King <hello@jamieking.me>
|
26
|
+
|
1
27
|
# [5.2.0](https://github.com/americanexpress/jest-image-snapshot/compare/v5.1.1...v5.2.0) (2022-08-31)
|
2
28
|
|
3
29
|
|
package/README.md
CHANGED
@@ -75,7 +75,7 @@ Thanks `jest-image-snapshot`, that broken header would not have looked good in p
|
|
75
75
|
npm i --save-dev jest-image-snapshot
|
76
76
|
```
|
77
77
|
|
78
|
-
Please note that `Jest` `>=20 <=
|
78
|
+
Please note that `Jest` `>=20 <=29` is a peerDependency. `jest-image-snapshot` will **not** work with anything below Jest 20.x.x
|
79
79
|
|
80
80
|
### Invocation
|
81
81
|
|
@@ -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,10 +1,10 @@
|
|
1
1
|
{
|
2
2
|
"name": "jest-image-snapshot",
|
3
|
-
"version": "
|
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": {
|
7
|
-
"node": "^
|
7
|
+
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
|
8
8
|
},
|
9
9
|
"scripts": {
|
10
10
|
"lint": "eslint ./ --ignore-path .gitignore --ext .js",
|
@@ -53,14 +53,14 @@
|
|
53
53
|
"eslint-config-amex": "^7.0.0",
|
54
54
|
"husky": "^4.2.1",
|
55
55
|
"image-size": "^0.8.3",
|
56
|
-
"jest": "^
|
57
|
-
"jest-snapshot": "^
|
56
|
+
"jest": "^29.0.0",
|
57
|
+
"jest-snapshot": "^29.0.0",
|
58
58
|
"lockfile-lint": "^4.0.0",
|
59
59
|
"mock-spawn": "^0.2.6",
|
60
60
|
"semantic-release": "^17.0.4"
|
61
61
|
},
|
62
62
|
"dependencies": {
|
63
|
-
"chalk": "^
|
63
|
+
"chalk": "^4.0.0",
|
64
64
|
"get-stdin": "^5.0.1",
|
65
65
|
"glur": "^1.1.2",
|
66
66
|
"lodash": "^4.17.4",
|
@@ -71,7 +71,7 @@
|
|
71
71
|
"ssim.js": "^3.1.1"
|
72
72
|
},
|
73
73
|
"peerDependencies": {
|
74
|
-
"jest": ">=20 <=
|
74
|
+
"jest": ">=20 <=29"
|
75
75
|
},
|
76
76
|
"husky": {
|
77
77
|
"hooks": {
|
package/src/diff-snapshot.js
CHANGED
@@ -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 =
|
285
|
-
|
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
@@ -15,7 +15,7 @@
|
|
15
15
|
const kebabCase = require('lodash/kebabCase');
|
16
16
|
const merge = require('lodash/merge');
|
17
17
|
const path = require('path');
|
18
|
-
const Chalk = require('chalk').
|
18
|
+
const Chalk = require('chalk').Instance;
|
19
19
|
const { diffImageToSnapshot, runDiffImageToSnapshot } = require('./diff-snapshot');
|
20
20
|
const fs = require('fs');
|
21
21
|
const OutdatedSnapshotReporter = require('./outdated-snapshot-reporter');
|
@@ -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,
|
@@ -174,7 +176,8 @@ function configureToMatchImageSnapshot({
|
|
174
176
|
} = this;
|
175
177
|
const chalkOptions = {};
|
176
178
|
if (typeof noColors !== 'undefined') {
|
177
|
-
|
179
|
+
// 1 means basic ANSI 16-color support, 0 means no support
|
180
|
+
chalkOptions.level = noColors ? 0 : 1;
|
178
181
|
}
|
179
182
|
const chalk = new Chalk(chalkOptions);
|
180
183
|
|
@@ -217,6 +220,7 @@ function configureToMatchImageSnapshot({
|
|
217
220
|
receivedDir,
|
218
221
|
diffDir,
|
219
222
|
diffDirection,
|
223
|
+
onlyDiff,
|
220
224
|
snapshotIdentifier,
|
221
225
|
updateSnapshot: snapshotState._updateSnapshot === 'all',
|
222
226
|
customDiffConfig: Object.assign({}, commonCustomDiffConfig, customDiffConfig),
|