jest: Unhelpful error message when jest --watch is run outside of git repository
Do you want to request a feature or report a bug? Bug
What is the current behavior?
When jest --watch
is executed inside a non-git folder the following exception is raised:
Determining test suites to run...Error: This promise must be present when running with -o.
at /path/to/node_modules/jest-cli/build/search_source.js:192:17
at next (native)
at step (/path/to/node_modules/jest-cli/build/search_source.js:20:362)
at /path/to/node_modules/jest-cli/build/search_source.js:20:592
at /path/to/node_modules/jest-cli/build/search_source.js:20:273
at SearchSource.getTestPaths (/path/to/node_modules/jest-cli/build/search_source.js:204:10)
at /path/to/node_modules/jest-cli/build/run_jest.js:45:31
at next (native)
at step (/path/to/node_modules/jest-cli/build/run_jest.js:24:380)
at /path/to/node_modules/jest-cli/build/run_jest.js:24:540
If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can yarn install
and yarn test
.
- Set up a new project (or clone existing one)
- Make sure
.git
folder is not present (removed) - Run jest
What is the expected behavior? A more helpful message as to why jest failed.
Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
- Jest v21.0.1
- NodeJS v6.10.1
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 61
- Comments: 15 (5 by maintainers)
Commits related to this issue
- Use watchAll fallback for non git/hq projects (#4419) — committed to sesigl/jest by sesigl 7 years ago
- Use watchAll fallback for non git/hq projects (#4737) * Use watchAll fallback for non git/hq projects (#4419) * use stdout instead of console * print error when no hq/git project instead of cha... — committed to jestjs/jest by sesigl 7 years ago
- Use watchAll fallback for non git/hq projects (#4419) — committed to sesigl/jest by sesigl 7 years ago
- fix watch fallback for non git/hg projects (#4865) * Use watchAll fallback for non git/hq projects (#4419) * use stdout instead of console * print error when no hq/git project instead of changi... — committed to jestjs/jest by sesigl 7 years ago
- Fixed jest/enzyme crap. Problem known, https://github.com/facebook/jest/issues/4419, caused by yarn and npm being in the same place... — committed to PeterTognola/MarkdownDocuments by PeterTognola 6 years ago
Downgrading back to jest cli version 20.0.4 seems to be a temporary solution:
npm install jest-cli@20.0.4 --save
or (I believe):yarn add jest-cli@20.0.4
Thanks for the point out there @aaronabramov. I ended up changing to --watchAll which helps to circumvent this issue.
Fixed in #4737 (not released)
@rogeliog it seems like it happens because
onlyChanged
is set to true here https://github.com/facebook/jest/blob/master/packages/jest-cli/src/lib/update_global_config.js#L53-L56and if
onlyChanged
is true, we assume that we’re in a git/hg repo and try to get the list of changed files, which is not possible if we’re not in git.Can we just remove this assignment from watch mode? is this config option is used for anything else then getting changed files from hg/git?
I’ve run into the same issue with the follow configuration:
I did a little playing with versions to deduce where the problem may have started. Downgrading to Jest v21.0.0 leaves me with the same problem, and the same workaround as above solves the issue. I’m able to run
jest --watch
with no errors when using Jest v20.0.4 and missing a .git directory in my project.My configuration is:
2 possibles solutions (that I found):