Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jest how set file pattern in package.json script

Tags:

reactjs

jestjs

I have in packadge.json

"scripts": {
  "test": "cross-env NODE_ENV=test jest"
},

I want to test all files match pattern

 front/**/*.test.js

but if

"scripts": {
  "test": "cross-env NODE_ENV=test jest \"front/**/*.test.js\""
},

I've got an error

Invalid testPattern front/**/*.test.js supplied. Running all tests instead.

So, how could I pass file names pattern to jest?

Thanks.

like image 887
Sasha Kos Avatar asked Jun 21 '18 14:06

Sasha Kos


2 Answers

According to the documentation you are supposed to use a regex for your pattern. So in your case you probably would write something like this:

"scripts": {
    "test": "cross-env NODE_ENV=test jest \"front/.*\\.test\\.js\""
}
like image 85
ghost23 Avatar answered Sep 26 '22 12:09

ghost23


Use the testRegex parameter in your jest config to set a filename pattern:

testRegex: 'front/.*\.test\.js$'

Have a look at the documentation here.

like image 40
Chetan Jadhav CD Avatar answered Sep 25 '22 12:09

Chetan Jadhav CD