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.
Starting with the previous structure project, the way to split the Unit Tests (ut) and Integration Tests (it) is to create a specific and dedicated package. For example it package, for integration tests and ut for unit tests. If you want to avoid previous undesirable effects, you have to configure some plugins.
Separating things Usually unit tests are fast and even if you run them by mistake, you won't feel uncomfortable. Integration, contract and acceptance tests can take several minutes if the project is huge. That's why it makes sense to separate integration and unit tests.
In general, Jest can run seven integration tests in parallel. The biggest impact on the duration for integration tests is the starting of the different docker containers.
The short answer is yes. For software to work properly, all units should integrate and perform as they're expected to. To ensure this is the case, you will need to perform integration tests.
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
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.
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