[Bug]: Snapshots not saved on path that snapshotResolver returns
Version
28.1.3
Steps to reproduce
Clone https://github.com/ChocolateLoverRaj/jest-bug-3
Run
npm test
Expected behavior
Snapshot written to lib/__snapshots__/file.js.snap
Actual behavior
Snapshot written to dist/__snapshots__/file.js.snap
Additional context
I am using webpack to transform files from lib dir to dist dir. I want the snapshots to stay with lib dir, so that it can be included in git.
Environment
System:
OS: Windows 10 10.0.19044
CPU: (8) x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
Binaries:
Node: 16.15.1 - C:\Program Files\nodejs\node.EXE
npm: 8.12.1 - C:\Program Files (x86)\Nodist\bin\npm.CMD
npmPackages:
jest: ^28.1.3 => 28.1.3
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.
@ChocolateLoverRaj I cannot reproduce - the snapshot is written to lib/.
@SimenB that is wierd that it works for you. I was using pnpm before, so I tried removing node_modules and installing with npm i. It's still saving snapshots to dist for me. Maybe I could create a GitHub Actions to see if it works on specific OS or Node.js versions.
Might be. I'm on mac - might be your logic doesn't work on windows?
@SimenB I ran CI on Windows, Mac, and Linux with multiple Node.js versions and everything fails - https://github.com/ChocolateLoverRaj/jest-bug-3/actions/runs/2928301547
It's in lib/__tests__/__snapshots__/
Note that you ignore the snapshot folder: https://github.com/ChocolateLoverRaj/jest-bug-3/blob/077af67b259dd784e7334c5fc93dea105a84feb6/.gitignore#L2
https://github.com/ChocolateLoverRaj/jest-bug-3/pull/1/files#r955804620
@SimenB after fixing the GitHub Actions test I found out that it only doesn't work on Windows. You were right. https://github.com/ChocolateLoverRaj/jest-bug-3/actions/runs/2935434359
Yeah, path replacement with forward slashes probably doesn't work. Too bad the check we have doesn't pick it up, but all it does is verify it works the same both ways. So if the replacement "fails" both ways, we don't detect it