Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: customize diffOutputPath detail #108

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 7 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Cypress Image Snapshot
# Goalkeeper Image Snapshot

Cypress Image Snapshot binds [jest-image-snapshot](https://github.com/americanexpress/jest-image-snapshot)'s image diffing logic to [Cypress.io](https://cypress.io) commands. **The goal is to catch visual regressions during integration tests.**
Goalkeeper Image Snapshot binds [jest-image-snapshot](https://github.com/americanexpress/jest-image-snapshot)'s image diffing logic to [Cypress.io](https://cypress.io) commands. **The goal is to catch visual regressions during integration tests.**

<details>
<summary>See it in action!</summary>
Expand All @@ -19,40 +19,12 @@ When an image diff fails, a composite image is constructed.

### Test Reporter

When using `cypress run` and `--reporter cypress-image-snapshot/reporter`, diffs are output to your terminal.
When using `cypress run` and `--reporter @kfe/goalkeeper-image-snapshot/reporter`, diffs are output to your terminal.

<img width="500px" src="https://user-images.githubusercontent.com/1153686/48518011-303d4580-e836-11e8-83ed-776acae78f9f.png" alt="Cypress Image Snapshot reporter"/>

</details>

## Installation

Install from npm

```bash
npm install --save-dev cypress-image-snapshot
```

then add the following in your project's `<rootDir>/cypress/plugins/index.js`:

```js
const {
addMatchImageSnapshotPlugin,
} = require('cypress-image-snapshot/plugin');

module.exports = (on, config) => {
addMatchImageSnapshotPlugin(on, config);
};
```

and in `<rootDir>/cypress/support/commands.js` add:

```js
import { addMatchImageSnapshotCommand } from 'cypress-image-snapshot/command';

addMatchImageSnapshotCommand();
```

## Syntax

```js
Expand Down Expand Up @@ -113,7 +85,7 @@ Run Cypress with `--env failOnSnapshotDiff=false` in order to prevent test failu

### Reporter

Run Cypress with `--reporter cypress-image-snapshot/reporter` in order to report snapshot diffs in your test results. This can be helpful to use with `--env failOnSnapshotDiff=false` in order to quickly view all failing snapshots and their diffs.
Run Cypress with `--reporter @kfe/goalkeeper-image-snapshot/reporter` in order to report snapshot diffs in your test results. This can be helpful to use with `--env failOnSnapshotDiff=false` in order to quickly view all failing snapshots and their diffs.

If you using [iTerm2](https://www.iterm2.com/version3.html), the reporter will output any image diffs right in your terminal 😎.

Expand All @@ -131,7 +103,7 @@ You'll then want to set up a `cypress-reporters.json` which may look a little li

```json
{
"reporterEnabled": "spec, mocha-junit-reporter, cypress-image-snapshot/reporter",
"reporterEnabled": "spec, mocha-junit-reporter, @kfe/goalkeeper-image-snapshot/reporter",
"mochaJunitReporterReporterOptions": {
"mochaFile": "cypress/results/results-[hash].xml"
}
Expand Down Expand Up @@ -188,5 +160,5 @@ The workflow of `cy.matchImageSnapshot()` when running Cypress is:

Cypress's screenshot functionality has changed significantly across `3.x.x` versions. In order to avoid buggy behavior, please use the following version ranges:

- `cypress-image-snapshot@>=1.0.0 <2.0.0` for `cypress@>=3.0.0 <3.0.2`
- `cypress-image-snapshot@>2.0.0` for `cypress@>3.0.2`.
- `@kfe/goalkeeper-image-snapshot@>=1.0.0 <2.0.0` for `cypress@>=3.0.0 <3.0.2`
- `@kfe/goalkeeper-image-snapshot@>2.0.0` for `cypress@>3.0.2`.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "cypress-image-snapshot",
"version": "3.1.1",
"description": "Cypress bindings for jest-image-snapshot.",
"repository": "https://github.com/palmerhq/cypress-image-snapshot",
"author": "Jack Cross <[email protected]>",
"name": "@kfe/goalkeeper-image-snapshot",
"version": "0.0.1",
"description": "Goalkeeper bindings for jest-image-snapshot.",
"repository": "https://github.com/HOUCe/goalkeeper-image-snapshot",
"author": "houce",
"license": "MIT",
"files": [
"*.js"
Expand Down
9 changes: 7 additions & 2 deletions src/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const failOnSnapshotDiff =
export function matchImageSnapshotCommand(defaultOptions) {
return function matchImageSnapshot(subject, maybeName, commandOptions) {
const options = {
resolveDiffOutputPath: diffOutputPath => diffOutputPath,
...defaultOptions,
...((typeof maybeName === 'string' ? commandOptions : maybeName) || {}),
};
Expand Down Expand Up @@ -50,9 +51,13 @@ export function matchImageSnapshotCommand(defaultOptions) {
imageDimensions.receivedWidth
}x${
imageDimensions.receivedHeight
}).\nSee diff for details: ${diffOutputPath}`
}).\nSee diff for details: ${options.resolveDiffOutputPath(
diffOutputPath
)}`
: `Image was ${diffRatio *
100}% different from saved snapshot with ${diffPixelCount} different pixels.\nSee diff for details: ${diffOutputPath}`;
100}% different from saved snapshot with ${diffPixelCount} different pixels.\nSee diff for details: ${options.resolveDiffOutputPath(
diffOutputPath
)}`;

if (failOnSnapshotDiff) {
throw new Error(message);
Expand Down