question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Snapshot comparison failing but results look identical

See original GitHub issue

🐛 Bug Report

A unit test is failing in one environment but not others. The output is very unhelpful because the serialized results look identical.

To Reproduce

Created a unit tests against captured console output using toMatchSnapshot().

    expect(getLog().log).toMatchSnapshot()

The results of running this test look like this:

[2020-04-22T17:27:08.927Z] FAIL src/__tests__/logger.test.js
[2020-04-22T17:27:08.927Z]   ● Console logging › Logs error level and above.
[2020-04-22T17:27:08.927Z]
[2020-04-22T17:27:08.927Z]     expect(received).toMatchSnapshot()
[2020-04-22T17:27:08.927Z]
[2020-04-22T17:27:08.927Z]     Snapshot name: `Console logging Logs error level and above. 1`
[2020-04-22T17:27:08.927Z]
[2020-04-22T17:27:08.927Z]     Snapshot: "[error]: Testing simple message at error level... "
[2020-04-22T17:27:08.927Z]     Received: "[error]: Testing simple message at error level... "

From this result I cannot fathom what is wrong with the matcher. As far as I know, this is not a custom matcher. .log is declared as a TS string type.

As of right now I have no idea how to reproduce since the error has given me no indication of what is not matching.

Expected behavior

Output either matches and succeeds or provides a clear indication of how the matcher failed.

Link to repl or repo (highly encouraged)

No way to reproduce outside environment at the moment. No idea what is wrong because the error message is completely opaque.

envinfo

[2020-04-22T18:10:43.171Z] + npx envinfo --preset jest
[2020-04-22T18:10:44.515Z] npx: installed 1 in 1.119s
[2020-04-22T18:10:44.765Z] 
[2020-04-22T18:10:44.765Z]   System:
[2020-04-22T18:10:44.765Z]     OS: Linux 4.14 Alpine Linux
[2020-04-22T18:10:44.765Z]     CPU: (2) x64 Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40GHz
[2020-04-22T18:10:44.765Z]   Binaries:
[2020-04-22T18:10:44.765Z]     Node: 12.16.2 - /usr/local/bin/node
[2020-04-22T18:10:44.765Z]     Yarn: 1.22.4 - /usr/local/bin/yarn
[2020-04-22T18:10:44.765Z]     npm: 6.14.4 - /usr/local/bin/npm
[2020-04-22T18:10:44.765Z]   npmPackages:
[2020-04-22T18:10:44.765Z]     jest: ^25.4.0 => 25.4.0 
[2020-04-22T18:10:44.765Z]

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:11

github_iconTop GitHub Comments

3reactions
robross0606commented, Apr 24, 2020

This turned out to be caused by Winston logger using os.EOL as the default for newlines. In this case, capturing and comparing snapshots on console output was failing due to an extra \r in the output that doesn’t show up on the error diff coming from Jest. Recommend an option to allow those diff messages to show escape codes. This was VERY hard to track down due to Jest output hiding control characters.

0reactions
SimenBcommented, Apr 24, 2020

Yeah exactly, that’s what concordance does

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest snapshot tests failing with same output because of ANSI
The output for the failing tests was identical. I tried to recreate the problem so I ran the test in my WSL and...
Read more >
Snapshot Testing - Jest
The test will fail if the two snapshots do not match: either the change is unexpected, or the reference snapshot needs to be...
Read more >
Snapshot Testing - Jest - w3resource
The test fails if the two snapshots do not match: either when the change is unexpected, or when the reference snapshot needs to...
Read more >
Why Screenshot Image Comparison Tools Fail With Dynamic ...
But that's not enough. There are many ways in which images might seem to be identical but the pixels don't match. Why does...
Read more >
Compare-Object gives false differences - powershell
Actually, both snapshot are from Import-Clixml, sorry for misleading. I've corrected the question. But it has no effect, actually -- result is the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found