Jest: Running jest in watch mode with an invalid file pattern causes jest to throw an exception.

Created on 19 Nov 2018  ยท  22Comments  ยท  Source: facebook/jest

๐Ÿ› Bug Report

Running Jest in watch mode and providing an invalid file pattern causes Jest to error and the process freezes. You have to send the process a SIGINT to kill the process, basically control + c

To Reproduce

Steps to reproduce the behavior:

Run jest in watch mode and filter by file name (Press P). Provide * as a pattern and the following is observed.

Do this.

image

And this is what happens

image

Only way to kill jest is to press control + c.

Expected behavior

Jest is known for its pleasant developer experience. This exception should return a developer friendly error and not cause Jest to hang with the only way of stopping it is to do a control + c;

Link to repl or repo (highly encouraged)

Not needed as it is easy to replicate.

Run npx envinfo --preset jest

Paste the results here:


npx: installed 1 in 3.086s

  System:
    OS: macOS High Sierra 10.13.6
    CPU: (4) x64 Intel(R) Core(TM) i5-7267U CPU @ 3.10GHz
  Binaries:
    Node: 8.11.3 - ~/.nvm/versions/node/v8.11.3/bin/node
    Yarn: 1.9.4 - /usr/local/bin/yarn
    npm: 6.4.1 - /usr/local/bin/npm
  npmPackages:
    jest: ^23.6.0 => 23.6.0

Note: I can make a PR for this if this behaviour is indeed not the desired behaviour.

Bug

Most helpful comment

I'm getting the same error on 24.0.0-alpha.6 when running npm test (which runs jest with no arguments). My config is empty. Removing node_modules and re-installing did not fix the issue for me.

$ npx envinfo --preset jest
npx: installed 1 in 1.477s
Path must be a string. Received undefined
npx: installed 1 in 1.483s
C:\Users\b\AppData\Roaming\npm-cache\_npx\15536\node_modules\envinfo\dist\cli.js

  System:
    OS: Windows 10
    CPU: (12) x64 Intel(R) Core(TM) i7-6800K CPU @ 3.40GHz
  Binaries:
    Yarn: 1.10.1 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 6.4.1 - C:\Program Files\nodejs\npm.CMD

All 22 comments

Yeah, that's not desired behavior. PR very much welcome!

Providing an invalid pattern in non-watch mode prints an error (Invalid testPattern * supplied. Running all tests instead.) and runs all tests.

Personally I think an invalid error should exit (with code 1) without running tests in non-watch, and print an error in watch mode.

@natealcedo @SimenB Can I pick it up?
P.S. @SimenB if it is not too complicated for the Jest first time contributing.

@SerhiiBilyk go for it! I'm actually not sure if it's too advanced, you should be able to grep your way to where the text is printed and where the error is thrown. Feel free to ask questions ๐Ÿ™‚

@SimenB I have found the code which is need to be fixed.
But I can't start development build of Jest in my project.
I did the build step by step from https://github.com/facebook/jest/blob/master/CONTRIBUTING.md
When I try to run jest, I'm getting the next error:

โ— Unrecognized CLI Parameters:

  Following options were not recognized:
  ["changed-files-with-ancestor", "clear-cache", "clear-mocks", "collect-coverage", "detect-leaks", "detect-open-handles", "error-on-deprecated", "find-related-tests",
"force-exit", "last-commit", "list-tests", "log-heap-usage", "map-coverage", "no-stack-trace", "only-changed", "only-failures", "pass-with-no-tests", "reset-mocks", "reset-modules", "restore-mocks", "run-in-band", "run-tests-by-path", "show-config", "skip-filter", "test-location-in-results", "update-snapshot", "use-stderr", "watch-all", "notify-mode", "prettier-path"]

  CLI Options Documentation:
  https://jestjs.io/docs/en/cli.html

[nodemon] app crashed - waiting for file changes before starting...

What I'm doing wrong?
P.S.I have tried also 'npm link'

@SerhiiBilyk what command are you running? Are you sure you checked out and pulled master?

@rickhanlonii yes, I'm sure.
1) In my clone:
get fetch , git pull
git checkout master
git checkout -b bugfix/7382
yarn link (in packages/jest-cli)
yarn run build (in root folder)

