jest-image-snapshot 2.12.0 → 4.0.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/.github/workflows/stale.yml +22 -0
- package/.travis.yml +20 -12
- package/CHANGELOG.md +52 -0
- package/CONTRIBUTING.md +65 -95
- package/README.md +5 -19
- package/commitlint.config.js +20 -0
- package/package.json +38 -12
- package/src/diff-snapshot.js +61 -34
@@ -0,0 +1,22 @@
|
|
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@v1
|
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-label: 'stale-issue'
|
20
|
+
exempt-pr-label: 'stale-pr'
|
21
|
+
stale-pr-label: 'stale-pr'
|
22
|
+
days-before-stale: 30
|
package/.travis.yml
CHANGED
@@ -1,14 +1,22 @@
|
|
1
1
|
language: node_js
|
2
2
|
node_js:
|
3
|
-
-
|
4
|
-
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
3
|
+
- 10
|
4
|
+
- 12
|
5
|
+
before_install:
|
6
|
+
# Create a master branch for commitlint
|
7
|
+
# https://github.com/conventional-changelog/commitlint/issues/6
|
8
|
+
- git remote set-branches origin master && git fetch
|
9
|
+
jobs:
|
10
|
+
include:
|
11
|
+
# Define the release stage that runs semantic-release
|
12
|
+
- stage: release
|
13
|
+
node_js:
|
14
|
+
- 10
|
15
|
+
- 12
|
16
|
+
deploy:
|
17
|
+
on:
|
18
|
+
branch: master
|
19
|
+
provider: script
|
20
|
+
skip_cleanup: true
|
21
|
+
script:
|
22
|
+
- npx semantic-release
|
package/CHANGELOG.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# [4.0.0](https://github.com/americanexpress/jest-image-snapshot/compare/v3.1.0...v4.0.0) (2020-05-14)
|
2
|
+
|
3
|
+
|
4
|
+
### chore
|
5
|
+
|
6
|
+
* upgrade to jest 26 + drop node 8 support ([#205](https://github.com/americanexpress/jest-image-snapshot/issues/205)) ([4834533](https://github.com/americanexpress/jest-image-snapshot/commit/4834533369dae1533c93ad883e3f66617d7d9c3f))
|
7
|
+
|
8
|
+
|
9
|
+
### BREAKING CHANGES
|
10
|
+
|
11
|
+
* drop node 8 support
|
12
|
+
|
13
|
+
# [3.1.0](https://github.com/americanexpress/jest-image-snapshot/compare/v3.0.1...v3.1.0) (2020-04-17)
|
14
|
+
|
15
|
+
|
16
|
+
### Features
|
17
|
+
|
18
|
+
* **options:** add option to pass on size missmatch ([#174](https://github.com/americanexpress/jest-image-snapshot/issues/174)) ([cee46b1](https://github.com/americanexpress/jest-image-snapshot/commit/cee46b1fc94f962c34900a8b655d22665cea2854)), closes [#83](https://github.com/americanexpress/jest-image-snapshot/issues/83) [#85](https://github.com/americanexpress/jest-image-snapshot/issues/85)
|
19
|
+
|
20
|
+
## [3.0.1](https://github.com/americanexpress/jest-image-snapshot/compare/v3.0.0...v3.0.1) (2020-03-25)
|
21
|
+
|
22
|
+
|
23
|
+
### Performance Improvements
|
24
|
+
|
25
|
+
* **diff-snapshot:** remove logic to bypass diff for identical images ([1be1b00](https://github.com/americanexpress/jest-image-snapshot/commit/1be1b006220b4144f98ad583c8cd6ff629aec7b3))
|
26
|
+
|
27
|
+
# [3.0.0](https://github.com/americanexpress/jest-image-snapshot/compare/v2.12.0...v3.0.0) (2020-03-24)
|
28
|
+
|
29
|
+
|
30
|
+
### Bug Fixes
|
31
|
+
|
32
|
+
* **diff:** small default maxBuffer ([df713f6](https://github.com/americanexpress/jest-image-snapshot/commit/df713f6afb7ec7130ec07e94d6a137a3ea62c5de))
|
33
|
+
* **diff-snapshot:** dumpDiffToConsole base64 string output ([#183](https://github.com/americanexpress/jest-image-snapshot/issues/183)) ([f73079f](https://github.com/americanexpress/jest-image-snapshot/commit/f73079f42f86696831ebe85d718e27d6f1d048c0))
|
34
|
+
|
35
|
+
|
36
|
+
### chore
|
37
|
+
|
38
|
+
* **packages:** updating jest to 25.1 for perf improvements ([#170](https://github.com/americanexpress/jest-image-snapshot/issues/170)) ([eb3dfa6](https://github.com/americanexpress/jest-image-snapshot/commit/eb3dfa605c0344ac4dc42cb7f9f76a5e4a732592))
|
39
|
+
* **packages:** upgrade from pixelmatch 4.x to 5.x, and pngjs to 3.4 ([#186](https://github.com/americanexpress/jest-image-snapshot/issues/186)) ([1edc9a3](https://github.com/americanexpress/jest-image-snapshot/commit/1edc9a31db2130b1eafb45738ebc81fa544d380f))
|
40
|
+
* **travis:** remove node 6 from travis config ([ce2b757](https://github.com/americanexpress/jest-image-snapshot/commit/ce2b757a6f337ac156e901a0f1e2851f94d0e7b2))
|
41
|
+
|
42
|
+
|
43
|
+
### Features
|
44
|
+
|
45
|
+
* **diff:** increase the maxBuffer to 10MB for the diff process ([#167](https://github.com/americanexpress/jest-image-snapshot/issues/167)) ([0927826](https://github.com/americanexpress/jest-image-snapshot/commit/0927826776e5fee04ea98cba5cd792aa5066e1fd))
|
46
|
+
|
47
|
+
|
48
|
+
### BREAKING CHANGES
|
49
|
+
|
50
|
+
* **packages:** pixelmatch is being major version bumped and so image diffs may be difference
|
51
|
+
* **packages:** Node min version is now 8
|
52
|
+
* **travis:** drop support for node 6
|
package/CONTRIBUTING.md
CHANGED
@@ -1,145 +1,115 @@
|
|
1
|
-
# Contributing
|
1
|
+
# Contributing to jest-image-snapshot
|
2
2
|
|
3
|
-
|
3
|
+
✨ Thank you for taking the time to contribute to this project ✨
|
4
4
|
|
5
|
-
|
5
|
+
## 📖 Table of Contents
|
6
6
|
|
7
|
-
*
|
8
|
-
*
|
9
|
-
*
|
10
|
-
*
|
7
|
+
* [Code of Conduct](#code-of-conduct)
|
8
|
+
* [Developing](#developing)
|
9
|
+
* [Submitting a new feature](#submitting-a-new-feature)
|
10
|
+
* [Reporting bugs](#reporting-bugs)
|
11
|
+
* [Contributing](#getting-in-contact)
|
12
|
+
* [Coding conventions](#coding-conventions)
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
We follow precise rules for git commit message formatting. These rules make it easier to review commit logs and improve contextual understanding of code changes. This also allows us to auto-generate the CHANGELOG from commit messages.
|
15
|
-
|
16
|
-
Each commit message consists of a **header**, **body** and **footer**.
|
14
|
+
## Code of Conduct
|
17
15
|
|
18
|
-
|
16
|
+
This project adheres to the American Express [Code of Conduct](./CODE_OF_CONDUCT.md). By contributing, you are expected to honor these guidelines.
|
19
17
|
|
20
|
-
|
18
|
+
## Developing
|
21
19
|
|
22
|
-
|
20
|
+
### Installation
|
23
21
|
|
24
|
-
|
25
|
-
|
26
|
-
```
|
22
|
+
1. Fork the repository `jest-image-snapshot` to your GitHub account.
|
23
|
+
2. Afterwards run the following commands in your terminal
|
27
24
|
|
28
|
-
|
25
|
+
```bash
|
26
|
+
$ git clone https://github.com/<your-github-username>/jest-image-snapshot
|
27
|
+
$ cd jest-image-snapshot
|
28
|
+
```
|
29
29
|
|
30
|
-
|
30
|
+
> replace `your-github-username` with your github username
|
31
31
|
|
32
|
-
|
32
|
+
3. Install the dependencies by running
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
* **style** (formatting, missing semi colons, etc; no functional code change)
|
38
|
-
* **refactor** (refactoring production code, eg. renaming a variable)
|
39
|
-
* **test** (adding missing tests, refactoring tests; no production code change)
|
40
|
-
* **chore** (updating build/env/packages, etc; no production code change)
|
34
|
+
```bash
|
35
|
+
$ npm install
|
36
|
+
```
|
41
37
|
|
42
|
-
|
38
|
+
4. You can now run any of these scripts from the root folder.
|
43
39
|
|
44
|
-
|
40
|
+
#### Running tests
|
45
41
|
|
46
|
-
|
47
|
-
feat(transactions): added column for quantity
|
48
|
-
feat(BalanceModule): initial setup
|
49
|
-
```
|
42
|
+
- **`npm run lint`**
|
50
43
|
|
51
|
-
|
44
|
+
Verifies that your code matches the American Express code style defined in [`eslint-config-amex`](https://github.com/americanexpress/eslint-config-amex).
|
52
45
|
|
53
|
-
|
54
|
-
fix(transaction/details): missing quantity field
|
55
|
-
```
|
46
|
+
- **`npm test`**
|
56
47
|
|
57
|
-
|
48
|
+
Runs unit tests **and** verifies the format of all commit messages on the current branch.
|
58
49
|
|
59
|
-
|
60
|
-
fix(transaction): missing quantity field in txn details
|
61
|
-
```
|
50
|
+
- **`npm posttest`**
|
62
51
|
|
63
|
-
|
52
|
+
Runs linting on the current branch, checks that the commits follow [conventional commits](https://www.conventionalcommits.org/) and verifies that the `package-lock.json` file includes public NPM registry URLs.
|
64
53
|
|
65
|
-
|
54
|
+
## Submitting a new feature
|
66
55
|
|
67
|
-
|
68
|
-
fix(home/transactions): txn actions not working
|
69
|
-
```
|
56
|
+
When submitting a new feature request or enhancement of an existing feature please review the following:-
|
70
57
|
|
71
|
-
|
58
|
+
### Is your feature request related to a problem
|
72
59
|
|
73
|
-
|
60
|
+
Please provide a clear and concise description of what you want and what your use case is.
|
74
61
|
|
75
|
-
|
62
|
+
### Provide an example
|
76
63
|
|
77
|
-
|
64
|
+
Please include a snippets of the code of the new feature.
|
78
65
|
|
79
|
-
|
80
|
-
$ git commit -m "fix(nav/link): incorrect URL for Travel"
|
81
|
-
```
|
66
|
+
### Describe the suggested enhancement
|
82
67
|
|
83
|
-
|
68
|
+
A clear and concise description of the enhancement to be added include a step-by-step guide if applicable.
|
69
|
+
Add any other context or screenshots or animated GIFs about the feature request
|
84
70
|
|
85
|
-
|
86
|
-
$ git commit -m "fix(nav): incorrect URL for Travel nav item :P"
|
87
|
-
```
|
71
|
+
### Describe alternatives you've considered
|
88
72
|
|
89
|
-
|
73
|
+
A clear and concise description of any alternative solutions or features you've considered.
|
90
74
|
|
91
|
-
|
75
|
+
## Reporting bugs
|
92
76
|
|
93
|
-
|
77
|
+
All issues are submitted within GitHub issues. Please check this before submitting a new issue.
|
94
78
|
|
95
|
-
|
79
|
+
### Describe the bug
|
96
80
|
|
97
|
-
|
98
|
-
$ git commit -m "fix(nav): corrected Travel URL"
|
99
|
-
```
|
81
|
+
A clear and concise description of what the bug is.
|
100
82
|
|
101
|
-
|
83
|
+
### Provide step-by-step guide on how to reproduce the bug
|
102
84
|
|
103
|
-
|
104
|
-
$ git commit -m "fix(nav): broken URL for Travel"
|
105
|
-
```
|
85
|
+
Steps to reproduce the behavior, please provide code snippets or a link to repository
|
106
86
|
|
87
|
+
### Expected behavior
|
107
88
|
|
108
|
-
|
89
|
+
Please provide a description of the expected behavior
|
109
90
|
|
110
|
-
|
91
|
+
### Screenshots
|
111
92
|
|
112
|
-
|
93
|
+
If applicable, add screenshots or animated GIFs to help explain your problem.
|
113
94
|
|
114
|
-
|
95
|
+
### System information
|
115
96
|
|
116
|
-
|
97
|
+
Provide the system information which is not limited to the below:
|
117
98
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
and for Pull Requests, use the format:
|
99
|
+
- Browser (if applies) [e.g. chrome, safari]
|
100
|
+
- Version of jest-image-snapshot: [e.g. 5.0.0]
|
101
|
+
- Node version:[e.g 10.15.1]
|
122
102
|
|
123
|
-
|
124
|
-
Related #37
|
125
|
-
```
|
103
|
+
### Security Bugs
|
126
104
|
|
127
|
-
|
105
|
+
Please review our [Security Policy](./SECURITY.md). Please follow the instructions outlined in the policy.
|
128
106
|
|
129
|
-
|
130
|
-
Closes #17, #26
|
131
|
-
Related #37
|
132
|
-
```
|
133
|
-
> Issues should always be referenced before pull requests, as shown above.
|
107
|
+
## Getting in contact
|
134
108
|
|
135
|
-
|
109
|
+
- Join our [Slack channel](https://one-amex.slack.com) request an invite [here](https://join.slack.com/t/one-amex/shared_invite/enQtOTA0MzEzODExODEwLTlmYzI1Y2U2ZDEwNWJjOTAxYTlmZTYzMjUyNzQyZTdmMWIwZGJmZDM2MDZmYzVjMDk5OWU4OGIwNjJjZWRhMjY)
|
136
110
|
|
137
|
-
|
111
|
+
## Coding conventions
|
138
112
|
|
139
|
-
|
140
|
-
refactor(nav/item): added prop (isActive)
|
141
|
-
|
142
|
-
NavItem now supports an "isActive" property. This property is used to control the styling of active navigation links.
|
113
|
+
### Git Commit Guidelines
|
143
114
|
|
144
|
-
|
145
|
-
```
|
115
|
+
We follow [conventional commits](https://www.conventionalcommits.org/) for git commit message formatting. These rules make it easier to review commit logs and improve contextual understanding of code changes. This also allows us to auto-generate the CHANGELOG from commit messages.
|
package/README.md
CHANGED
@@ -18,12 +18,11 @@ Want to get paid for your contributions to `jest-image-snapshot`?
|
|
18
18
|
* [Features](#-features)
|
19
19
|
* [Usage](#-usage)
|
20
20
|
* [API](#-api)
|
21
|
-
* [Available Scripts](#-available-scripts)
|
22
21
|
* [Contributing](#-contributing)
|
23
22
|
|
24
23
|
## ✨ Features
|
25
24
|
|
26
|
-
* Take image snapshots of your
|
25
|
+
* Take image snapshots of your application
|
27
26
|
* Ability to compare snapshots from a baseline
|
28
27
|
* Update snapshots when you're good with changes
|
29
28
|
* Customize a difference threshold
|
@@ -76,7 +75,7 @@ Thanks `jest-image-snapshot`, that broken header would not have looked good in p
|
|
76
75
|
npm i --save-dev jest-image-snapshot
|
77
76
|
```
|
78
77
|
|
79
|
-
Please note that `Jest` `>=20 <=
|
78
|
+
Please note that `Jest` `>=20 <=25` is a peerDependency. `jest-image-snapshot` will **not** work with anything below Jest 20.x.x
|
80
79
|
|
81
80
|
### Invocation
|
82
81
|
|
@@ -112,9 +111,10 @@ See [the examples](./examples/README.md) for more detailed usage or read about a
|
|
112
111
|
* `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.
|
113
112
|
* `failureThresholdType`: (default `pixel`) (options `percent` or `pixel`) Sets the type of threshold that would trigger a failure.
|
114
113
|
* `updatePassedSnapshot`: (default `false`) Updates a snapshot even if it passed the threshold against the existing one.
|
115
|
-
* `blur`: (default `0`) Applies Gaussian Blur on compared images, accepts radius in pixels as value. Useful when you have noise after scaling images per different resolutions on your target website, usually setting
|
114
|
+
* `blur`: (default `0`) Applies Gaussian Blur on compared images, accepts radius in pixels as value. Useful when you have noise after scaling images per different resolutions on your target website, usually setting its value to 1-2 should be enough to solve that problem.
|
116
115
|
* `runInProcess`: (default `false`) Runs the diff in process without spawning a child process.
|
117
116
|
* `dumpDiffToConsole`: (default `false`) Will output base64 string of a diff image to console in case of failed tests (in addition to creating a diff image). This string can be copy-pasted to a browser address string to preview the diff for a failed test.
|
117
|
+
* `allowSizeMismatch`: (default `false`) If set to true, the build will not fail when the screenshots to compare have different sizes.
|
118
118
|
|
119
119
|
```javascript
|
120
120
|
it('should demonstrate this matcher`s usage with a custom pixelmatch config', () => {
|
@@ -209,20 +209,6 @@ it('renders correctly', async () => {
|
|
209
209
|
...
|
210
210
|
```
|
211
211
|
|
212
|
-
## 📜 Available Scripts
|
213
|
-
|
214
|
-
**`npm run lint`**
|
215
|
-
|
216
|
-
Verifies that your code matches the American Express code style defined in [`eslint-config-amex`](https://github.com/americanexpress/eslint-config-amex).
|
217
|
-
|
218
|
-
**`npm test`**
|
219
|
-
|
220
|
-
Runs unit tests **and** verifies the format of all commit messages on the current branch.
|
221
|
-
|
222
|
-
**`npm posttest`**
|
223
|
-
|
224
|
-
Runs linting on the current branch.
|
225
|
-
|
226
212
|
## 🏆 Contributing
|
227
213
|
|
228
214
|
We welcome Your interest in the American Express Open Source Community on Github.
|
@@ -233,7 +219,7 @@ and to recipients of software distributed by American Express, You reserve all
|
|
233
219
|
right, title, and interest, if any, in and to Your Contributions. Please [fill
|
234
220
|
out the Agreement](https://cla-assistant.io/americanexpress/jest-image-snapshot).
|
235
221
|
|
236
|
-
Please feel free to open pull requests and see [CONTRIBUTING.md](./CONTRIBUTING.md)
|
222
|
+
Please feel free to open pull requests and see [CONTRIBUTING.md](./CONTRIBUTING.md) to learn how to get started contributing.
|
237
223
|
|
238
224
|
## 🗝️ License
|
239
225
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2020 American Express Travel Related Services Company, Inc.
|
3
|
+
*
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
5
|
+
* in compliance with the License. You may obtain a copy of the License at
|
6
|
+
*
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
*
|
9
|
+
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
10
|
+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,either express
|
11
|
+
* or implied. See the License for the specific language governing permissions and limitations
|
12
|
+
* under the License.
|
13
|
+
*/
|
14
|
+
|
15
|
+
module.exports = {
|
16
|
+
extends: ['@commitlint/config-conventional'],
|
17
|
+
rules: {
|
18
|
+
'scope-case': [2, 'always', ['pascal-case', 'camel-case', 'kebab-case']],
|
19
|
+
},
|
20
|
+
};
|
package/package.json
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
{
|
2
2
|
"name": "jest-image-snapshot",
|
3
|
-
"version": "
|
3
|
+
"version": "4.0.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": ">= 10.14.2"
|
8
8
|
},
|
9
9
|
"scripts": {
|
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",
|
14
|
+
"posttest": "npm run lint && npm run test:git-history && npm run test:lockfile"
|
13
15
|
},
|
14
16
|
"keywords": [
|
15
17
|
"test",
|
@@ -42,13 +44,20 @@
|
|
42
44
|
"author": "Andres Escobar <andres.escobar@aexp.com> (https://github.com/anescobar1991)",
|
43
45
|
"license": "Apache-2.0",
|
44
46
|
"devDependencies": {
|
45
|
-
"
|
46
|
-
"
|
47
|
+
"@commitlint/cli": "^8.3.5",
|
48
|
+
"@commitlint/config-conventional": "^8.3.4",
|
49
|
+
"@semantic-release/changelog": "^5.0.0",
|
50
|
+
"@semantic-release/git": "^9.0.0",
|
51
|
+
"amex-jest-preset": "^6.0.1",
|
52
|
+
"eslint": "^6.8.0",
|
47
53
|
"eslint-config-amex": "^7.0.0",
|
48
|
-
"
|
49
|
-
"
|
50
|
-
"
|
51
|
-
"jest-snapshot": "^
|
54
|
+
"husky": "^4.2.1",
|
55
|
+
"image-size": "^0.8.3",
|
56
|
+
"jest": "^26.0.1",
|
57
|
+
"jest-snapshot": "^26.0.1",
|
58
|
+
"semantic-release": "^17.0.4",
|
59
|
+
"lockfile-lint": "^4.0.0",
|
60
|
+
"mock-spawn": "^0.2.6"
|
52
61
|
},
|
53
62
|
"dependencies": {
|
54
63
|
"chalk": "^1.1.3",
|
@@ -56,11 +65,28 @@
|
|
56
65
|
"glur": "^1.1.2",
|
57
66
|
"lodash": "^4.17.4",
|
58
67
|
"mkdirp": "^0.5.1",
|
59
|
-
"pixelmatch": "^
|
60
|
-
"pngjs": "^3.
|
68
|
+
"pixelmatch": "^5.1.0",
|
69
|
+
"pngjs": "^3.4.0",
|
61
70
|
"rimraf": "^2.6.2"
|
62
71
|
},
|
63
72
|
"peerDependencies": {
|
64
|
-
"jest": ">=20 <=
|
73
|
+
"jest": ">=20 <=26"
|
74
|
+
},
|
75
|
+
"husky": {
|
76
|
+
"hooks": {
|
77
|
+
"pre-commit": "npm test",
|
78
|
+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
|
79
|
+
}
|
80
|
+
},
|
81
|
+
"release": {
|
82
|
+
"plugins": [
|
83
|
+
"@semantic-release/commit-analyzer",
|
84
|
+
"@semantic-release/release-notes-generator",
|
85
|
+
"@semantic-release/changelog",
|
86
|
+
"@semantic-release/npm",
|
87
|
+
"@semantic-release/git",
|
88
|
+
"@semantic-release/github"
|
89
|
+
],
|
90
|
+
"branch": "master"
|
65
91
|
}
|
66
92
|
}
|
package/src/diff-snapshot.js
CHANGED
@@ -19,7 +19,6 @@ const mkdirp = require('mkdirp');
|
|
19
19
|
const pixelmatch = require('pixelmatch');
|
20
20
|
const { PNG } = require('pngjs');
|
21
21
|
const rimraf = require('rimraf');
|
22
|
-
const { createHash } = require('crypto');
|
23
22
|
const glur = require('glur');
|
24
23
|
const ImageComposer = require('./image-composer');
|
25
24
|
|
@@ -84,8 +83,39 @@ const shouldUpdate = ({ pass, updateSnapshot, updatePassedSnapshot }) => (
|
|
84
83
|
(!pass && updateSnapshot) || (pass && updatePassedSnapshot)
|
85
84
|
);
|
86
85
|
|
86
|
+
const shouldFail = ({
|
87
|
+
totalPixels,
|
88
|
+
diffPixelCount,
|
89
|
+
hasSizeMismatch,
|
90
|
+
allowSizeMismatch,
|
91
|
+
failureThresholdType,
|
92
|
+
failureThreshold,
|
93
|
+
}) => {
|
94
|
+
let pass = false;
|
95
|
+
let diffSize = false;
|
96
|
+
const diffRatio = diffPixelCount / totalPixels;
|
97
|
+
if (hasSizeMismatch) {
|
98
|
+
// do not fail if allowSizeMismatch is set
|
99
|
+
pass = allowSizeMismatch;
|
100
|
+
diffSize = true;
|
101
|
+
}
|
102
|
+
if (!diffSize || pass === true) {
|
103
|
+
if (failureThresholdType === 'pixel') {
|
104
|
+
pass = diffPixelCount <= failureThreshold;
|
105
|
+
} else if (failureThresholdType === 'percent') {
|
106
|
+
pass = diffRatio <= failureThreshold;
|
107
|
+
} else {
|
108
|
+
throw new Error(`Unknown failureThresholdType: ${failureThresholdType}. Valid options are "pixel" or "percent".`);
|
109
|
+
}
|
110
|
+
}
|
111
|
+
return {
|
112
|
+
pass,
|
113
|
+
diffSize,
|
114
|
+
diffRatio,
|
115
|
+
};
|
116
|
+
};
|
117
|
+
|
87
118
|
function diffImageToSnapshot(options) {
|
88
|
-
/* eslint complexity: ["error", 12] */
|
89
119
|
const {
|
90
120
|
receivedImageBuffer,
|
91
121
|
snapshotIdentifier,
|
@@ -98,6 +128,7 @@ function diffImageToSnapshot(options) {
|
|
98
128
|
failureThreshold,
|
99
129
|
failureThresholdType,
|
100
130
|
blur,
|
131
|
+
allowSizeMismatch = false,
|
101
132
|
} = options;
|
102
133
|
|
103
134
|
let result = {};
|
@@ -142,40 +173,31 @@ function diffImageToSnapshot(options) {
|
|
142
173
|
|
143
174
|
const diffImage = new PNG({ width: imageWidth, height: imageHeight });
|
144
175
|
|
145
|
-
let pass = false;
|
146
|
-
let diffSize = false;
|
147
|
-
let diffRatio = 0;
|
148
176
|
let diffPixelCount = 0;
|
149
177
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
178
|
+
diffPixelCount = pixelmatch(
|
179
|
+
receivedImage.data,
|
180
|
+
baselineImage.data,
|
181
|
+
diffImage.data,
|
182
|
+
imageWidth,
|
183
|
+
imageHeight,
|
184
|
+
diffConfig
|
185
|
+
);
|
154
186
|
|
155
|
-
|
156
|
-
diffPixelCount = pixelmatch(
|
157
|
-
receivedImage.data,
|
158
|
-
baselineImage.data,
|
159
|
-
diffImage.data,
|
160
|
-
imageWidth,
|
161
|
-
imageHeight,
|
162
|
-
diffConfig
|
163
|
-
);
|
187
|
+
const totalPixels = imageWidth * imageHeight;
|
164
188
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
}
|
178
|
-
}
|
189
|
+
const {
|
190
|
+
pass,
|
191
|
+
diffSize,
|
192
|
+
diffRatio,
|
193
|
+
} = shouldFail({
|
194
|
+
totalPixels,
|
195
|
+
diffPixelCount,
|
196
|
+
hasSizeMismatch,
|
197
|
+
allowSizeMismatch,
|
198
|
+
failureThresholdType,
|
199
|
+
failureThreshold,
|
200
|
+
});
|
179
201
|
|
180
202
|
if (isFailure({ pass, updateSnapshot })) {
|
181
203
|
mkdirp.sync(diffDir);
|
@@ -213,7 +235,7 @@ function diffImageToSnapshot(options) {
|
|
213
235
|
diffOutputPath,
|
214
236
|
diffRatio,
|
215
237
|
diffPixelCount,
|
216
|
-
imgSrcString: `data:image/png;base64,${pngBuffer}`,
|
238
|
+
imgSrcString: `data:image/png;base64,${pngBuffer.toString('base64')}`,
|
217
239
|
};
|
218
240
|
} else if (shouldUpdate({ pass, updateSnapshot, updatePassedSnapshot })) {
|
219
241
|
mkdirp.sync(snapshotsDir);
|
@@ -222,6 +244,7 @@ function diffImageToSnapshot(options) {
|
|
222
244
|
} else {
|
223
245
|
result = {
|
224
246
|
pass,
|
247
|
+
diffSize,
|
225
248
|
diffRatio,
|
226
249
|
diffPixelCount,
|
227
250
|
diffOutputPath,
|
@@ -240,7 +263,11 @@ function runDiffImageToSnapshot(options) {
|
|
240
263
|
|
241
264
|
const writeDiffProcess = childProcess.spawnSync(
|
242
265
|
process.execPath, [`${__dirname}/diff-process.js`],
|
243
|
-
{
|
266
|
+
{
|
267
|
+
input: Buffer.from(serializedInput),
|
268
|
+
stdio: ['pipe', 'inherit', 'inherit', 'pipe'],
|
269
|
+
maxBuffer: 10 * 1024 * 1024, // 10 MB
|
270
|
+
}
|
244
271
|
);
|
245
272
|
|
246
273
|
if (writeDiffProcess.status === 0) {
|