Closed bcheidemann closed 3 months ago
I have the same problem. I was expecting multiline strings were stored with template literals (like Jest), so it's more easy to detect changes and see git diff.
I've also detected differences between Windows and Unix/Macos due endline (\n
vs \r\n
) but not sure if this is a bug or is the desired behavior.
I have the same problem. I was expecting multiline strings were stored with template literals (like Jest), so it's more easy to detect changes and see git diff.
I've also detected differences between Windows and Unix/Macos due endline (
\n
vs\r\n
) but not sure if this is a bug or is the desired behavior.
I would expect that (within reason) if you run the same code, it should produce the same output on all platforms.
Are you able to produce different snapshot output with the same code on MacOS and Windows? If so, could you share the code and the output it produces for each platform?
I saw this problem when I was porting the tests of Lume (a SSG) to snapshots. You can see here the github action with the error: https://github.com/lumeland/lume/runs/6140674360?check_suite_focus=true
And was able to fix it with a replaceAll
function: https://github.com/lumeland/lume/commit/f3f29787ba8e6c739f2443a8e116df6b67734316
But I'm not sure if the problem is the snapshot. Lume reads the file content of the source files with Deno.readTextFile()
so maybe the problem is that this function behaves differently in Windows and MacOS/Linux?
I saw this problem when I was porting the tests of Lume (a SSG) to snapshots. You can see here the github action with the error: https://github.com/lumeland/lume/runs/6140674360?check_suite_focus=true
And was able to fix it with a
replaceAll
function: https://github.com/lumeland/lume/commit/f3f29787ba8e6c739f2443a8e116df6b67734316But I'm not sure if the problem is the snapshot. Lume reads the file content of the source files with
Deno.readTextFile()
so maybe the problem is that this function behaves differently in Windows and MacOS/Linux?
Thanks for the explanation @oscarotero
I can't see the GH actions output you sent for some reason 🤔
Anyway, I'll put up a fix for this - most likely this evening but definitely this week. 👍
I send you a screenshot with a piece of the output:
Fixed in #2166
Describe the bug
When
assertSnapshot
is called with a multiline string, the newlines are replaced with the characters\\n
making it hard to read multiline snapshots.Steps to Reproduce
deno test test.ts -- -u
Expected behavior
The snapshot file should be formatted as follows:
Environment
Workaround
The current workaround is to write your test file like this:
Which will result in more readable output: