jest-image-snapshot 4.5.1 → 5.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 +27 -0
- package/README.md +6 -4
- package/package.json +5 -5
- package/src/diff-snapshot.js +13 -1
- package/src/index.js +8 -1
- package/.github/pull_request_template.md +0 -33
- package/.github/workflows/health-check.yml +0 -31
- package/.github/workflows/release.yml +0 -37
- package/.github/workflows/stale.yml +0 -23
- package/.github/workflows/tests.yml +0 -43
- package/images/create-snapshot.gif +0 -0
- package/images/fail-snapshot.gif +0 -0
- package/images/image-diff.png +0 -0
- package/jest-image-snapshot.png +0 -0
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,30 @@
|
|
1
|
+
## [5.1.1](https://github.com/americanexpress/jest-image-snapshot/compare/v5.1.0...v5.1.1) (2022-08-25)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* **diff-snapshot:** make recievedDir optional ([#306](https://github.com/americanexpress/jest-image-snapshot/issues/306)) ([cd4fa73](https://github.com/americanexpress/jest-image-snapshot/commit/cd4fa734dd72f8e590e8b672c3081468a5842a20)), closes [#300](https://github.com/americanexpress/jest-image-snapshot/issues/300)
|
7
|
+
|
8
|
+
# [5.1.0](https://github.com/americanexpress/jest-image-snapshot/compare/v5.0.0...v5.1.0) (2022-05-30)
|
9
|
+
|
10
|
+
|
11
|
+
### Features
|
12
|
+
|
13
|
+
* 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))
|
14
|
+
|
15
|
+
# [5.0.0](https://github.com/americanexpress/jest-image-snapshot/compare/v4.5.1...v5.0.0) (2022-05-30)
|
16
|
+
|
17
|
+
|
18
|
+
### chore
|
19
|
+
|
20
|
+
* **jest:** upgrade v28 ([a902a5b](https://github.com/americanexpress/jest-image-snapshot/commit/a902a5baa87d0925b3ff241d7f592f6e1fc0c8fd)), closes [#296](https://github.com/americanexpress/jest-image-snapshot/issues/296)
|
21
|
+
|
22
|
+
|
23
|
+
### BREAKING CHANGES
|
24
|
+
|
25
|
+
* **jest:** drop support for Node 10 due
|
26
|
+
to jest use of globalThis in Node 12
|
27
|
+
|
1
28
|
## [4.5.1](https://github.com/americanexpress/jest-image-snapshot/compare/v4.5.0...v4.5.1) (2021-06-25)
|
2
29
|
|
3
30
|
|
package/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
<h1 align="center">
|
2
|
-
<img src='https://github.com/americanexpress/jest-image-snapshot/raw/main/jest-image-snapshot.png' alt="Jest Image Snapshot - One Amex" width='50%'/>
|
2
|
+
<img src='https://github.com/americanexpress/jest-image-snapshot/raw/main/images/jest-image-snapshot.png' alt="Jest Image Snapshot - One Amex" width='50%'/>
|
3
3
|
</h1>
|
4
4
|
|
5
5
|
[](https://www.npmjs.com/package/jest-image-snapshot)
|
@@ -53,15 +53,15 @@ it('renders correctly', async () => {
|
|
53
53
|
...
|
54
54
|
```
|
55
55
|
|
56
|
-
<img title="Adding an image snapshot" src="
|
56
|
+
<img title="Adding an image snapshot" src="https://raw.githubusercontent.com/americanexpress/jest-image-snapshot/main/images/create-snapshot.gif" width="50%">
|
57
57
|
|
58
58
|
Then after a few days as I finish adding another feature to my component I notice one of my tests failing!
|
59
59
|
|
60
|
-
<img title="A failing image snapshot test" src="
|
60
|
+
<img title="A failing image snapshot test" src="https://raw.githubusercontent.com/americanexpress/jest-image-snapshot/main/images/fail-snapshot.gif" width="50%">
|
61
61
|
|
62
62
|
Oh no! I must have introduced a regression! Let's see what the diff looks like to identify what I need to fix:
|
63
63
|
|
64
|
-
<img title="Image diff" src="
|
64
|
+
<img title="Image diff" src="https://raw.githubusercontent.com/americanexpress/jest-image-snapshot/main/images/image-diff.png" width="50%">
|
65
65
|
|
66
66
|
And now that I know that I broke the card art I can fix it!
|
67
67
|
|
@@ -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,10 +1,10 @@
|
|
1
1
|
{
|
2
2
|
"name": "jest-image-snapshot",
|
3
|
-
"version": "
|
3
|
+
"version": "5.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": {
|
7
|
-
"node": "
|
7
|
+
"node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0"
|
8
8
|
},
|
9
9
|
"scripts": {
|
10
10
|
"lint": "eslint ./ --ignore-path .gitignore --ext .js",
|
@@ -53,8 +53,8 @@
|
|
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": "^28.0.3",
|
57
|
+
"jest-snapshot": "^28.0.3",
|
58
58
|
"lockfile-lint": "^4.0.0",
|
59
59
|
"mock-spawn": "^0.2.6",
|
60
60
|
"semantic-release": "^17.0.4"
|
@@ -71,7 +71,7 @@
|
|
71
71
|
"ssim.js": "^3.1.1"
|
72
72
|
},
|
73
73
|
"peerDependencies": {
|
74
|
-
"jest": ">=20 <=
|
74
|
+
"jest": ">=20 <=28"
|
75
75
|
},
|
76
76
|
"husky": {
|
77
77
|
"hooks": {
|
package/src/diff-snapshot.js
CHANGED
@@ -189,7 +189,9 @@ function diffImageToSnapshot(options) {
|
|
189
189
|
receivedImageBuffer,
|
190
190
|
snapshotIdentifier,
|
191
191
|
snapshotsDir,
|
192
|
-
|
192
|
+
storeReceivedOnFailure,
|
193
|
+
receivedDir = path.join(options.snapshotsDir, '__received_output__'),
|
194
|
+
diffDir = path.join(options.snapshotsDir, '__diff_output__'),
|
193
195
|
diffDirection,
|
194
196
|
updateSnapshot = false,
|
195
197
|
updatePassedSnapshot = 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,7 +193,8 @@ function configureToMatchImageSnapshot({
|
|
189
193
|
});
|
190
194
|
|
191
195
|
const snapshotsDir = customSnapshotsDir || path.join(path.dirname(testPath), SNAPSHOTS_DIR);
|
192
|
-
const
|
196
|
+
const receivedDir = customReceivedDir;
|
197
|
+
const diffDir = customDiffDir;
|
193
198
|
const baselineSnapshotPath = path.join(snapshotsDir, `${snapshotIdentifier}-snap.png`);
|
194
199
|
OutdatedSnapshotReporter.markTouchedFile(baselineSnapshotPath);
|
195
200
|
|
@@ -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,
|
@@ -1,33 +0,0 @@
|
|
1
|
-
<!--- Provide a general summary of your changes in the Title above -->
|
2
|
-
|
3
|
-
## Description
|
4
|
-
<!--- Describe your changes in detail -->
|
5
|
-
|
6
|
-
## Motivation and Context
|
7
|
-
<!--- Why is this change required? What problem does it solve? -->
|
8
|
-
<!--- If it fixes an open issue, please link to the issue here. -->
|
9
|
-
|
10
|
-
## How Has This Been Tested?
|
11
|
-
<!--- Please describe in detail how you tested your changes. -->
|
12
|
-
<!--- Include details of your testing environment, tests ran to see how -->
|
13
|
-
<!--- your change affects other areas of the code, etc. -->
|
14
|
-
|
15
|
-
## Types of Changes
|
16
|
-
<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
|
17
|
-
- [ ] Bug fix (non-breaking change which fixes an issue)
|
18
|
-
- [ ] New feature (non-breaking change which adds functionality)
|
19
|
-
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
|
20
|
-
- [ ] Documentation (adding or updating documentation)
|
21
|
-
- [ ] Dependency update
|
22
|
-
|
23
|
-
## Checklist:
|
24
|
-
<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
|
25
|
-
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
|
26
|
-
- [ ] My change requires a change to the documentation and I have updated the documentation accordingly.
|
27
|
-
- [ ] My changes are in sync with the code style of this project.
|
28
|
-
- [ ] There aren't any other open Pull Requests for the same issue/update.
|
29
|
-
- [ ] These changes should be applied to a maintenance branch.
|
30
|
-
- [ ] I have added the Apache 2.0 license header to any new files created.
|
31
|
-
|
32
|
-
## What is the Impact to Developers Using Jest-Image-Snapshot?
|
33
|
-
<!--- Please describe how your changes impacts developers using Jest-Image-Snapshot. -->
|
@@ -1,31 +0,0 @@
|
|
1
|
-
name: Health Check
|
2
|
-
|
3
|
-
on:
|
4
|
-
schedule:
|
5
|
-
# At minute 0 past hour 0800 and 2000.
|
6
|
-
- cron: '0 8,20 * * *'
|
7
|
-
|
8
|
-
jobs:
|
9
|
-
tests:
|
10
|
-
runs-on: ubuntu-latest
|
11
|
-
strategy:
|
12
|
-
matrix:
|
13
|
-
node: [ '10.x', '12.x', '14.x', '16.x' ]
|
14
|
-
name: Node ${{ matrix.node }}
|
15
|
-
steps:
|
16
|
-
- uses: actions/checkout@v2
|
17
|
-
- run: |
|
18
|
-
git remote set-branches --add origin main
|
19
|
-
git fetch
|
20
|
-
- name: Setup Node
|
21
|
-
uses: actions/setup-node@v2
|
22
|
-
with:
|
23
|
-
node-version: ${{ matrix.node }}
|
24
|
-
- name: Install Dependencies
|
25
|
-
run: npm ci
|
26
|
-
env:
|
27
|
-
NODE_ENV: development
|
28
|
-
- name: Run Test Script
|
29
|
-
run: npm run test
|
30
|
-
env:
|
31
|
-
NODE_ENV: production
|
@@ -1,37 +0,0 @@
|
|
1
|
-
name: Release
|
2
|
-
|
3
|
-
on:
|
4
|
-
push:
|
5
|
-
branches:
|
6
|
-
- main
|
7
|
-
|
8
|
-
jobs:
|
9
|
-
prepare:
|
10
|
-
runs-on: ubuntu-latest
|
11
|
-
if: "! contains(github.event.head_commit.message, '[skip ci]')"
|
12
|
-
steps:
|
13
|
-
- run: echo "${{ github.event.head_commit.message }}"
|
14
|
-
release:
|
15
|
-
needs: prepare
|
16
|
-
name: Release
|
17
|
-
runs-on: ubuntu-latest
|
18
|
-
steps:
|
19
|
-
- name: Checkout
|
20
|
-
uses: actions/checkout@v2
|
21
|
-
with:
|
22
|
-
persist-credentials: false
|
23
|
-
- name: Setup Node.js
|
24
|
-
uses: actions/setup-node@v2
|
25
|
-
with:
|
26
|
-
node-version: 12
|
27
|
-
- name: Install dependencies
|
28
|
-
run: npm ci
|
29
|
-
- name: Release
|
30
|
-
env:
|
31
|
-
GIT_AUTHOR_EMAIL: ${{ secrets.GIT_AUTHOR_EMAIL }}
|
32
|
-
GIT_AUTHOR_NAME: ${{ secrets.GIT_AUTHOR_NAME }}
|
33
|
-
GIT_COMMITTER_EMAIL: ${{ secrets.GIT_COMMITTER_EMAIL }}
|
34
|
-
GIT_COMMITTER_NAME: ${{ secrets.GIT_COMMITTER_NAME }}
|
35
|
-
GITHUB_TOKEN: ${{ secrets.PA_TOKEN }}
|
36
|
-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
37
|
-
run: npx semantic-release
|
@@ -1,23 +0,0 @@
|
|
1
|
-
name: Mark stale issues and pull requests
|
2
|
-
|
3
|
-
on:
|
4
|
-
schedule:
|
5
|
-
- cron: "0 0 * * *"
|
6
|
-
|
7
|
-
jobs:
|
8
|
-
stale:
|
9
|
-
|
10
|
-
runs-on: ubuntu-latest
|
11
|
-
|
12
|
-
steps:
|
13
|
-
- uses: actions/stale@v3
|
14
|
-
with:
|
15
|
-
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
16
|
-
stale-issue-message: 'This issue is stale because it has been open 30 days with no activity.'
|
17
|
-
stale-pr-message: 'This pull request is stale because it has been open 30 days with no activity.'
|
18
|
-
stale-issue-label: 'stale-issue'
|
19
|
-
exempt-issue-labels: 'enhancement,documentation,good-first-issue,question,bug'
|
20
|
-
stale-pr-label: 'stale-pr'
|
21
|
-
exempt-pr-labels: 'work-in-progress'
|
22
|
-
days-before-stale: 30
|
23
|
-
days-before-close: -1
|
@@ -1,43 +0,0 @@
|
|
1
|
-
name: Tests
|
2
|
-
|
3
|
-
on:
|
4
|
-
pull_request:
|
5
|
-
branches:
|
6
|
-
- main
|
7
|
-
|
8
|
-
jobs:
|
9
|
-
tests:
|
10
|
-
runs-on: ubuntu-latest
|
11
|
-
strategy:
|
12
|
-
matrix:
|
13
|
-
node: [ '10.x','12.x', '14.x', '16.x' ]
|
14
|
-
name: Node ${{ matrix.node }}
|
15
|
-
steps:
|
16
|
-
- uses: actions/checkout@v2
|
17
|
-
- run: |
|
18
|
-
git remote set-branches --add origin main
|
19
|
-
git fetch
|
20
|
-
- name: Setup Node
|
21
|
-
uses: actions/setup-node@v2
|
22
|
-
with:
|
23
|
-
node-version: ${{ matrix.node }}
|
24
|
-
- name: Install Dependencies
|
25
|
-
run: npm ci
|
26
|
-
env:
|
27
|
-
NODE_ENV: development
|
28
|
-
- name: Unit Tests
|
29
|
-
run: npm run test
|
30
|
-
env:
|
31
|
-
NODE_ENV: production
|
32
|
-
- name: Lockfile Lint Test
|
33
|
-
run: npm run test:lockfile
|
34
|
-
env:
|
35
|
-
NODE_ENV: production
|
36
|
-
- name: Git History Test
|
37
|
-
run: npm run test:git-history
|
38
|
-
env:
|
39
|
-
NODE_ENV: production
|
40
|
-
- name: Lint
|
41
|
-
run: npm run lint
|
42
|
-
env:
|
43
|
-
NODE_ENV: production
|
Binary file
|
package/images/fail-snapshot.gif
DELETED
Binary file
|
package/images/image-diff.png
DELETED
Binary file
|
package/jest-image-snapshot.png
DELETED
Binary file
|