jest-image-snapshot 4.3.0 → 4.5.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.
@@ -0,0 +1,33 @@
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. -->
@@ -0,0 +1,31 @@
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
@@ -0,0 +1,37 @@
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
@@ -0,0 +1,43 @@
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
package/CHANGELOG.md CHANGED
@@ -1,3 +1,31 @@
1
+ ## [4.5.1](https://github.com/americanexpress/jest-image-snapshot/compare/v4.5.0...v4.5.1) (2021-06-25)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **deps:** bump glob-parent from 5.1.1 to 5.1.2 ([#276](https://github.com/americanexpress/jest-image-snapshot/issues/276)) ([0c5879e](https://github.com/americanexpress/jest-image-snapshot/commit/0c5879ea2552682208e822d5d696c94121ed7125))
7
+
8
+ # [4.5.0](https://github.com/americanexpress/jest-image-snapshot/compare/v4.4.1...v4.5.0) (2021-04-29)
9
+
10
+
11
+ ### Features
12
+
13
+ * allow folders on snapshot identifier ([#267](https://github.com/americanexpress/jest-image-snapshot/issues/267)) ([ad49a97](https://github.com/americanexpress/jest-image-snapshot/commit/ad49a975a425826245a3f72e4df262db09ce25ea))
14
+
15
+ ## [4.4.1](https://github.com/americanexpress/jest-image-snapshot/compare/v4.4.0...v4.4.1) (2021-04-01)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * incorrect stats reported to jest ([#257](https://github.com/americanexpress/jest-image-snapshot/issues/257)) ([e8f949a](https://github.com/americanexpress/jest-image-snapshot/commit/e8f949a845facf4e0fc47f6f63ab59f791d4148a))
21
+
22
+ # [4.4.0](https://github.com/americanexpress/jest-image-snapshot/compare/v4.3.0...v4.4.0) (2021-02-26)
23
+
24
+
25
+ ### Features
26
+
27
+ * better error message ([#254](https://github.com/americanexpress/jest-image-snapshot/issues/254)) ([af44dd4](https://github.com/americanexpress/jest-image-snapshot/commit/af44dd49bf82caefb289b7780c97a1ba6bcc9e8d))
28
+
1
29
  # [4.3.0](https://github.com/americanexpress/jest-image-snapshot/compare/v4.2.0...v4.3.0) (2020-12-16)
2
30
 
3
31
 
package/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  <h1 align="center">
2
- <img src='https://github.com/americanexpress/jest-image-snapshot/raw/master/jest-image-snapshot.png' alt="Jest Image Snapshot - One Amex" width='50%'/>
2
+ <img src='https://github.com/americanexpress/jest-image-snapshot/raw/main/jest-image-snapshot.png' alt="Jest Image Snapshot - One Amex" width='50%'/>
3
3
  </h1>
4
4
 
5
5
  [![npm](https://img.shields.io/npm/v/jest-image-snapshot)](https://www.npmjs.com/package/jest-image-snapshot)
6
- [![Travis (.org) branch](https://img.shields.io/travis/americanexpress/jest-image-snapshot/master)](https://travis-ci.org/americanexpress/jest-image-snapshot)
6
+ ![Health Check](https://github.com/americanexpress/jest-image-snapshot/workflows/Health%20Check/badge.svg)
7
7
  [![Mentioned in Awesome Jest](https://awesome.re/mentioned-badge.svg)](https://github.com/jest-community/awesome-jest)
8
8
 
9
9
  > Jest matcher that performs image comparisons using [pixelmatch](https://github.com/mapbox/pixelmatch) and behaves just like [Jest snapshots](https://facebook.github.io/jest/docs/snapshot-testing.html) do! Very useful for visual regression testing.
@@ -39,7 +39,7 @@ To update the stored image snapshot run Jest with `--updateSnapshot` or `-u` arg
39
39
 
40
40
  ### See it in action
41
41
 
42
- Typically this matcher is used to for visual tests that run on a browser. For example let's say I finish working on a feature and want to write a test to prevent visual regressions:
42
+ Typically this matcher is used for visual tests that run on a browser. For example let's say I finish working on a feature and want to write a test to prevent visual regressions:
43
43
 
44
44
  ```javascript
45
45
  ...
@@ -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 <=25` is a peerDependency. `jest-image-snapshot` will **not** work with anything below Jest 20.x.x
78
+ Please note that `Jest` `>=20 <=27` is a peerDependency. `jest-image-snapshot` will **not** work with anything below Jest 20.x.x
79
79
 
80
80
  ### Invocation
81
81
 
@@ -109,7 +109,7 @@ 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
- * `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.
112
+ * `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
113
  * `diffDirection`: (default: `horizontal`) (options `horizontal` or `vertical`) Changes diff image layout direction
114
114
  * `noColors`: Removes coloring from console output, useful if storing the results in a file
115
115
  * `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.
@@ -188,7 +188,7 @@ Since SSIM calculates differences in structural similarity by building a moving
188
188
  - Reduced false positives (failing tests when the images look the same)
189
189
  - Higher sensitivity to actual changes in the image itself.
190
190
 
191
- Documentation supporting these claims can be found in the many analyses comparing SSIM to Peak Signal to Noise Ratio (PSNR). See [Wang, Z.; Simoncelli, E. P. (September 2008). "Maximum differentiation (MAD) competition: a methodology for comparing computational models of perceptual quantities"](https://ece.uwaterloo.ca/~z70wang/publications/MAD.pdf) and Zhang, L.; Zhang, L.; Mou, X.; Zhang, D. (September 2012). A comprehensive evaluation of full reference image quality assessment algorithms. 2012 19th IEEE International Conference on Image Processing. pp. 1477–1480. [Wikipedia](http://en.wikipedia.org/wiki/Structural_Similarity) also provides many great reference sources describing the topic.
191
+ Documentation supporting these claims can be found in the many analyses comparing SSIM to Peak Signal to Noise Ratio (PSNR). See [Wang, Z.; Simoncelli, E. P. (September 2008). "Maximum differentiation (MAD) competition: a methodology for comparing computational models of perceptual quantities"](https://ece.uwaterloo.ca/~z70wang/publications/MAD.pdf) and Zhang, L.; Zhang, L.; Mou, X.; Zhang, D. (September 2012). A comprehensive evaluation of full reference image quality assessment algorithms. 2012 19th IEEE International Conference on Image Processing. pp. 1477–1480. [Wikipedia](https://en.wikipedia.org/wiki/Structural_similarity) also provides many great reference sources describing the topic.
192
192
 
193
193
  As such, most users can benefit from setting a 1% or 0.01 threshold for any SSIM comparison. The below code shows a one line modification of the 1% threshold example.
194
194
 
@@ -292,7 +292,7 @@ Please feel free to open pull requests and see [CONTRIBUTING.md](./CONTRIBUTING.
292
292
  ## 🗝️ License
293
293
 
294
294
  Any contributions made under this project will be governed by the [Apache License
295
- 2.0](https://github.com/americanexpress/jest-image-snapshot/blob/master/LICENSE.txt).
295
+ 2.0](https://github.com/americanexpress/jest-image-snapshot/blob/main/LICENSE.txt).
296
296
 
297
297
  ## 🗣️ Code of Conduct
298
298
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jest-image-snapshot",
3
- "version": "4.3.0",
3
+ "version": "4.5.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": {
@@ -10,7 +10,7 @@
10
10
  "lint": "eslint ./ --ignore-path .gitignore --ext .js",
11
11
  "test": "jest --ci=false",
12
12
  "test:lockfile": "lockfile-lint -p package-lock.json -t npm -a npm -o https: -c -i",
13
- "test:git-history": "commitlint --from origin/master --to HEAD",
13
+ "test:git-history": "commitlint --from origin/main --to HEAD",
14
14
  "posttest": "npm run lint && npm run test:git-history && npm run test:lockfile"
15
15
  },
16
16
  "keywords": [
@@ -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": "^26.0.1",
57
- "jest-snapshot": "^26.0.1",
56
+ "jest": "^27.0.4",
57
+ "jest-snapshot": "^27.0.4",
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 <=26"
74
+ "jest": ">=20 <=27"
75
75
  },
76
76
  "husky": {
77
77
  "hooks": {
@@ -80,6 +80,20 @@
80
80
  }
81
81
  },
82
82
  "release": {
83
+ "branches": [
84
+ "+([0-9])?(.{+([0-9]),x}).x",
85
+ "main",
86
+ "next",
87
+ "next-major",
88
+ {
89
+ "name": "beta",
90
+ "prerelease": true
91
+ },
92
+ {
93
+ "name": "alpha",
94
+ "prerelease": true
95
+ }
96
+ ],
83
97
  "plugins": [
84
98
  "@semantic-release/commit-analyzer",
85
99
  "@semantic-release/release-notes-generator",
@@ -87,7 +101,6 @@
87
101
  "@semantic-release/npm",
88
102
  "@semantic-release/git",
89
103
  "@semantic-release/github"
90
- ],
91
- "branch": "master"
104
+ ]
92
105
  }
93
106
  }
@@ -205,7 +205,7 @@ function diffImageToSnapshot(options) {
205
205
  let result = {};
206
206
  const baselineSnapshotPath = path.join(snapshotsDir, `${snapshotIdentifier}-snap.png`);
207
207
  if (!fs.existsSync(baselineSnapshotPath)) {
208
- mkdirp.sync(snapshotsDir);
208
+ mkdirp.sync(path.dirname(baselineSnapshotPath));
209
209
  fs.writeFileSync(baselineSnapshotPath, receivedImageBuffer);
210
210
  result = { added: true };
211
211
  } else {
@@ -269,7 +269,7 @@ function diffImageToSnapshot(options) {
269
269
  });
270
270
 
271
271
  if (isFailure({ pass, updateSnapshot })) {
272
- mkdirp.sync(diffDir);
272
+ mkdirp.sync(path.dirname(diffOutputPath));
273
273
  const composer = new ImageComposer({
274
274
  direction: diffDirection,
275
275
  });
@@ -307,7 +307,7 @@ function diffImageToSnapshot(options) {
307
307
  imgSrcString: `data:image/png;base64,${pngBuffer.toString('base64')}`,
308
308
  };
309
309
  } else if (shouldUpdate({ pass, updateSnapshot, updatePassedSnapshot })) {
310
- mkdirp.sync(snapshotsDir);
310
+ mkdirp.sync(path.dirname(baselineSnapshotPath));
311
311
  fs.writeFileSync(baselineSnapshotPath, receivedImageBuffer);
312
312
  result = { updated: true };
313
313
  } else {
@@ -343,7 +343,7 @@ function runDiffImageToSnapshot(options) {
343
343
  const output = writeDiffProcess.output[3].toString();
344
344
  result = JSON.parse(output);
345
345
  } else {
346
- throw new Error('Error running image diff.');
346
+ throw new Error(`Error running image diff: ${(writeDiffProcess.error && writeDiffProcess.error.message) || 'Unknown Error'}`);
347
347
  }
348
348
 
349
349
  return result;
package/src/index.js CHANGED
@@ -57,9 +57,9 @@ function checkResult({
57
57
  } else {
58
58
  ({ pass } = result);
59
59
 
60
- updateSnapshotState(snapshotState, { matched: snapshotState.matched + 1 });
61
-
62
- if (!pass) {
60
+ if (pass) {
61
+ updateSnapshotState(snapshotState, { matched: snapshotState.matched + 1 });
62
+ } else {
63
63
  const currentRun = timesCalled.get(snapshotIdentifier);
64
64
  if (!retryTimes || (currentRun > retryTimes)) {
65
65
  updateSnapshotState(snapshotState, { unmatched: snapshotState.unmatched + 1 });
package/.travis.yml DELETED
@@ -1,24 +0,0 @@
1
- language: node_js
2
- node_js:
3
- - 10
4
- - 12
5
- - 14
6
- before_install:
7
- # Create a master branch for commitlint
8
- # https://github.com/conventional-changelog/commitlint/issues/6
9
- - git remote set-branches origin master && git fetch
10
- jobs:
11
- include:
12
- # Define the release stage that runs semantic-release
13
- - stage: release
14
- node_js:
15
- - 10
16
- - 12
17
- - 14
18
- deploy:
19
- on:
20
- branch: master
21
- provider: script
22
- skip_cleanup: true
23
- script:
24
- - npx semantic-release