jest icon indicating copy to clipboard operation
jest copied to clipboard

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

Open Andarist opened this issue 5 years ago β€’ 15 comments

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: https://github.com/emotion-js/emotion/issues/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.

Andarist avatar Apr 22 '20 15:04 Andarist

Thanks @Andarist, failing tests are the best bug reports ever! πŸ˜€

@pedrottimark @jeysal any ideas here?

SimenB avatar Apr 23 '20 09:04 SimenB

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.

Andarist avatar Apr 23 '20 09:04 Andarist

Either I messed up the merge or this is fixed. @Andarist any idea? πŸ˜€

SimenB avatar Feb 11 '22 07:02 SimenB

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

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.

codecov-commenter avatar Feb 11 '22 08:02 codecov-commenter

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

Andarist avatar Feb 11 '22 12:02 Andarist

I'm happy to land this as a regression test πŸ™‚

SimenB avatar Feb 11 '22 13:02 SimenB

Ah wait no, the test demonstrates the error, it wasn't a failing test. Makes sense! Ref https://github.com/facebook/jest/pull/9863#discussion_r413071029

SimenB avatar Feb 11 '22 13:02 SimenB

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

Andarist avatar Feb 11 '22 13:02 Andarist

yeah, seems like it to me πŸ™‚

SimenB avatar Feb 11 '22 13:02 SimenB

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[bot] avatar Feb 11 '23 14:02 github-actions[bot]

bump for stale bot

Andarist avatar Feb 12 '23 10:02 Andarist

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[bot] avatar Feb 12 '24 11:02 github-actions[bot]

bump for stale bot

Andarist avatar Feb 12 '24 11:02 Andarist