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

[FeatureRequest] Allow jest to be ran without watch mode. #6284

Closed
ricokahler opened this issue Jan 27, 2019 · 5 comments
Closed

[FeatureRequest] Allow jest to be ran without watch mode. #6284

ricokahler opened this issue Jan 27, 2019 · 5 comments
Assignees

Comments

@ricokahler
Copy link
Contributor

It seems like the only way to get jest to run in without watch mode is to run it with --coverage or set the environment variable to CI=true. Running npm test -- --watch=false (and similar) does not work.

My use case for this feature is debugging within VS Code through react scripts.

The following launch configuration was given in the create-react-app docs

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Debug CRA Tests",
      "type": "node",
      "request": "launch",
      "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/react-scripts",
      "args": [
        "test",
        "--runInBand",
        "--no-cache"
      ],
      "cwd": "${workspaceRoot}",
      "protocol": "inspector",
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen"
    }
  ]
}

This somewhat works but it does not break at breakpoints because (I think) react-scripts is runs jest in watch mode. Adding "env": { "CI": "true" }, allows breakpoints to work again because it disables watch mode.

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Create react app debugging",
      "type": "node",
      "request": "launch",
      "env": { "CI": "true" }, // this makes breakpoints work 
      "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/react-scripts",
      "args": ["test", "--runInBand", "--no-cache"],
      "cwd": "${workspaceRoot}",
      "protocol": "inspector",
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen"
    }
  ]
}

I'm fine with this workaround but I'd happier with a --watch=false, --no-watch, --single, or similar flag.

Thanks for the amazing tool and I apologize if I missed anything!

Somewhat related issues:

#784
#1137

@ricokahler ricokahler changed the title [FeatureRequest] Allow jest to be ran not to be ran in watch mode. [FeatureRequest] Allow jest to be ran without watch mode. Jan 27, 2019
@rally25rs
Copy link

+1 for this feature, especially considering #2393 (when in watch mode on linux, it fails with too many file watchers)

The fix for this is in jest@24, but as of now, react-scripts is locked to jest@23.6.0 but if you could run jest not in watch mode, then it would be a way to workaround the above issue.

@mrmckeb
Copy link
Contributor

mrmckeb commented Jan 30, 2019

I think we need to address this, as it is raised often. I'd be open to a PR adding --no-watch.

@rally25rs, I'm not sure what feature you're referring to - can you provide a link?

I use it with watch-mode on Linux (Ubuntu) and it works well locally.

@mrmckeb mrmckeb self-assigned this Jan 30, 2019
@ricokahler
Copy link
Contributor Author

ricokahler commented Jan 30, 2019

@mrmckeb I put up this one-line PR for --watch=false #6285 if you didn't see. Not sure if it solves the problem the correct way but the simple change seemed to do the job.

@rally25rs
Copy link

@mrmckeb #2393 and jestjs/jest#3254 are the issues I'm trying to resolve. In a very simple new react app (crate-react-app plus react-router and react-bootstrap; and the project has 2 views in it so far just to test out react-router):

vagrant@vagrant-ubuntu-trusty-64:~/projects/business_continuity/management_ui$ yarn test
yarn run v1.13.0
$ react-scripts test
internal/fs/watchers.js:173
    throw error;
    ^

Error: ENOSPC: System limit for number of file watchers reached, watch '/home/vagrant/projects/business_continuity/management_ui/node_modules/eslint-plugin-react/node_modules/resolve/test/module_dir/ymodules'
    at FSWatcher.start (internal/fs/watchers.js:165:26)
    at Object.watch (fs.js:1254:11)
    at NodeWatcher.watchdir (/home/vagrant/projects/business_continuity/management_ui/node_modules/sane/src/node_watcher.js:175:20)
    at Walker.<anonymous> (/home/vagrant/projects/business_continuity/management_ui/node_modules/sane/src/common.js:116:12)
    at Walker.emit (events.js:182:13)
    at /home/vagrant/projects/business_continuity/management_ui/node_modules/walker/lib/walker.js:69:16
    at go$readdir$cb (/home/vagrant/projects/business_continuity/management_ui/node_modules/graceful-fs/graceful-fs.js:162:14)
    at FSReqWrap.oncomplete (fs.js:141:20)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

the issue seems to be that react-scripts forces jest --watch and jest then tries to watch every file in node_modules (i base this on the comments of these linked issues. it seems to make sense anyway, as my actual project not including node_modules only has a couple dozen files)

In the linked issue there is a comment that this is fixed in jest@24 but react-scripts errors if you use any version but 23.6.0. It also prevents you from setting the jest config option watchPathIgnorePatterns which you could use to tell jest to no longer watch files in node_modules. There is also no way to run jest without --watch and avoid this altogether.

react@16.7.0
react-scripts@2.1.3
jest@23.6.0

@mrmckeb
Copy link
Contributor

mrmckeb commented Jan 31, 2019

We need to bump to jest@24, agreed @rally25rs. For now though, a no-watch flag would help a lot of people.

@lock lock bot locked and limited conversation to collaborators Feb 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants