2015-11-11 44 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 

將執行測試,而忽略報告

相關問題