How to prevent testing-libarary running coverage on untested files every time I save my test file?

Viewed 896

I am using the test-library for React , and everytime I edit my test file and save it, it will automatically running coverage on other untested files and gave me a report. there are hundreds of files in my project,and it could really waste time. I don't want this, I just want it run test on my current selected file.

the command I have used is

npm run test /myprojrct/myFile.test.js

is there a way to resolve it ?

2 Answers

Adding the --watch flag to your test script should make jest run tests only on changed files after each save.

More details and other available options can be found here: https://jestjs.io/docs/en/cli#--watch

You should add --coverage=false flag to prevent collecting coverage.

npm run test --coverage=false

Other useful flags:

npm run test --watch // watcher will re-run only the tests that depend on the changed files
npm run test --watchAll // watcher will re-run *ALL* tests when a file has changed
npm run test -t="rendering Button" // will run only tests with a name that matches the regex
npm run test fileName.js // this argument will be treated as a regular expression to match against files in your project
Related