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

时间:2019-01-02 10:54:45

标签: javascript jestjs testunit

当前,我正在使用标准的testRegex逻辑来运行测试

  "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.

2 个答案:

答案 0 :(得分:1)

我使用以下命令可以工作:

jest "/client"

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

答案 1 :(得分:0)

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