I have Jest installed on my machine and typing jest
from terminal results in tests from parent folers also getting executed. I want to run tests only from the current folder.
For e.g. if I go to c:/dev/app
in terminal and type some-jest-command
, it should only run files with .test.js
present in the app
folder. Currently, running jest
command from app
folder runs tests in parent folders too, which is not my desired behaviour.
If you want to run the tests from a specific folder user the --testPathPattern jest flag. When setting up the npm script add the path to the folder as well. In your package. json add the flag in you npm scripts.
To speed-up your tests, Jest can run them in parallel. By default, Jest will parallelise tests that are in different files. IMPORTANT: Paralellising tests mean using different threads to run test-cases simultaneously.
src/file. test. js mentioned first in the Getting Started docs, and is great for keeping tests (especially unit) easy to find next to source files.
% jest --watch. By default, Jest will run tests against all changed files since the last commit, but watch mode also exposes many options. By hitting the w key, you can see the different ways to operate Jest in watch mode. The options are dynamic, so it's worth playing around within watch mode to see what's available.
By default, Jest will try to recursively test everything from whatever folder package.json
is located.
Let's say you're in c:/dev/app
, and your package.json
is in c:
. If your basic command to invoke Jest is npm test
, then try with run npm test dev/app
.
If you want to run the tests from a specific folder user the --testPathPattern jest flag. When setting up the npm script add the path to the folder as well. In your package.json add the flag in you npm scripts. Check the bellow code for an example.
"scripts": { .... "test:unit": "jest --watchAll --testPathPattern=src/js/tests/unit-tests", "test:integration": "jest --watchAll --testPathPattern=src/js/tests/integration", "test:helpers": "jest --watchAll jest --findRelatedTests src/js/tests/unit-tests/helpers/helpers.test.js" .... },
After that open the command line, change your directory where your project is and run unit test.
npm run test:unit
or integration tests.
npm run test:integration
or if you want a test only for one specific file run
npm run test:helpers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With