Skip to content

Conversation

@mosofsky
Copy link

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):

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 cared 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         |

michaelosofsky added 10 commits December 12, 2022 19:18
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant