Don't force "--watch" into Jest
See original GitHub issueIf you are reporting a bug, please fill in below. Otherwise feel to remove this template entirely.
Description
I want the tests to terminate after running once. But there doesn’t seem to be any way to disable this behavior except setting the CI
environment variable like: "test": "CD=true react-scripts test --env=jsdom",
in package.json. I traced the source of this behavior to these lines in test.js
// Watch unless on CI
if (!process.env.CI) {
argv.push('--watch');
}
I understand that watching can be good when in the development cycle but when I want to run the tests in a pipeline or some script or git push hooks, I want to escape this mechanism.
Expected behavior
One of these
- Make the
npm test
run only once and then make another one callednpm run test:watch
that watches. - Maybe add another package.json script called
npm run test:once
Actual behavior
Tell us what actually happens.
Environment
react-scripts@0.4.1 node@6.5.0 npm@3.10.3
I can make a PR if this behavior is confirmed.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:14
- Comments:13 (6 by maintainers)
Top 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 >How to run, ignore or skip Jest tests, suites and files
Skip and ignore tests by filtering with the Jest CLI in interactive watch mode. To run the Jest CLI in interactive or watch...
Read more >Start jest in watch mode without executing any tests
I have a lot of test files in my project, and I would like to know how can I start jest in watch...
Read more >Modern React testing, part 2: Jest and Enzyme - Artem Sapegin
This is how I usually run Jest. Watch mode is fast enough even in large projects, where running all tests takes many minutes....
Read more >Configuring code coverage in Jest, the right way
If there is something that should be never overlooked in any project, be it JavaScript or any other language, that's code coverage.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
From your PR:
CI
is already being handledCOVERAGE
doesn’t really seem like a good fit for me because you can already runnpm test -- --coverage
as explained in User Guide, and it works in watch mode just as fine.NO_TEST_WATCH
or similar in the comment above in this thread. As I also noted, I’m happy to revisit this at some point, but not now.I understand your arguments well. I have considered each of these options (including leaving
--watch
inpackage.json
) when I was integrating the test watcher. I made a choice to default to--watch
unlessCI
is present, and I intend to stick to that choice for a while now. I appreciate your feedback and I’m happy to discuss this again in several months, but I don’t intend to change it now.Simple hack is to prevent
--watch
is this:This works because the code detects presence of
--watchAll
: