-
-
Notifications
You must be signed in to change notification settings - Fork 27k
Allow npm test
to not run in watch mode for better cross-platform / tooling CI.
#1137
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
Comments
@cchamberlain Could you elaborate on why setting the |
@fson - Thanks, I'll test it out soon but think it should work. Still feels against the norm to me for |
@cchamberlain I've just changed my
which works great |
@troygoode - Have you tried that on Windows? |
@cchamberlain no, I haven't. works great in bash though |
@troygoode - The main problem here is that setting environment variables via scripts section is not cross-platform friendly and is not on a roadmap to ever be (last I read). On Windows, you would need to use: Further, |
You can set them in cross-platform way:
then use "test": "cross-env CI=true react-scripts test --env=jsdom"
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! |
// Watch unless on CI or in coverage mode
if (!process.env.CI && argv.indexOf('--coverage') < 0) {
argv.push('--watch');
} From this, For my projects I've created an additional NPM script: "test:coverage": "npm test -- --coverage" and just include that in other script definitions as needed when I want to run tests only once. |
Thanks @gaearon and @ryansully. Both of those should cover my needs. |
If you can create a standalone reproducing case somebody might be able to take a look! |
As explained here: facebook/create-react-app#1137 (comment)
Jenkins does not set CI env variable. Also setting up debug launch configuration in VS Code for tests is extra effort. Actually I am not yet figure it out. |
Seems like react-scripts test by default goes into a continuous mode watching the file system. It also appears that this causes problems both on Windows and the Linux CI build such that the test infrastructure does not find any tests until a file is changed. Using --coverage is a hack ([based on a comment in CRA](facebook/create-react-app#1137 (comment))) that react-scripts looks for and forces immediate test run and no watching.
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
to
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).
The text was updated successfully, but these errors were encountered: