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

jest-snapshot: Distinguish empty string from internal snapshot not written #8898

Merged
merged 2 commits into from
Sep 1, 2019

Conversation

pedrottimark
Copy link
Contributor

@pedrottimark pedrottimark commented Sep 1, 2019

Summary

Breaking change: Add boolean isInline property to SnapshotMatchOptions so

  • inlineSnapshot: undefined means internal snapshot not written instead of external snapshot
  • inlineSnapshot: '' means empty string instead of internal snapshot not written

While trouble-shooting #8880 empty string in external snapshot, I found that internal snapshots had similar problem with different effect:

  1. '--ci=false' when inline snapshot is empty string and received value is non-empty string, then instead of ordinary failure, test passes and replaces expected with received
  2. '--ci=true' when inline snapshot was not written, test has ordinary failure with empty string as expected value

Edge case 1 requires custom serializer which writes empty string not enclosed in quote marks

Effect of change on dependent packages without TypeScript that do not upgrade a match call:

  • external snapshot: no change, because absence of isInline means not inline
  • internal snapshot: ignore inline snapshot, instead read and write as external snapshot

For what it’s worth, while reviewing GitHub repos for a subset of dependents on jest-snapshot I did found few calls to match method of SnapshotState and no calls to match inline snapshot

Test plan

Added 2 new e2e tests

Especially because of prettier update to inline snapshot tests, I changed the enclosing punctuation for literal strings from double quote to single quote

@codecov-io
Copy link

codecov-io commented Sep 1, 2019

Codecov Report

Merging #8898 into master will increase coverage by 0.01%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8898      +/-   ##
==========================================
+ Coverage   64.23%   64.24%   +0.01%     
==========================================
  Files         275      275              
  Lines       11658    11656       -2     
  Branches     2845     2844       -1     
==========================================
  Hits         7488     7488              
+ Misses       3546     3544       -2     
  Partials      624      624
Impacted Files Coverage Δ
packages/jest-snapshot/src/State.ts 0% <0%> (ø) ⬆️
packages/jest-snapshot/src/index.ts 28.85% <0%> (+0.19%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4482e71...051c6cf. Read the comment docs.

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it 🙂

@pedrottimark pedrottimark merged commit 5545730 into jestjs:master Sep 1, 2019
@pedrottimark pedrottimark deleted the empty-snapshot-2 branch September 1, 2019 20:57
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants