Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vitest always writes snapshot files on Windows 10 with Node 18.17.1 #4653

Closed
6 tasks done
christoph-schlumpf opened this issue Dec 4, 2023 · 2 comments · Fixed by #5449
Closed
6 tasks done

Vitest always writes snapshot files on Windows 10 with Node 18.17.1 #4653

christoph-schlumpf opened this issue Dec 4, 2023 · 2 comments · Fixed by #5449
Labels
p2-nice-to-have Not breaking anything but nice to have (priority)

Comments

@christoph-schlumpf
Copy link

christoph-schlumpf commented Dec 4, 2023

Describe the bug

On Windows 10 with Node 18.17.1, vitest always writes the snapshot files when running the tests, even if there are no changes in the snapshot. This leads to unnecessary writes and changed files in the repo.

Reason for this issue is this code:

async readSnapshotFile(filepath: string): Promise<string | null> {

readSnapshotFile always reads an empty string ("") on Windows. Additionally, many repos on windows have git config autocrlf enabled.

I fixed it with the following patch:

const readSnapshotFile = async (filepath) => {
    if (!existsSync(filepath)) {
        return null;
    }
    return promises
        .readFile(filepath, { encoding: "utf-8" })
        .then((content) => (process.platform === "win32" ? content.replace(/\r\n|\r/g, "\n") : content));
}; 

Reproduction

Can be reproced on any Windows machine with Node 18.17.1 and vitest with snapshots.

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz
    Memory: 25.88 GB / 47.71 GB
  Binaries:
    Node: 18.17.1 - C:\eplatform\mytools\node\node.EXE
    npm: 9.6.7 - C:\eplatform\mytools\node\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.3636.0), Chromium (119.0.2151.58)
    Internet Explorer: 11.0.19041.3636
  npmPackages:
    @vitejs/plugin-react: ~4.0.0 => 4.0.4
    @vitest/coverage-istanbul: ^0.34.6 => 0.34.6
    @vitest/ui: ~0.32.0 => 0.32.4
    vite: ~4.3.9 => 4.3.9
    vitest: 0.34.6 => 0.34.6

Used Package Manager

npm

Validations

@sheremet-va
Copy link
Member

We don't think this should be built-in, but we can expose an option to override the default behaviour: #5449

@sheremet-va sheremet-va added p2-nice-to-have Not breaking anything but nice to have (priority) and removed p2-to-be-discussed Enhancement under consideration (priority) labels Apr 25, 2024
@christoph-schlumpf
Copy link
Author

Hi @sheremet-va Thank you for the information. we will try out the override solution.

@github-actions github-actions bot locked and limited conversation to collaborators May 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p2-nice-to-have Not breaking anything but nice to have (priority)
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants