2015-05-19 27 views
22

如何在使用摩卡和instanbul时从覆盖率报告中排除文件夹和文件(按路径)?使用摩卡和伊斯坦布尔时从排除范围中排除文件

我想通过配置来排除,而不是

/*istanbul ignore next*/ 
在每个文件

(詹金斯生成的报告使用)

感谢,

+0

你是如何调用伊斯坦布尔? – JME

+0

你说的是什么意思? –

+0

你如何运行伊斯坦布尔?我问,因为有一个命令行选项来排除文件。 – JME

回答

19

可以忽略匹配的文件使用-x参数一定的规律。

istanbul help cover 

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

如何在配置文件中执行此操作,例如GruntFile? – nottinhill

+0

取决于您用来包装伊斯坦布尔的咕噜库。在'grunt-karma'中,我排除了像这样的文件夹('app/tests'):'{...,preprocessors ['app/{*。js,!(tests)/ **/*。js} '] = ['coverage'],...}' – Blaise

4

我你的情况我会使用以下方法:

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

您只需通过添加多个-x选项排除多个模式。

4

感谢您的建议,

这是解决方案:

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

如果运行istanbul help config你会看到伊斯坦布尔的默认配置。您可以将默认配置复制/粘贴到源树的根目录下的.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: [] 
+0

您确定排除可以将include-all-sources设置为true吗? 仪表: 根:SRC 包括,所有来源:真 详细:真 不包括: “\ * \ */src目录/客户/ \ * \ *”] 报告: DIR: “覆盖” 而我仍然在我的报告中获取客户端文件。 –

相关问题