9

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?

donzul
  • 405
  • 1
  • 4
  • 13

3 Answers3

25

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:

Dana Woodman
  • 4,148
  • 1
  • 38
  • 35
7

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
Patrick Hund
  • 19,163
  • 11
  • 66
  • 95
2

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

SimenB
  • 6,410
  • 2
  • 23
  • 27