【问题标题】:Code coverage "Unknown" using jest 15.1.1使用 jest 15.1.1 的代码覆盖率“未知”
【发布时间】:2017-01-26 11:04:15
【问题描述】:

当我尝试包含所有项目源代码以获得更合理的代码覆盖率数字时,我最终得到了

----------|----------|----------|----------|----------|----------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
All files |  Unknown |  Unknown |  Unknown |  Unknown |                |
----------|----------|----------|----------|----------|----------------|

我的配置包含以下内容:

"collectCoverageFrom": [
    "<rootDir>/app_modules/",
    "<rootDir>/src/"
],    

我也试过不带/,带**/*.js,只带*.js,都无济于事。

基于--debug 选项,路径扩展为我想从中收集覆盖信息的路径(不是问题)

那么获得更准确的覆盖率信息有什么魔力?

我能找到的最好的文档来自这个 Github PR:https://github.com/facebook/jest/pull/1349/files


我最终做了:

"collectCoverageFrom": [
    "**/*.js",
    "!webpack.config.js"
],

这只是因为这是默认配置的一部分

"testPathIgnorePatterns": [
    "/node_modules/"
],

但它确实为测试运行增加了大量时间。

【问题讨论】:

    标签: javascript jestjs babel-jest


    【解决方案1】:

    仔细查看您的链接:

    collectCoverageFrom: {
      description: wrap(
        'relative to <rootDir> glob pattern matching the files that coverage ' +
          'info needs to be collected from.'
          ...
    

    您不能使用&lt;rootDir&gt;。试试:

    collectCoverageFrom: [
        "**/app_modules/**",
        "**/src/**"
    ],
    

    【讨论】:

      【解决方案2】:

      这只是添加到您编辑的问题的其他信息:而不是声明第二个数组:

      "testPathIgnorePatterns": [
          "/node_modules/"
      ],
      

      您可以继续使用您的 collectCoverageFrom 数组,方法是将 ! 添加到您不想收集有关覆盖信息的目录中:

      collectCoverageFrom: [
          "!**/node_modules/**"
      ],
      

      【讨论】:

        【解决方案3】:

        您可以使用选项 forceCoverageMatch 强制取消覆盖:['/.ts','/.js']

        【讨论】:

          猜你喜欢
          • 2014-09-09
          • 1970-01-01
          • 2022-01-18
          • 1970-01-01
          • 1970-01-01
          • 2012-06-30
          • 2018-06-03
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多