2015-11-11 47 views
0

我正在开发一个nodeJS +角度堆叠应用程序。为了生成后端的代码覆盖率报告,我使用了istanbul和mocha。但是,覆盖率报告显示的数字不正确。如何配置伊斯坦布尔覆盖范围报告以排除某些源?

如果我运行istanbul cover _mocha --print detail /path/to/tests*我得到全面覆盖(但只在测试规范要求的文件上)。另一方面,如果我运行istanbul cover _mocha --print detail --include-all-sources /path/to/tests*伊斯坦布尔也检查前端代码的测试覆盖率(角度,我使用karma/jasmine单独测试)。

如何运行istanbul,因此它只包含后端源文件?

回答

-1

你有没有你的后端代码和你的前端代码在不同的目录?例如/test/api/test/dashboard或其他。如果你把你的代码分开,你可以告诉在伊斯坦布尔的一次像这样在每个报告:

istanbul cover _mocha test/api/**/*.js

有道理?这会为你工作吗?

让我知道。

+0

我的项目的结构更像 server/* public/js* (angular) test/mocha/* (backend tests) test/jasmine/* (angular tests) 位于dist/index.js上覆盖文件 – simonas88

0

我也遇到过类似的情况,因此认为如果它可以帮助某人,尽管它是一个旧的职位,值得分享。 伊斯坦布尔以当前目录(。)作为覆盖目录运行命令时。为了只包含一个特定的目录到覆盖范围,使用"--root /dir/"选项。这将只为该目录中的文件生成覆盖率报告。

0

据伊斯坦布尔帮助盖输出

$ ./node_modules/.bin/istanbul help cover 

Usage: istanbul cover [<options>] <executable-js-file-or-command> [--<arguments-to-jsfile>] 

Options are: 

    --config <path-to-config> 
      the configuration file to use, defaults to .istanbul.yml 

    --root <path> 
      the root path to look for files to instrument, defaults to . 

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

    -i <include-pattern> [-i <include-pattern>] 
      one or more glob patterns e.g. "**/*.js" 

    --[no-]default-excludes 
      apply default excludes [ **/node_modules/**, **/test/**, 
      **/tests/** ], defaults to true 

    --hook-run-in-context 
      hook vm.runInThisContext in addition to require (supports 
      RequireJS), defaults to false 

    --post-require-hook <file> | <module> 
      JS module that exports a function for post-require processing 

    --report <format> [--report <format>] 
      report format, defaults to lcov (= lcov.info + HTML) 

    --dir <report-dir> 
      report directory, defaults to ./coverage 

    --print <type> 
      type of report to print to console, one of summary (default), 
      detail, both or none 

    --verbose, -v 
      verbose mode 

    --[no-]preserve-comments 
      remove/preserve comments in the output, defaults to false 

    --include-all-sources 
      instrument all unused sources after running tests, defaults to 
      false 

    --[no-]include-pid 
      include PID in output coverage filename 

你应该用-X从覆盖报告中排除某些文件。即:

$ ./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha test -X dist/index.js 

将执行测试,而忽略报告

相关问题