jest how set file pattern in package.json script

岁酱吖の 提交于 2020-08-19 16:44:45

问题


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.


回答1:


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\""
}



回答2:


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

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

Have a look at the documentation here.



来源:https://stackoverflow.com/questions/50971278/jest-how-set-file-pattern-in-package-json-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!