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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jest chokes on unexpected snapshot file when --no-cache and --watch are used together #7636

Closed
aleclarson opened this issue Jan 15, 2019 · 7 comments

Comments

@aleclarson
Copy link
Contributor

馃悰 Bug Report

Error: ENOENT: no such file or directory, stat '[redacted]/spec/promise.spec.ts'

Jest is trying to "stat" a test file that does not exist, and it doesn't try to catch in case of failure. For example, let's say you have a test file containing tests that take snapshots. If you rename the test file (but not its snapshot file), Jest later assumes that the snapshot file is legitimate and resolves the associated test file based off the snapshot file path, but only if --no-cache and --watch are used together (which is common when debugging tests).

Also, I cannot get stack traces to show (for uncaught Jest errors). Is there a CLI flag for that?

To Reproduce

Steps to reproduce the behavior:

  1. Create a test that takes a snapshot
  2. Run jest like normal
  3. Rename the test file, but not its snapshot file
  4. Run jest --no-cache --watch

Expected behavior

No errors.

Link to repl or repo (highly encouraged)

None yet.

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: macOS 10.14.1
    CPU: (12) x64 Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz
  Binaries:
    Node: 11.3.0 - ~/.nvm/versions/node/v11.3.0/bin/node
    Yarn: 1.13.0 - /usr/local/bin/yarn
    npm: 6.5.0 - ~/.nvm/versions/node/v11.3.0/bin/npm
  npmPackages:
    jest: ^23.6.0 => 23.6.0 
@thymikee
Copy link
Collaborator

Please include a repro so we can download and investigate

@rmartin-carecloud
Copy link

rmartin-carecloud commented Jan 30, 2019

I am running into similar issues when attempting to run watch mode. I apologize in advance that I, unfortunately, cannot provide a repro.

Error: ENOENT: no such file or directory, stat '[redacted]/src/__tests__/searchAPI/dispensableDrug/packaged-drugs.test.js'

Error: ENOENT: no such file or directory, unlink '[redacted]/src/__tests__/searchAPI/dispensableDrug/__snapshots__/searchByID.test.js.snap'
at Object.unlinkSync(fs.js: 952: 3)
at files.filter.map.snapshotFile([redacted]/node_modules/jest-snapshot/build/index.js:79:22)
at Array.map(<anonymous>)
at Object.cleanup ([redacted]/node_modules/jest-snapshot/build/index.js:77:6)
at [redacted]/node_modules/jest-cli/build/TestScheduler.js:329:21
    at Set.forEach (<anonymous>)
  at updateSnapshotState ([redacted]/node_modules/jest-cli/build/TestScheduler.js:326:18)
  at [redacted]/node_modules/jest-cli/build/TestScheduler.js:386:7
    at Generator.next (<anonymous>)
    at step ([redacted]/node_modules/jest-cli/build/TestScheduler.js:147:30)

Run npx envinfo --preset jest

  System:
    OS: macOS 10.14.2
    CPU: (8) x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
  Binaries:
    Node: 10.15.0 - /usr/local/bin/node
    Yarn: 1.13.0 - /usr/local/bin/yarn
    npm: 6.7.0 - /usr/local/bin/npm
  npmPackages:
    jest: ^23.6.0 => 23.6.0

The issue seems to sometimes be fixed by manually deleting all snapshots. yarn test -u and then rewriting new snapshots doesn't seem to solve the issue as it continues looking for an invalid file.

@SimenB
Copy link
Member

SimenB commented Jan 31, 2019

Also, I cannot get stack traces to show (for uncaught Jest errors). Is there a CLI flag for that?

This might have been fixed as part of #7745 (not released, but you can make the essentially the same change locally by doing chalk.red(error.stack)).

@SimenB
Copy link
Member

SimenB commented Jan 31, 2019

That said, I cannot reproduce following the steps in the OP

image

Maybe this was fixed as part of the refactoring in #6143 (which landed in Jest 24)? Can any of you reproduce using Jest 24?

@rmartin-carecloud
Copy link

Maybe this was fixed as part of the refactoring in #6143 (which landed in Jest 24)? Can any of you reproduce using Jest 24?

I've upgraded and haven't run into the issue again so far. If I do, I will be sure to let you know. Thanks for looking into this for us Simen!

@SimenB
Copy link
Member

SimenB commented Feb 10, 2019

Awesome! I'll take a chance and close this, then. Happy to reopen if it's still an issue

@SimenB SimenB closed this as completed Feb 10, 2019
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants