0

Scenario

I'm working on an app that has fast unit/functional jest tests along with slower end-to-end jest-puppeteer tests. I would like to split those up so that I can run the faster tests as part of a git pre-commit hook and leave the end-to-end tests to be run on CI after the code is eventually pushed to origin.

Question

How can I define specific tests to run at pre-commit? Specifically via regex similar to jest moduleNameMapper eg <rootDir>/__tests__/[a-z]+\.unit\.test\.js


  • Best idea so far:

in package.json add test:pre which uses bash find . -regex with bash for do to run desired "pre commit" tests

Jacksonkr
  • 31,583
  • 39
  • 180
  • 284
  • Which part of this are you stuck on? How to run a script pre-commit? How to write the pattern for the tests you want to select (what distinguishes them)? How to pass that to Jest (have you read https://jestjs.io/docs/en/cli.html)? – jonrsharpe Aug 10 '20 at 17:22

1 Answers1

0

I've added

"test:pre": "PRE=1 npm test -- test/pre-*test.js" 
# everything after -- is a kind of regex filter for matching file names

to my package.json scripts and in my jest-puppeteer global-setup.js I'm using

if(+process.env.PRE) return;

before all the puppeteer extras are started. So now I can

$ npm run test:pre

and violá

Jacksonkr
  • 31,583
  • 39
  • 180
  • 284