【问题标题】:Excluding files from coverage when using Mocha and Istanbul使用 Mocha 和 Istanbul 时从覆盖范围中排除文件
【发布时间】:2015-07-31 09:52:21
【问题描述】:

使用 mocha 和 instanbul 时,如何从覆盖率报告中排除文件夹和文件(按路径)?

我想通过配置排除而不是

/*istanbul ignore next*/

在每个文件中。

(Jenkins使用的生成报告)

谢谢,

【问题讨论】:

  • 你如何调用伊斯坦布尔?
  • 调用是什么意思?
  • 伊斯坦布尔的运营情况如何?我问是因为有一个命令行选项可以排除文件。
  • 我跑:istanbul cover _mocha -- --recursive -R tap test/ > test.tap && istanbul report clover

标签: node.js jenkins mocha.js istanbul


【解决方案1】:

感谢您的建议,

这是解决方案:

istanbul cover -x '**/config/**'  _mocha -- --recursive -R tap test/ > test.tap && istanbul report clover

【讨论】:

    【解决方案2】:

    如果您运行 istanbul help config,您将看到 istanbul 的默认配置。您可以将默认配置复制/粘贴到源代码树根目录下的 .istanbul.yml 文件中,然后将排除项存储在其中。

    这是我的样子(这样可以很容易地排除许多目录):

    verbose: false
    instrumentation:
        root: .
        extensions:
            - .js
        default-excludes: true
        excludes: ['**/tinymce/**', '**/lib/**', '**/tools/**', '**/build/**']
        embed-source: false
        variable: __coverage__
        compact: true
        preserve-comments: false
        complete-copy: false
        save-baseline: false
        baseline-file: ./coverage/coverage-baseline.json
        include-all-sources: true
        include-pid: false
        es-modules: false
    reporting:
        print: summary
        reports:
            - lcov
        dir: ./tools/coverage
        watermarks:
            statements: [50, 80]
            lines: [50, 80]
            functions: [50, 80]
            branches: [50, 80]
        report-config:
            clover: {file: clover.xml}
            cobertura: {file: cobertura-coverage.xml}
            json: {file: coverage-final.json}
            json-summary: {file: coverage-summary.json}
            lcovonly: {file: lcov.info}
            teamcity: {file: null, blockName: Code Coverage Summary}
            text: {file: null, maxCols: 0}
            text-lcov: {file: lcov.info}
            text-summary: {file: null}
    hooks:
        hook-run-in-context: false
        post-require-hook: null
        handle-sigint: false
    check:
        global:
            statements: 0
            lines: 0
            branches: 0
            functions: 0
            excludes: []
        each:
            statements: 0
            lines: 0
            branches: 0
            functions: 0
            excludes: []
    

    【讨论】:

    • 您确定排除将 include-all-sources 设置为 true 的作品吗?仪器:根:src include-all-sources:true 详细:true 排除:["**/src/client/**"] 报告:dir:"coverage" 我仍然在我的报告中获取客户端文件。
    【解决方案3】:

    您可以使用-x 参数忽略匹配特定模式的文件。

     istanbul help cover
    
     ...
     -x <exclude-pattern> [-x <exclude-pattern>]
            one or more fileset patterns e.g. "**/vendor/**"
     ...
    

    【讨论】:

    • 如何在配置文件中执行此操作,例如GruntFile?
    • 取决于你用来包装伊斯坦布尔的 grunt 库。在grunt-karma 中,我排除了这样的文件夹(app/tests):{..., preprocessors['app/{*.js,!(tests)/**/*.js}'] = ['coverage'], ...}
    【解决方案4】:

    我会使用以下内容:

    istanbul -x "**/pattern/to/exclude/**" cover _mocha -- --recursive -R tap test/ > test.tap && istanbul report clover –  snoof 9 hours ago 
    

    您可以通过添加多个-x 选项来排除多个模式。

    【讨论】:

      猜你喜欢
      • 2014-04-26
      • 1970-01-01
      • 2015-08-12
      • 2018-12-04
      • 2021-12-29
      • 2022-10-21
      • 2021-02-13
      • 2018-07-27
      • 2020-10-31
      相关资源
      最近更新 更多