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

🐛 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.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 25 (10 by maintainers)

Most upvoted comments

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

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

> fsevents@1.2.4 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 jest-beta@1.0.0 No description
npm WARN jest-beta@1.0.0 No repository field.

+ jest@24.0.0-alpha.6
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