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.

Allow `npm test` to not run in watch mode for better cross-platform / tooling CI.

See original GitHub issue

I’ve been using create-react-app in conjunction with lerna repos and for the most part its been an awesome experience. The one issue I’ve been seeing is when trying to issue lerna run test commands to test all packages that have a “test” script. Since create-react-app defaults to entering watch mode on test, it hangs.

After some digging it looks like I might be able to set a CI environment variable to disable the watch mode, however this does not work well due to the nuances of setting environment variables cross platform.

Something as simple as changing the default from

    "test": "react-scripts test --env=jsdom",

to

    "test": "react-scripts test --env=jsdom --watch",

would allow me to simply turn it off. Conversely adding an optional --no-watch or --single-run flag would solve the problem.

I’m happy to submit a PR, but wanted to get some feedback first on the internal direction regarding whether this has been considered in the past, and the reasoning around the current implementation. I get that its a nice experience for the casual user, but at the cost of CI and incompatibility with lerna there should be some sort of escape hatch (short of eject).

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:22
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

87reactions
troygoodecommented, Jan 2, 2017

@cchamberlain I’ve just changed my package.json to:

"test": "CI=true react-scripts test --env=jsdom",

which works great

44reactions
gaearoncommented, Feb 11, 2017

You can set them in cross-platform way:

npm i --save-dev cross-env

then use

  "test": "cross-env CI=true react-scripts test --env=jsdom"

Further, npm test is commonly used in CI processes in the context of it being a single run without needing to set an environment variable.

I think you might have misunderstood. In most CIs you don’t need to set this variable because it is already set by CI environments. Travis, Circle, and probably others already do this.

I hope this helps!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Running Tests | Create React App
By default npm test runs the watcher with interactive CLI. However, you can force it to run tests once and finish the process...
Read more >
Run Create-React-App Tests not in Watch Mode
Cross platform solution for this: Install cross-env; Use your test command with such props: "test:nowatch": "cross-env CI=true react-scripts ...
Read more >
best-practice - npm
Launches the test runner in the interactive watch mode. See the section about running tests for more information.
Read more >
Frontend testing standards and style guidelines - GitLab Docs
Running yarn jest-debug runs Jest in debug mode, allowing you to debug/inspect ... If you cannot improve the performance of the tests, you...
Read more >
Test tools for .NET and cross-platform apps - Visual Studio Blog
Visual Studio 2022 brings better test tools to your everyday development with Show in Test Explorer, Remote Testing, Test audio cues, ...
Read more >

github_iconTop Related Medium Post

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