简体   繁体   English

Jest 按特定路径运行测试

[英]Jest running tests by specific path

currently I am using the standard testRegex logic to run my tests目前我正在使用标准的 testRegex 逻辑来运行我的测试

  "jest": {
    "moduleFileExtensions": [
      "ts",
      "js"
    ],
    "transform": {
      "^.+\\.ts?$": "<rootDir>/node_modules/ts-jest/preprocessor.js",
      "^.+\\.js?$": "babel-jest"
    },
    "testRegex": "/tests/.*\\.(ts|js)$"
  }

But I would like to split them using specific paths但我想使用特定路径拆分它们

test-client   "testRegex": "/tests/client/.*\\.(ts|js)$"
test-server   "testRegex": "/tests/server/.*\\.(ts|js)$"

I see that there is a, option --runTestsByPath.我看到有一个选项 --runTestsByPath。 but I cannot find any example of it但我找不到任何例子

feedback welcome欢迎反馈

UPDATE更新

I tried to add the script我试图添加脚本

"test-client": "jest   --runTestsByPath \"tests/client/\""

with a test file : tests/client/test.spec.js带有测试文件:tests/client/test.spec.js

but got an error :但出现错误:

$ jest   --runTestsByPath "tests/client/"
No tests found
No files found in /Users/../myapp.
Make sure Jest's configuration does not exclude this directory.

I use the follow command and works:我使用以下命令并工作:

jest "/client"

You can see the Jest documentation here: https://jestjs.io/docs/en/22.x/cli您可以在此处查看 Jest 文档: https : //jestjs.io/docs/en/22.x/cli

jest someDirectory --collectCoverageFrom=**/someDirectory/**/*.js

--runTestsByPath needs the leading './' --runTestsByPath 需要前导'./'

I have got this working for myself:我已经为自己工作了:

jest --runTestsByPath "./directory/testFile.js"

and

jest --runTestsByPath "./directory"

Note I'm on WSL1, but should be the same for most flavours of linux.注意我在 WSL1 上,但对于大多数风格的 linux 应该是相同的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM