I'm setting up a lerna monorepo with jest, I'm using jest's projects like so: projects: ['<rootDir>/packages/*']
.
Running tests work as expected, however, I'm not sure how can I run a specific project? Say I have:
/packages
jest.config.js
/core
jest.config.js
/blog
jest.config.js
Currently jest
runs tests in both packages using their specific configs, however, I'm not sure how can I tell jest to just run tests in one of those packages?
Assuming you want to do this with Jest's projects
property:
As of Jest v26.1.0, you can now run selected projects
with Jest by doing the following:
jest --selectProjects myproj
This will find any "project" in your jest.config.js
by it's displayName
value.
See:
You can call jest with the name of a test that you want to run. You can also use just parts of the path to the test, or even a regular expression. So in your case, you could run tests in the core
package like this:
jest packages/core
There is currently no clean way of doing it from the CLI (see https://github.com/facebook/jest/issues/6189), but you can use https://github.com/rogeliog/jest-watch-select-projects to achieve it in watch mode
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