question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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:

https://github.com/facebook/create-react-app/issues/784 https://github.com/facebook/create-react-app/issues/1137

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mrmckebcommented, 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.

0reactions
rally25rscommented, Jan 30, 2019

@mrmckeb #2393 and https://github.com/facebook/jest/issues/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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest CLI Options
The jest command line runner has a number of useful options. You can run jest --help to view all available options. Many of...
Read more >
Learn Jest Watch Mode – Testing React Applications, v2
Here's what you'd learn in this lesson: When configuring Jest watch mode, which allows runs tests related to only the files that have...
Read more >
Jest | WebStorm Documentation - JetBrains
Configure rerunning tests automatically on changes in the related source files. To do that, add the --watch flag in the Jest options field....
Read more >
Frontend testing standards and style guidelines - GitLab Docs
Running yarn jest-debug runs Jest in debug mode, allowing you to debug/inspect as described ... You can also run some focused tests without...
Read more >
vscode-jest - Visual Studio Marketplace
This extension supports full jest features in vscode environment to ... automatically run and monitor all tests in watch mode upon launch, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found