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

Add a failing test for printSnapshotAndReceived incorrectly recognizing sometimes indented lines as changed #9863

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Andarist
Copy link
Contributor

Summary

It has been reported to Emotion that each printed style property is being shown as changed in Jest 25 when anything changes between snapshots & received: emotion-js/emotion#1847

It turned out that we currently ignore indentation because we use OldPlugin interface and we just print retrieved styles with always indented. We plan to fix this soon, but I believe the issue is still worth fixing in Jest itself - especially that the comment here:
https://github.com/facebook/jest/blob/32aaff83f02c347ccd591727544002490fb4ee9a/packages/jest-snapshot/src/printSnapshot.ts#L316-L317
suggests that this was supposed to be handled.

So far I've just added a failing test and would like to first check-in if there is an interest in fixing this before I dive into this further. I've also actually tried to fix this quickly by calling dedentLines on this:
https://github.com/facebook/jest/blob/32aaff83f02c347ccd591727544002490fb4ee9a/packages/jest-snapshot/src/printSnapshot.ts#L324
but while it has fixed my issue it has changed 2 other tests and it would require further investigation why this is happening and how the fix could be improved.

<t>+ Received + 2</>

<m>- **some plugin-generated string with custom leading whitespace**</>
<t>+ **some plugin-generated string with custom leading whitespace**</>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this should not be detected as changed because it's exactly the same line in both snapshot and received values

@SimenB
Copy link
Member

SimenB commented Apr 23, 2020

Thanks @Andarist, failing tests are the best bug reports ever! 😀

@pedrottimark @jeysal any ideas here?

@Andarist
Copy link
Contributor Author

Just an additional note because it might not be super clear while skimming through my original post - this has changed between Jest 24 and Jest 25. Jest 24 did not report those false positives.

@SimenB
Copy link
Member

SimenB commented Feb 11, 2022

Either I messed up the merge or this is fixed. @Andarist any idea? 😀

@codecov-commenter
Copy link

Codecov Report

Merging #9863 (1e57d0e) into main (e3c84b5) will increase coverage by 0.00%.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #9863   +/-   ##
=======================================
  Coverage   68.47%   68.48%           
=======================================
  Files         324      324           
  Lines       16968    16968           
  Branches     5060     5060           
=======================================
+ Hits        11619    11620    +1     
+ Misses       5317     5316    -1     
  Partials       32       32           
Impacted Files Coverage Δ
packages/jest-snapshot/src/plugins.ts 100.00% <0.00%> (+20.00%) ⬆️

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 e3c84b5...1e57d0e. Read the comment docs.

@Andarist
Copy link
Contributor Author

Andarist commented Feb 11, 2022

@SimenB This PR was sent quite some time ago - there is a high chance of this being fixed now so perhaps this can be closed. I would probably recommend trying to check if there is already a test for this because if there is not then maybe it's still worth landing this PR so this test could act as a regression test for the future.

I'm afraid that I won't have enough time to look into this myself though.

@SimenB
Copy link
Member

SimenB commented Feb 11, 2022

I'm happy to land this as a regression test 🙂

@SimenB
Copy link
Member

SimenB commented Feb 11, 2022

Ah wait no, the test demonstrates the error, it wasn't a failing test. Makes sense! Ref #9863 (comment)

@Andarist
Copy link
Contributor Author

Ah, so the problem is still here - I just didn't make it a failing test case back then but rather a test showcasing an invalid behavior, did I get this right (I'm refreshing my own memory about this issue)?

@SimenB
Copy link
Member

SimenB commented Feb 11, 2022

yeah, seems like it to me 🙂

@github-actions
Copy link

This PR is stale because it has been open 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Feb 11, 2023
@Andarist
Copy link
Contributor Author

bump for stale bot

@github-actions github-actions bot removed the Stale label Feb 12, 2023
Copy link

This PR is stale because it has been open 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Feb 12, 2024
@Andarist
Copy link
Contributor Author

bump for stale bot

@github-actions github-actions bot removed the Stale label Feb 12, 2024
Copy link

This PR is stale because it has been open 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants