第一显示代码,以后我会解释,
grunt.initConfig({
browserify: {
// build specs using browserify
specs: {
src: ["spec/**/*Spec.js"],
dest: "spec/build/specs.js",
options: {
debug: true
}
},
// build source files using browserify and browserify-istanbul
dev: {
options: {
debug: true,
browserifyOptions: {
standalone: 'abc'
},
transform: [['browserify-istanbul', {
ignore: ['**/node_modules/**'], // ignore third party libs
defaultIgnore: true
}]]
},
src: ['abc.js'],
dest: 'dist/abc.js'
}
},
connect: {
server: {
options: {
port: 7000
}
}
},
// test using jasmine, generate coverage report using istanbul
jasmine: {
coverage: {
src: ['dist/abc.js'],
options: {
junit: {
path: 'bin/junit'
},
host: 'http://localhost:7000/',
specs: 'spec/build/specs.js',
keepRunner: true,
summary: true,
template: require('grunt-template-jasmine-istanbul'),
templateOptions: {
replace: false, // *** this option is very important
coverage: 'bin/coverage/coverage.json',
report: [
{
type: 'html',
options: {
dir: 'spec/coverage/html'
}
}]
}
}
}
}
grunt.registerTask('specs', ['browserify:specs', 'browserify:dev', 'connect', 'jasmine']);
产生伊斯坦布尔覆盖报告的步骤可归纳为三条:
- 仪器代码
- 运行测试
- 生成覆盖率报告
在我们的解决方案中,我们使用在步骤1中,grunt-contrib-jasmine
browerify-istanbul
和runt-template-jasmine-istanbul
在步骤2和3
browserify-istanbul
将让browserify建设步骤中,您的仪器代码,通过这种方式,我们可以很容易忽略的第三方库。但grunt-template-jasmine-istanbul
将再次测试代码。为避免这种情况,您可以在选项中将replace
设置为false
。
参考文献:
- Istanbul steps
- broswerify-istanbul
- grunt-contrib-jasmine
- grunt-template-jasmine-istanbul -
replace
选项
你弄清楚这一个?它目前是在守卫项目中工作吗? –
这个问题在这里出现了3年的答案是什么意思... – QueueHammer