我希望能够使用html-cov
记者,即使测试通过了,所有的覆盖率值都是 0。
我使用 Grunt,Istanbul 来创建检测代码和 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
istanbul 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_record
mocha 似乎没有获得测试覆盖率,但如果我启用storeCoverage
and makeReport
,instabul 会向我显示正确的文件数和每个文件中使用的代码百分比。mocha 只能使用jscoverage的覆盖范围吗?如果没有,我是否缺少任何步骤?