我希望能够使用html-cov报告器,即使测试正在通过,所有的覆盖率值都是0。
我使用Grunt来创建仪表化代码,使用mocha来进行测试,这是我的grunt文件
module.exports = (grunt) ->
release = (type = 'develop') ->
switch type
when 'master'
grunt.task.run('release')
else
grunt.config.set('release',
options:
tag : false
pushTags: false
npm : false
)
grunt.task.run('release')
return
grunt.initConfig
pkg: grunt.file.readJSON 'package.json'
covervars:
base : 'tests/lib-cov'
build : '<%=covervars.base %>/build'
reports: '<%=covervars.base %>/reports'
watch:
coffee:
files: ['./src/**/*.coffee', './tests/**/*.spec.coffee']
tasks: ['build']
coffee:
compile:
options:
bare: true
expand : true
cwd : 'src'
src : '**/*.coffee'
dest : 'lib'
ext : '.js'
clean:
coverage: [
'<%=covervars.base %>/*'
]
instrument:
files : './lib/**/*.js'
options:
basePath: '<%=covervars.build %>/'
reloadTasks:
rootPath: '<%=covervars.build %>/lib/'
storeCoverage:
options:
dir: '<%=covervars.reports %>/'
makeReport:
src : '<%=covervars.reports %>/**/*.json'
options:
type : 'lcov',
dir : '<%=covervars.reports %>',
print: 'detail'
cafemocha:
test:
src : './tests/server/**/*.spec.coffee'
options:
require : ['./tests/common.coffee','./lib/']
ignoreLeaks: false
checkLeaks : true
colors : true
ui : 'bdd',
reporter : 'dot'
coverage:
src : './tests/server/**/*.spec.coffee'
options:
require : ['./tests/common.coffee','./<%=covervars.build %>/lib/']
globals : ['__coverage__']
ignoreLeaks: false
colors : true
ui : 'bdd',
reporter : 'spec'
coverage :
output: 'tests/lib-cov/coverage.html'
karma:
options :
configFile: 'tests/client/karma.conf.js'
unit :
browsers : ['Firefox']
singleRun: true
continuous:
browsers : ['Firefox', 'Chrome']
singleRun: false
grunt.loadNpmTasks 'grunt-release'
grunt.loadNpmTasks 'grunt-karma'
grunt.loadNpmTasks 'grunt-contrib-watch'
grunt.loadNpmTasks 'grunt-contrib-coffee'
grunt.loadNpmTasks 'grunt-cafe-mocha'
grunt.loadNpmTasks 'grunt-contrib-clean'
grunt.loadNpmTasks 'grunt-istanbul'
grunt.registerTask 'test', ['cafemocha:test']
grunt.registerTask 'cover', [
'coffee', 'clean',
'instrument',
#'reloadTasks',
'cafemocha:coverage',
#'storeCoverage', 'makeReport'
]
grunt.registerTask 'test:continuous', ['karma:continuous']
grunt.registerTask 'build', ['coffee', 'test']
grunt.registerTask 'releaseit', release
grunt.registerTask 'default', ['watch']插入指令的代码如下所示:http://pastebin.com/3wAt5VZT
伊斯坦布尔lcov.info文件的一部分(已正确生成)
TN:
SF:./lib/index.js
FNF:0
FNH:0
DA:1,1
DA:2,1
DA:10,1
DA:12,1
DA:14,1
DA:16,1
DA:18,1
DA:20,1
DA:22,1
DA:24,1
LF:10
LH:10
BRF:0
BRH:0
end_of_recordmocha似乎没有获得测试覆盖率,但如果我启用storeCoverage和makeReport,instabul会显示正确的文件数和每个文件中使用的代码百分比。mocha只能使用jscoverage的覆盖范围吗?如果不是,我是不是遗漏了什么步骤?
发布于 2014-05-19 18:36:31
我创建了我自己的grunt插件就可以做到这一点。它执行mocha并通过stdin将其即时传递给伊斯坦布尔。https://github.com/pocesar/grunt-mocha-istanbul,可通过npm npm install grunt-mocha-istanbul安装
它有一个名为coverage的gruntjs事件,使您能够使用从插入指令的代码生成的lcov.info
发布于 2013-08-04 06:34:45
我使用BlanketJS而不是伊斯坦布尔实现了这一点。Blanket不是创建源文件的单独仪表化副本,而是实时、动态地评估覆盖率。
为了让Blanket能够与Mocha和Grunt一起工作,我最终编写了自己的Grunt插件。该插件支持“强制执行”最小阈值,否则Grunt任务将失败。
我写了一篇博文,所有细节都在这里:http://www.geekdave.com/2013/08/02/automated-code-coverage-enforcement-for-mocha-using-grunt-and-blanket/
https://stackoverflow.com/questions/17260505
复制相似问题