笑npm脚本的正则expression式
我想执行2个不同的testing环境,
一个用于integration tests
,另一个用于unit tests
。
文件夹结构是这样的:
__tests__/ut/p/a/t/h/file.test.ts __tests__/it/p/a/t/h/file.test.ts
我拿出了这些正则expression式:
(__tests__/ut/.*\.test)\.(tsx?|ts?)$
(__tests__/it/.*\.test)\.(tsx?|ts?)$
我的脚本如下所示:
"test:ut": "jest \"(__tests__/ut/.*\\.test)\\.(tsx?|ts?)$\"", "test:it": "jest \"(__tests__/it/.*\\.test)\\.(tsx?|ts?)$\"",
但是当我运行yarn test:ut
我得到:
yarn run v1.3.2 $ jest "(__tests__/ut/.*\.test)\.(tsx?|ts?)$" No tests found In /home/dev/sample 20 files checked. testMatch: **/__tests__/**/*.js?(x),**/?(*.)(spec|test).js?(x) - 0 matches testPathIgnorePatterns: /node_modules/ - 20 matches Pattern: (__tests__/ut/.*\.test)\.(tsx?|ts?)$ - 0 matches Done in 0.49s.
虽然,如果我在jsonconfiguration文件中使用相同的模式,它工作。
我想我是如何执行这个jest
。
我该如何解决?
编辑
执行此操作:
"test:ut": "jest -c jest.json \"(__tests__\\/ut\\/.*\\.test)\\.(tsx?|ts?)$\"",
结果no tests found
。
但是,如果我把正则expression式放在configuration文件里面,
{ "testRegex": "(__tests__\\/ut\\/.*\\.test)\\.(tsx?|ts?)$", "transform": { "^.+\\.tsx?$": "<rootDir>/node_modules/ts-jest/preprocessor.js" }, "moduleFileExtensions": [ "ts", "tsx", "js", "json", "jsx" ] }
作为npm script
执行它我只是从configuration文件testRegex
。