Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
natealcedo opened this issue Nov 19, 2018 · 25 comments

Comments

@natealcedo
Copy link

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

@SimenB
Copy link
Member

SimenB commented Nov 19, 2018

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.

@captain-yossarian
Copy link

captain-yossarian commented Nov 21, 2018

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

@SimenB
Copy link
Member

SimenB commented Nov 21, 2018

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

@captain-yossarian
Copy link

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

@rickhanlonii
Copy link
Member

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

@captain-yossarian
Copy link

captain-yossarian commented Nov 24, 2018

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

@rickhanlonii
Copy link
Member

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

@captain-yossarian
Copy link

captain-yossarian commented Nov 26, 2018

@rickhanlonii
Copy link
Member

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?

@captain-yossarian
Copy link

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

@onetom
Copy link

onetom commented Nov 27, 2018

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

@captain-yossarian
Copy link

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

@rickhanlonii
Copy link
Member

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

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

@captain-yossarian
Copy link

captain-yossarian commented Nov 27, 2018

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

@captain-yossarian
Copy link

@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

@bcanseco
Copy link

bcanseco commented Nov 28, 2018

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
Copy link
Member

Let's track the failed jest@beta runs in #7424 and keep this issue on track to fix the og issue 👌

@captain-yossarian
Copy link

@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

@rickhanlonii
Copy link
Member

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

@SimenB
Copy link
Member

SimenB commented Nov 29, 2018

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?

@captain-yossarian
Copy link

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

@SimenB
Copy link
Member

SimenB commented Nov 29, 2018

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

@github-actions
Copy link

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the Stale label Feb 25, 2022
@github-actions
Copy link

This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants