You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Vitest treats CRLF and LF as the same in snapshots which leads to the wrong snapshot being used. E.g. if a string has CRLF it'll incorrectly be normalised to LF.
import{test,expect}from'vitest';test.for(['a\nb',// ["a", "\n", "b"], snapshot will have ["a", "\n", "b"]'a\r\nb',// ["a", "\r", "\n", "b"], snapshot will have ["a", "\n", "\n", "b"]])('"%s".split("")',(input)=>{expect(input.split("")).toMatchSnapshot();})
On Windows it correctly generates two snapshots for both. But then when it compares the snapshot on a second run this test will fail because the line endings aren't right.
On Ubuntu it writes the first snapshot to the file. Then it incorrectly uses the first snapshot for the second test and fails.
I think an actual solution would be in this direction. Instead of writing actual CRs and LFs in the title and snapshot, write \r and \n so that CRLF cannot be normalised to LF.
Describe the bug
Vitest treats
CRLF
andLF
as the same in snapshots which leads to the wrong snapshot being used. E.g. if a string hasCRLF
it'll incorrectly be normalised toLF
.On Windows it correctly generates two snapshots for both. But then when it compares the snapshot on a second run this test will fail because the line endings aren't right.
On Ubuntu it writes the first snapshot to the file. Then it incorrectly uses the first snapshot for the second test and fails.
Reproduction
https://github.com/melusc/vitest-snapshot-crlf
You can see how it behaves on Windows or Ubuntu in the Github Actions logs: https://github.com/melusc/vitest-snapshot-crlf/actions/runs/12869505983
System Info
Used Package Manager
yarn
Validations
The text was updated successfully, but these errors were encountered: