Skip to content

Commit

Permalink
Integrate istanbul for test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Bart van den Eijnden authored and marcjansen committed Apr 2, 2015
1 parent 6d55e4a commit 7c9795b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
/examples/example-list.xml
/node_modules/
/dist/
/src_instrumented/
/coverage/
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ before_script:
- "rm src/ol/renderer/webgl/*shader.js"

script: "./build.py ci"

after_success: "npm run test-coverage"
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"install": "node tasks/install.js",
"postinstall": "closure-util update",
"start": "node tasks/serve.js",
"test": "node tasks/test.js"
"test": "node tasks/test.js",
"test-coverage": "istanbul instrument src -o src_instrumented && mv src src_old && mv src_instrumented src && istanbul cover npm test istanbul && mv src src_instrumented && mv src_old src && istanbul report --root coverage lcov"
},
"main": "dist/ol.js",
"repository": {
Expand All @@ -38,6 +39,7 @@
"devDependencies": {
"clean-css": "2.2.16",
"expect.js": "0.3.1",
"istanbul": "^0.3.13",
"jquery": "2.1.1",
"jshint": "2.5.6",
"mocha": "1.21.5",
Expand Down
5 changes: 5 additions & 0 deletions tasks/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ serve.createServer(function(err, server) {
url + '/test/index.html'
];

if (process.argv.length > 2 && process.argv[2] === 'istanbul') {
args.push('spec', '{"hooks": "' +
path.join(__dirname, '../test/phantom_hooks.js') + '"}');
}

var child = spawn(phantomjs.path, args, {stdio: 'inherit'});
child.on('exit', function(code) {
process.exit(code);
Expand Down
15 changes: 15 additions & 0 deletions test/phantom_hooks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
afterEnd: function(runner) {
var fs = require('fs');
var coverage = runner.page.evaluate(function() {
return window.__coverage__;
});

if (coverage) {
console.log('Writing coverage to coverage/coverage.json');
fs.write('coverage/coverage.json', JSON.stringify(coverage), 'w');
} else {
console.log('No coverage data generated');
}
}
};

0 comments on commit 7c9795b

Please sign in to comment.