jest: Jest fails when git branch name looks like a json file
π Bug Report
Jest hard-fails with an exit code if the git branch is named package.json
To Reproduce
Steps to reproduce the behavior:
- Create a git branch named
fix/package.json
- Push the branch to a remote
- Run jest
jest --coverage
Expected behavior
Jest runs as normal
Actual behavior
Jest errors because it perceives the git reference marker file as a JSON file (because of the filename) and attempts to parse that reference marker as JSON (which it isnβt, and never would be)
> jest --coverage
Error: Cannot parse /Users/c050004/Documents/git/logger/.git/refs/heads/fix/package.json as JSON: Unexpected token e in JSON at position 0
at Object.<anonymous> (/Users/c050004/Documents/git/logger/node_modules/jest-haste-map/build/worker.js:167:15)
at Generator.next (<anonymous>)
at asyncGeneratorStep (/Users/c050004/Documents/git/logger/node_modules/jest-haste-map/build/worker.js:78:24)
at _next (/Users/c050004/Documents/git/logger/node_modules/jest-haste-map/build/worker.js:98:9)
at /Users/c050004/Documents/git/logger/node_modules/jest-haste-map/build/worker.js:103:7
at new Promise (<anonymous>)
at Object.<anonymous> (/Users/c050004/Documents/git/logger/node_modules/jest-haste-map/build/worker.js:95:12)
at Object.worker (/Users/c050004/Documents/git/logger/node_modules/jest-haste-map/build/worker.js:120:18)
at execFunction (/Users/c050004/Documents/git/logger/node_modules/jest-worker/build/workers/processChild.js:155:17)
at execHelper (/Users/c050004/Documents/git/logger/node_modules/jest-worker/build/workers/processChild.js:139:5)
npm ERR! Test failed. See above for more details.
Link to repl or repo (highly encouraged)
- https://github.com/amclin/react-project-boilerplate/pull/329
- https://travis-ci.com/github/amclin/react-project-boilerplate/jobs/320222180#L245
envinfo
System:
OS: macOS 10.15.3
CPU: (8) x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
Binaries:
Node: 10.16.3 - ~/.nvm/versions/node/v10.16.3/bin/node
Yarn: 1.19.1 - /usr/local/bin/yarn
npm: 6.14.4 - ~/Documents/git/logger/node_modules/.bin/npm
npmPackages:
jest: ^25.3.0 => 25.3.0
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 17 (15 by maintainers)
Commits related to this issue
- test: temporary non-invasive commit for testing jest See https://github.com/facebook/jest/issues/9829 — committed to amclin/react-project-boilerplate by deleted user 4 years ago
I donβt think we need to make it configurable for now. Somebody can complain if they really need it, but I donβt really see a use case for tests in a VCS directory (while I can imagine use cases for tests in other hidden directories).
And yes, we only need to update the node crawler (which also has
find
in it)In the next days, Iβll update my PR to follow this approach.
Yes, I took a look in this page on watchman docs and looks like it ignores
.git
by default.To reproduce the error, I did the following locally (in the jest repo).
Might be that watchman just ignores
.git
directory and not hidden files in general?My main issue with fixing this issue via an ignore pattern is that if people override that pattern, watchman would still ignore it, but other crawlers would not. Which is why I think maybe fixing the crawlers is a better solution?
Oh, thanks for the PR @leonardovillela, very much appreciated π
I think it would be a sane default to skip dotfiles in
modulePathIgnorePatterns
and document (add a note?) how to enable this scenario (people put their tests innode_modules/
directories, so I can imagine someone is using a dotfile for the same thing π)