生成伊斯坦布尔代码覆盖率报告为茉莉花testing运行(通过咕噜)phantomjs的一个browserify包
标题说明了一切。 尽pipe通过networking浏览,我还没有find一个解决这个问题的例子。
这里有一些错过
- https://github.com/amitayd/grunt-browserify-jasmine-node-example – grunt,browserify和jasmine
- https://github.com/gotwarlost/istanbul/issues/59#issuecomment-18799734 – browserify和伊斯坦布尔
这里是我正在进行的代码https://github.com/wheresrhys/on-guard/tree/browserify (注意这是“browserify”分支 – Gruntfile.js是一个混乱,但将很快整理)。 我最初的调查使用console.log
表明,不知何故bundle.src.js
被加载到页面中,但是当testing运行(并通过!) bundle.src.js
的代码没有运行,所以我有一个感觉这可能是一个混淆的问题…虽然一个仅限于phantomjs,因为当我打开铬的specrunner代码正在运行。
我正在使用grunt-browserify
+ browserify-istanbul
+ grunt-contrib-jasmine
+ grunt-template-jasmine-istanbul
作为解决scheme。 使用browserify
构build源文件时,此解决scheme也排除了第三方库 。
首先显示代码,稍后我会解释,
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']);
生成伊斯坦布尔报道的步骤可以归结为三个:
- 仪器代码
- 运行testing
- 生成覆盖率报告
在我们的解决scheme中,我们在步骤1中使用了browerify-istanbul
,在步骤2和3中使用了grunt-contrib-jasmine
和runt-template-jasmine-istanbul
。
browserify-istanbul
会让你在browserify构build步骤中使用工具代码,这样我们可以轻松地忽略第三方库。 但是, grunt-template-jasmine-istanbul
将会重新编写代码。 为了避免这种情况,您可以在选项中将replace
设置为false
。
参考文献:
- 伊斯坦布尔步
- broswerify伊斯坦布尔
- 咕噜-的contrib -茉莉
- grunt-template-jasmine-istanbul –
replace
选项