按特定路径运行测试的开玩笑



目前我正在使用标准的测试正则表达式逻辑来运行我的测试

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

但我想使用特定路径拆分它们

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

我看到有一个选项--runTestsByPath。 但我找不到任何例子

欢迎反馈

更新

我尝试添加脚本

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

使用测试文件:tests/client/test.spec.js

但得到一个错误:

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

我使用以下命令并工作:

jest "/client"

您可以在此处查看 Jest 文档:https://jestjs.io/docs/en/22.x/cli

--runTestsByPath 需要前导的 './'

我为自己工作:

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

jest --runTestsByPath "./directory"

注意我使用的是 WSL1,但对于大多数 Linux 版本来说应该是相同的。

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

最新更新