vitest-dev / vitest-dev/vitest

Snapshots incorrectly treat CR as LF

Open
#7,305 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

p3-minor-bug
Dominant language
TypeScript
Stars
17.1k
Forks
2k
Avg merge
1d 22h
Merged PRs (30d)
94

Description

Describe the bug

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.

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/17612890884

System Info
System:
    OS: Windows 11 10.0.26100
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
    Memory: 770.81 MB / 7.84 GB
  Binaries:
    Node: 23.6.0 - C:\nvm4w\nodejs\node.EXE
    Yarn: 4.6.0 - C:\nvm4w\nodejs\yarn.CMD
    npm: 10.9.2 - C:\nvm4w\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (124.0.2478.105)
  npmPackages:
    vitest: ^3.0.2 => 3.0.2
Used Package Manager

yarn

Validations

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the linked minimal reproduction with Vitest on Windows and Ubuntu, then compare the generated and second-run snapshot behavior described in the issue. Done means CRLF and LF remain distinct in snapshots and the reproduction passes consistently across both environments.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.