Reputation: 179
Currently, I have two folders: __tests__
for unit (fast) tests and __integration__
for slow tests.
Then, in package.json
:
{
"scripts": {
"test": "jest",
"test:integration": "jest -c '{}'",
...
},
"jest": {
"testPathIgnorePatterns": ["/node_modules/", "__integration__"]
}
}
So, when I want to do TDD, I'm running just npm test
and when I want to test the entire project, npm run test:integration
.
As Jest is offered as a "no configuration" test framework, I was thinking if there's a better (or proper) way to configure this.
Thank you.
Upvotes: 17
Views: 11540
Reputation: 12693
Quoting from this post.
You can try name files like:
index.unit.test.js
and api.int.test.js
And with Jest’s pattern matching feature, it makes it simple to run them separately as well. For unit testing run
jest unit
and for integration testing runjest int
.
File structure/location you can define based on your preferences as the pattern matching based on the file name is how jest knows what to run.
Also see jest cli documentation about npm scripts:
If you run Jest via
npm test
, you can still use the command line arguments by inserting a--
betweennpm test
and the Jest arguments
Upvotes: 27
Reputation: 1850
Have you tried jest --watch
for TDD? It runs only files related to your git changes, runs errors first and heavily utilise cache for speed.
Other than that, jest -c
accepts a path, not a string. You should be good with jest -c jest-integration-config.json
, provided that jest-integration-config.json sits in your project's root.
Upvotes: 10