Reporting istanbul code coverage for jasmine tests run (via grunt) in a browser package in phantomjs

The title says that everything is real. Despite trawling on the Internet, I did not find a single example of a solution to this problem.

Here are a few misses

Here is my runtime code https://github.com/wheresrhys/on-guard/tree/browserify (note that the "browserify" branch - Gruntfile.js is a bit of a mess, but it will clean it up soon). My initial research using console.log shows that bundle.src.js somehow loads on the page, but when the tests are executed (and passed!), The code in bundle.src.js does not start, so I have a feeling that it may be a problem with an alias ... although one that is limited to phantoms, when I open the specrunner in chrome, the code runs.

+7
gruntjs phantomjs browserify istanbul
source share
1 answer

I am using grunt-browserify + browserify-istanbul + grunt-contrib-jasmine + grunt-template-jasmine-istanbul as a solution. This solution also has excluded third-party libraries when creating source files using browserify .

Show the code first, I will explain later

 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']); 

The steps for generating an Istanbul coverage report can be summarized in three:

  • Device code
  • Launch test
  • Coverage Report

In our solution, we use browerify-istanbul in steps 1, grunt-contrib-jasmine and runt-template-jasmine-istanbul in steps 2 and 3.

browserify-istanbul will allow you to type code in the browser at the construction stage, so we can easily ignore third-party libraries. But grunt-template-jasmine-istanbul will program the code again. To avoid this, you can set replace to false in the options.

works:

0
source share

All Articles