【问题标题】:Jest pattern "" - 0 matches (moving from jest 19 -> jest 20)笑话模式 "" - 0 个匹配项(从 jest 19 -> jest 20 移动)
【发布时间】:2017-06-02 12:06:22
【问题描述】:

我正在使用以下 jest.unittest.json 文件(通过 jest --config 选项使用):

{
  "bail": false,
  "verbose": true,
  "transform": {
    "^.+\\.(ts|tsx)$": "typescript-babel-jest"
  },
  "testPathIgnorePatterns": [
    "<rootDir>/lib",
    "<rootDir>/lib_es6",
    "/node_modules/",
    "fixtures.ts",
    "/fixtures/"
  ],
  "moduleFileExtensions": [
    "js", "jsx", "ts", "tsx", "node"
  ],
  "roots": [
    "<rootDir>/src/__unittests__/Logger",
    "<rootDir>/src/__unittests__/Renderer/renderer.test.ts"
  ],
  "testRegex": "<rootDir>/src/__unittests__/.*\\.test.(ts|tsx|js|jsx)$"
}

注意测试文件是 src/unittests/Renderer/renderer.test.ts 等等。

它曾经工作到 jest v19,但升级到 v20 后,此配置不再工作。

当我做 jest --config jest.unittest.json --verbose 时,我得到:

Pattern: "" - 0 matches

我的配置有什么问题吗?

【问题讨论】:

    标签: jestjs babel-jest


    【解决方案1】:

    尝试将testRegex 更改为类似的内容:

    "(/src/__unittests__/.*|\\.(test|spec))\\.(ts|tsx|js)$"

    【讨论】:

      【解决方案2】:

      我想说这很有趣,您配置了 2 个 roots 并在您的 testRegex 中只使用一个路径。同样在文档中,他们捕获了不带扩展名的路径和文件名,这不是您这样做的方式。用括号捕获路径和文件名。请参阅那里的文档(我也会跳过&lt;rootDir&gt;,因为您可能想同时使用两个根):https://jestjs.io/docs/configuration#testregex-string--arraystring

      【讨论】:

        猜你喜欢
        • 2022-09-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-09-23
        • 1970-01-01
        • 1970-01-01
        • 2021-06-12
        相关资源
        最近更新 更多