2) In my project:
yarn link jest-cli
3) When I'm running inside my project: jest --watch path/to/file
I see the code (console.log) which I previously have added to clone repo jest-cli/bin/jest.js
But next, I see an error :(

What I'm doing wrong?

Those steps should work - do you have a link to your jest fork so I can try?

@rickhanlonii https://github.com/SerhiiBilyk/fork_jest here you have

Hm, did you manually fork that? It would be pretty difficult for me to verify that fork before running it, can you fork it through github and try that way?

@rickhanlonii oh, sorry, anyway it was most fresh clone.
Here is my fork, https://github.com/SerhiiBilyk/jest

I'm not sure what's the best place to report jest@beta issues, but I'm also getting above mentioned "Unrecognized CLI Parameters" error.

Minimal repro case:

โ‹Š> cd /tmp/

/p/tmp
โ‹Š> mkdir jest-beta

/p/tmp
โ‹Š> cd jest-beta/

/p/t/jest-beta
โ‹Š> nix-shell -p nodejs-8_x --run fish
set: Tried to change the read-only variable '_'
Welcome to fish, the friendly interactive shell

/p/t/jest-beta
โ‹Š> npm init -y
Wrote to /private/tmp/jest-beta/package.json:

{
  "name": "jest-beta",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}



/p/t/jest-beta
โ‹Š> npm i -E -D jest@beta

> [email protected] install /private/tmp/jest-beta/node_modules/fsevents
> node install

[fsevents] Success: "/private/tmp/jest-beta/node_modules/fsevents/lib/binding/Release/node-v64-darwin-x64/fse.node" already installed
Pass --update-binary to reinstall or --build-from-source to recompile
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN [email protected] No description
npm WARN [email protected] No repository field.

+ [email protected]
added 635 packages from 363 contributors and audited 18183 packages in 11.706s
found 0 vulnerabilities


/p/t/jest-beta
โ‹Š> npx jest
โ— Unrecognized CLI Parameters:

  Following options were not recognized:
  ["changed-files-with-ancestor", "clear-cache", "clear-mocks", "collect-coverage", "detect-leaks", "detect-open-handles", "error-on-deprecated", "find-related-tests", "force-exit", "last-commit", "list-tests", "log-heap-usage", "map-coverage", "no-stack-trace", "only-changed", "only-failures", "pass-with-no-tests", "reset-mocks", "reset-modules", "restore-mocks", "run-in-band", "run-tests-by-path", "show-config", "skip-filter", "test-location-in-results", "update-snapshot", "use-stderr", "watch-all", "notify-mode", "prettier-path"]

  CLI Options Documentation:
  https://jestjs.io/docs/en/cli.html

It is strange, because I'm running jest without any CLI parameters

This is v weird, @SerhiiBilyk I ran your fork with no troubles

Can you both post the result of npx envinfo --preset jest?

@rickhanlonii
System:
OS: Windows 10
CPU: (4) x64 Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz
Binaries:
Yarn: 1.9.4 - ~\AppDataRoaming\npm\yarn.CMD
npm: 6.4.0 - ~\AppDataRoaming\npm\npm.CMD

@rickhanlonii after removing node_modules (rm rf), and installing it again, it works as expected. I don't know why. I did it previously, but it wasn't work

I'm getting the same error on 24.0.0-alpha.6 when running npm test (which runs jest with no arguments). My config is empty. Removing node_modules and re-installing did not fix the issue for me.

$ npx envinfo --preset jest
npx: installed 1 in 1.477s
Path must be a string. Received undefined
npx: installed 1 in 1.483s
C:\Users\b\AppData\Roaming\npm-cache\_npx\15536\node_modules\envinfo\dist\cli.js

  System:
    OS: Windows 10
    CPU: (12) x64 Intel(R) Core(TM) i7-6800K CPU @ 3.40GHz
  Binaries:
    Yarn: 1.10.1 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 6.4.1 - C:\Program Files\nodejs\npm.CMD

Let's track the failed jest@beta runs in https://github.com/facebook/jest/issues/7424 and keep this issue on track to fix the og issue ๐Ÿ‘Œ

@SimenB @rickhanlonii :
1) Do I must to check if I'm in watch mode or above prompt is by default in watch mode?
2) Do I need to process.exit(1) if path RegExp is invalid?
3) What about running all tests?
Thank you

Will defer to @SimenB, I'm not familiar with the issue

1 nah, it should always fail
2 no, just throw. We don't want to exit in watch mode, only print the error
3 what do you mean?

@SimenB Do I need run all tests in watch mode if regexp will be invalid?

Ah! No, just print an error and wait for the user to change the pattern

Was this page helpful?
0 / 5 - 0 ratings