Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run specific jest project

Tags:

jestjs

lerna

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?

like image 813
donzul Avatar asked Sep 21 '18 14:09

donzul


Video Answer


3 Answers

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:

  • https://github.com/facebook/jest/issues/7542
  • https://github.com/facebook/jest/pull/8612
  • https://github.com/facebook/jest/releases/tag/v26.1.0
like image 195
Dana Woodman Avatar answered Oct 29 '22 01:10

Dana Woodman


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
like image 29
Patrick Hund Avatar answered Oct 28 '22 23:10

Patrick Hund


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

like image 40
SimenB Avatar answered Oct 29 '22 00:10

SimenB