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: Fix regression in diff for jest-snapshot-serializer-raw #9419

Merged
merged 3 commits into from
Jan 16, 2020

Conversation

pedrottimark
Copy link
Contributor

Summary

Found by @SimenB in a diff for e2e/__tests__/__snapshots__/showConfig.test.ts.snap

Ouch, I assumed that all snapshot serializers support the indent option.

But jest-snapshot-serializer-raw does not, because it deals with strings.

Because the snapshot is JSON serialization of an object, it can be dedented.

Therefore, the expected value has no indentation and the received value has default indentation. Only the opening and closing braces are in common.

As a future chore, add a minimal serializer to test-utils which does not use the object-with-symbol-key-idiom, for tests that do not need to distinguish top-level strings from lower-level strings (for example, array items, object keys or values). That will support substring diffs for Jest test files that serialize only strings (like the example e2e test of CLI output).

Test plan

Verified locally for the example of adding "moduleWrapper": true, property:

  1. Jest 24.9.0 reports + Received + 1
  2. Without fix, Jest master reports - Snapshot - 122 + Received + 123
  3. With fix, Jest master reports + Received + 1

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.

Wonderful, thanks!

@SimenB
Copy link
Member

SimenB commented Jan 16, 2020

Is it possible to add a test as well? No blocker of course 🙂

@pedrottimark
Copy link
Contributor Author

Yeah, what do you think if I add an e2e test as a follow-up chore?

@SimenB
Copy link
Member

SimenB commented Jan 16, 2020

perfect 👍

@codecov-io
Copy link

codecov-io commented Jan 16, 2020

Codecov Report

Merging #9419 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #9419      +/-   ##
=========================================
+ Coverage    64.8%   64.8%   +<.01%     
=========================================
  Files         281     281              
  Lines       11998   12000       +2     
  Branches     2959    2960       +1     
=========================================
+ Hits         7775    7777       +2     
  Misses       3591    3591              
  Partials      632     632
Impacted Files Coverage Δ
packages/jest-snapshot/src/printSnapshot.ts 100% <100%> (ø) ⬆️

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 17f6c83...529db52. Read the comment docs.

CHANGELOG.md Outdated Show resolved Hide resolved
@SimenB SimenB merged commit c8c4c4e into jestjs:master Jan 16, 2020
@pedrottimark pedrottimark deleted the raw-diff-without-dedent branch January 16, 2020 16:26
@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