Jest fails when git branch name looks like a json file
See original GitHub issue🐛 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
Issue Analytics
- State:
- Created 3 years ago
- Comments:17 (7 by maintainers)
Top Results From Across the Web
error: pathspec 'test-branch' did not match any file(s) known to git
When cloning a repo, only one local branch ( master , here) is created and checked out in the resulting clone, irrespective of...
Read more >Configuring Jest
For example, with the following configuration jest will fail if there is less than 80% branch, line, and function coverage, or if there...
Read more >Husky - Git hooks
Modern native Git hooks made easy. ... Husky is used by these awesome projects: ... Another case you may be in is if...
Read more >Setting Up Jest - LearnHowToProgram.com
Make sure that you are referencing the code from the branch called 1_functioning_environment . This is the default branch, so running git clone......
Read more >Beyond API testing with Jest | CircleCI
Jest is a JavaScript-based testing framework that lets you test both ... Next, you need to make some changes to the package.json file...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

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
findin it)In the next days, I’ll update my PR to follow this approach.