jest icon indicating copy to clipboard operation
jest copied to clipboard

[Bug]: Snapshots not saved on path that snapshotResolver returns

Open ChocolateLoverRaj opened this issue 3 years ago • 0 comments

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

ChocolateLoverRaj avatar Jul 25 '22 18:07 ChocolateLoverRaj

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.

github-actions[bot] avatar Aug 24 '22 18:08 github-actions[bot]

@ChocolateLoverRaj I cannot reproduce - the snapshot is written to lib/.

SimenB avatar Aug 25 '22 13:08 SimenB

@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.

ChocolateLoverRaj avatar Aug 25 '22 15:08 ChocolateLoverRaj

Might be. I'm on mac - might be your logic doesn't work on windows?

SimenB avatar Aug 25 '22 15:08 SimenB

@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

ChocolateLoverRaj avatar Aug 25 '22 16:08 ChocolateLoverRaj

It's in lib/__tests__/__snapshots__/

SimenB avatar Aug 25 '22 17:08 SimenB

Note that you ignore the snapshot folder: https://github.com/ChocolateLoverRaj/jest-bug-3/blob/077af67b259dd784e7334c5fc93dea105a84feb6/.gitignore#L2

SimenB avatar Aug 25 '22 17:08 SimenB

https://github.com/ChocolateLoverRaj/jest-bug-3/pull/1/files#r955804620

SimenB avatar Aug 26 '22 08:08 SimenB

@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

ChocolateLoverRaj avatar Aug 26 '22 17:08 ChocolateLoverRaj

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

SimenB avatar Aug 26 '22 17:08 SimenB