【问题标题】:Jest running tests by specific path开玩笑按特定路径运行测试
【发布时间】:2019-01-02 10:54:44
【问题描述】:

目前我正在使用标准的 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.

【问题讨论】:

标签: javascript jestjs testunit


【解决方案1】:

我使用以下命令并且工作:

jest "/client"

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

【讨论】:

    【解决方案2】:

    --runTestsByPath 需要前导 './'

    我已经为自己解决了这个问题:

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

    jest --runTestsByPath "./directory"
    

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

    【讨论】:

      【解决方案3】:
      jest someDirectory --collectCoverageFrom=**/someDirectory/**/*.js
      

      【讨论】:

        猜你喜欢
        • 2018-07-02
        • 1970-01-01
        • 2017-11-01
        • 2018-12-27
        • 1970-01-01
        • 2017-05-10
        • 2020-02-06
        • 2020-03-25
        • 1970-01-01
        相关资源
        最近更新 更多