-
Notifications
You must be signed in to change notification settings - Fork 119
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
Added autofailNewSnapshots to force Cypress to fail if no snapshot is found #228
Open
mosofsky
wants to merge
10
commits into
meinaart:master
Choose a base branch
from
mosofsky:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Then I published to npm: 1. npm login 2. npm publish --access=public
This is a proof of concept to test out going through the full development and release process on this fork of https://github.com/meinaart/cypress-plugin-snapshots Also added .idea to .gitignore
I ran `yarn import` based on reference 1. References: 1. https://classic.yarnpkg.com/lang/en/docs/migrating-from-npm/
This is a proof of concept to test out `yarn link` (reference 1) References: 1. https://classic.yarnpkg.com/lang/en/docs/cli/link/
New parameter "autofailNewSnapshots" default to false. If true, automatically fail if no existing snapshot found. This is useful for production builds to prevent tests of passing just because they're missing snapshots. In order to cause a failure when no snapshot is found, both matchImageSnapshot.js and matchTextSnapshot.js need to return a result object that has result.passed=false and result.updated=false. That way logMessage.js throws the Error to make Cypress report the test as a failure. In order to cause result.passed=false and result.updated=false, we have introduced the new autofailNewSnapshots configuration parameter that does what we want, namely: ``` Given autofailNewSnapshots is true When no <snapshot_type> snapshot is found Then the test should fail Examples: | snapshot_type | | text | | image | ``` Also, deleted package-lock.json since we now use yarn. Testing: The following scenarios test the new functionality pretty well. I tested a few key ones that I most about and recorded "// PASS" to indicate that they worked. ``` Given autofailNewSnapshots is false When no <snapshot_type> snapshot is found And it actual matches the snapshot Then the test should pass Examples: | snapshot_type | | text | // PASS | image | ``` ``` Given autofailNewSnapshots is false When <snapshot_type> snapshot is found And it actual matches the snapshot Then the test should pass Examples: | snapshot_type | | text | | image | ``` ``` Given autofailNewSnapshots is false When no <snapshot_type> snapshot is found And actual does not match the snapshot Then the test should fail Examples: | snapshot_type | | text | // PASS | image | ``` ``` Given autofailNewSnapshots is false When <snapshot_type> snapshot is found And actual does not match the snapshot Then the test should fail Examples: | snapshot_type | | text | | image | ``` ``` Given autofailNewSnapshots is true When no <snapshot_type> snapshot is found Then the test should fail Examples: | snapshot_type | | text | // PASS | image | ``` ``` Given autofailNewSnapshots is true When a <snapshot_type> snapshot is found And actual match the snapshot Then the test should pass Examples: | snapshot_type | | text | // PASS | image | ``` ``` Given autofailNewSnapshots is true When a <snapshot_type> snapshot is found And actual does not match the snapshot Then the test should fail Examples: | snapshot_type | | text | // PASS | image | ```
# Conflicts: # package-lock.json
# Conflicts: # package.json
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Added autofailNewSnapshots
New parameter "autofailNewSnapshots" default to false.
If true, automatically fail if no existing snapshot found. This is useful for production builds to prevent tests from passing just because they're missing snapshots.
In order to cause a failure when no snapshot is found, both matchImageSnapshot and matchTextSnapshot need to return a result object that has result.passed=false and result.updated=false. That way logMessage throws the Error to make Cypress report the test as a failure.
In order to cause result.passed=false and result.updated=false, we have introduced the new autofailNewSnapshots configuration parameter that does what we want, namely (note the syntax for expressing tests below is Gherkin):
Also, deleted package-lock.json since we now use yarn.
Testing:
The following scenarios test the new functionality pretty well. I tested a few key ones that I cared most about and recorded "// PASS" to indicate that they worked.