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

Indented inline snapshots. #8198

Merged
merged 9 commits into from
Mar 24, 2019

Conversation

scotthovestadt
Copy link
Contributor

Summary

Inline snapshots are currently ugly. Not only are they not indented by default, but the matcher will fail if you indent them manually. This PR adds support for indented inline snapshots.

A few things to note:

  • Non-indented snapshots will continue to pass and will not be updated automatically unless a snapshot in the file is updated.
  • The extra indentation is not reflected in the reporter.

When/if this PR is accepted, I'll be trying to make a PR into Prettier for better UX, since Prettier won't currently update your inline snapshots formatting automatically.

Test plan

  • All existing tests pass, including e2e snapshot tests for inline tests.
  • Added a few more test cases specifically for this feature.
  • Tested manually against real tests.

@codecov-io
Copy link

codecov-io commented Mar 23, 2019

Codecov Report

Merging #8198 into master will increase coverage by 0.01%.
The diff coverage is 61.01%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8198      +/-   ##
==========================================
+ Coverage    62.3%   62.31%   +0.01%     
==========================================
  Files         265      265              
  Lines       10473    10524      +51     
  Branches     2542     2554      +12     
==========================================
+ Hits         6525     6558      +33     
- Misses       3366     3383      +17     
- Partials      582      583       +1
Impacted Files Coverage Δ
packages/jest-snapshot/src/index.ts 28.57% <5.55%> (-3.14%) ⬇️
packages/jest-snapshot/src/inline_snapshots.ts 80.85% <85.36%> (+7.51%) ⬆️

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 7e4e170...855af3a. 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.

This is great! It'll look way better indented. Just left a single inline comment.

Could you add a changelog entry?

packages/jest-snapshot/src/index.ts Outdated Show resolved Hide resolved
packages/jest-snapshot/src/inline_snapshots.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@jeysal jeysal left a comment

Choose a reason for hiding this comment

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

This looks really cool and like a very solid impl, thanks @scotthovestadt! Left a few comments inline

packages/jest-snapshot/src/inline_snapshots.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@jeysal jeysal left a comment

Choose a reason for hiding this comment

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

NICE 😎

@scotthovestadt scotthovestadt merged commit 5cde98e into jestjs:master Mar 24, 2019
@cpojer
Copy link
Member

cpojer commented Mar 25, 2019

Nice! I've always wanted this to be what inline snapshots look like, and you have made this a ton easier.

The next step for inline snapshots is to drop pretty-format and just put the concrete value into the right hand side, like expect(object).toMatch<matcherName>({apple: 'banana'}).

@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.

6 participants