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

Most upvoted comments

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-L56

and 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:

  • Jest v21.0.1
  • Node v8.4.0
  • npm v5.4.0
  • Mac OS 10.12.4

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:

...
"react": "16.0.0-alpha.12",
"react-native": "0.45.1",
"react-native-camera": "^0.10.0",
"babel-jest": "21.2.0",
"babel-preset-react-native": "4.0.0",
"jest": "21.2.1",
...

2 possibles solutions (that I found):

  1. I downgraded back to V20.0.4.
  2. instead of ‘yarn test --watch’ I am using ‘yarn test --watchAll’ (as @TroySchmidt suggested)