jest-image-snapshot 2.11.1 → 2.12.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/README.md CHANGED
@@ -1,13 +1,9 @@
1
- <h1>
2
- <center>
3
- <br />
4
- <img src="./jest-image-snapshot.png" alt="Jest Image Snapshot - One Amex" width="50%" />
5
- <br /><br />
6
- </center>
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%'/>
7
3
  </h1>
8
4
 
9
- [![npm version](https://badge.fury.io/js/jest-image-snapshot.svg)](https://badge.fury.io/js/jest-image-snapshot)
10
- [![Build Status](https://travis-ci.org/americanexpress/jest-image-snapshot.svg?branch=master)](https://travis-ci.org/americanexpress/jest-image-snapshot)
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)
11
7
  [![Mentioned in Awesome Jest](https://awesome.re/mentioned-badge.svg)](https://github.com/jest-community/awesome-jest)
12
8
 
13
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.
@@ -19,11 +15,11 @@ Want to get paid for your contributions to `jest-image-snapshot`?
19
15
 
20
16
  ## 📖 Table of Contents
21
17
 
22
- * [Features](#Features)
23
- * [Usage](#Usage)
24
- * [API](#API)
25
- * [Available Scripts](#Available%20Scripts)
26
- * [Contributing](#Contributing)
18
+ * [Features](#-features)
19
+ * [Usage](#-usage)
20
+ * [API](#-api)
21
+ * [Available Scripts](#-available-scripts)
22
+ * [Contributing](#-contributing)
27
23
 
28
24
  ## ✨ Features
29
25
 
@@ -118,6 +114,7 @@ See [the examples](./examples/README.md) for more detailed usage or read about a
118
114
  * `updatePassedSnapshot`: (default `false`) Updates a snapshot even if it passed the threshold against the existing one.
119
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 it's value to 1-2 should be enough to solve that problem.
120
116
  * `runInProcess`: (default `false`) Runs the diff in process without spawning a child process.
117
+ * `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.
121
118
 
122
119
  ```javascript
123
120
  it('should demonstrate this matcher`s usage with a custom pixelmatch config', () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jest-image-snapshot",
3
- "version": "2.11.1",
3
+ "version": "2.12.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": {
@@ -213,6 +213,7 @@ function diffImageToSnapshot(options) {
213
213
  diffOutputPath,
214
214
  diffRatio,
215
215
  diffPixelCount,
216
+ imgSrcString: `data:image/png;base64,${pngBuffer}`,
216
217
  };
217
218
  } else if (shouldUpdate({ pass, updateSnapshot, updatePassedSnapshot })) {
218
219
  mkdirp.sync(snapshotsDir);
package/src/index.js CHANGED
@@ -36,6 +36,7 @@ function checkResult({
36
36
  retryTimes,
37
37
  snapshotIdentifier,
38
38
  chalk,
39
+ dumpDiffToConsole,
39
40
  }) {
40
41
  let pass = true;
41
42
  /*
@@ -65,11 +66,15 @@ function checkResult({
65
66
  message = () => {
66
67
  let failure;
67
68
  if (result.diffSize) {
68
- failure = `Expected image to be the same size as the snapshot (${result.imageDimensions.baselineWidth}x${result.imageDimensions.baselineHeight}), but was different (${result.imageDimensions.receivedWidth}x${result.imageDimensions.receivedHeight}).\n`
69
- + `${chalk.bold.red('See diff for details:')} ${chalk.red(result.diffOutputPath)}`;
69
+ failure = `Expected image to be the same size as the snapshot (${result.imageDimensions.baselineWidth}x${result.imageDimensions.baselineHeight}), but was different (${result.imageDimensions.receivedWidth}x${result.imageDimensions.receivedHeight}).\n`;
70
70
  } else {
71
- failure = `Expected image to match or be a close match to snapshot but was ${differencePercentage}% different from snapshot (${result.diffPixelCount} differing pixels).\n`
72
- + `${chalk.bold.red('See diff for details:')} ${chalk.red(result.diffOutputPath)}`;
71
+ failure = `Expected image to match or be a close match to snapshot but was ${differencePercentage}% different from snapshot (${result.diffPixelCount} differing pixels).\n`;
72
+ }
73
+
74
+ failure += `${chalk.bold.red('See diff for details:')} ${chalk.red(result.diffOutputPath)}`;
75
+
76
+ if (dumpDiffToConsole) {
77
+ failure += `\n${chalk.bold.red('Or paste below image diff string to your browser`s URL bar.')}\n ${result.imgSrcString}`;
73
78
  }
74
79
 
75
80
  return failure;
@@ -128,6 +133,7 @@ function configureToMatchImageSnapshot({
128
133
  updatePassedSnapshot: commonUpdatePassedSnapshot = false,
129
134
  blur: commonBlur = 0,
130
135
  runInProcess: commonRunInProcess = false,
136
+ dumpDiffToConsole: commonDumpDiffToConsole = false,
131
137
  } = {}) {
132
138
  return function toMatchImageSnapshot(received, {
133
139
  customSnapshotIdentifier = commonCustomSnapshotIdentifier,
@@ -141,6 +147,7 @@ function configureToMatchImageSnapshot({
141
147
  updatePassedSnapshot = commonUpdatePassedSnapshot,
142
148
  blur = commonBlur,
143
149
  runInProcess = commonRunInProcess,
150
+ dumpDiffToConsole = commonDumpDiffToConsole,
144
151
  } = {}) {
145
152
  const {
146
153
  testPath, currentTestName, isNot, snapshotState,
@@ -197,6 +204,7 @@ function configureToMatchImageSnapshot({
197
204
  retryTimes,
198
205
  snapshotIdentifier,
199
206
  chalk,
207
+ dumpDiffToConsole,
200
208
  });
201
209
  };
202
210
  }