Integrate istanbul for test coverage
This commit is contained in:
committed by
Marc Jansen
parent
6d55e4aa99
commit
7c9795ba35
2
.gitignore
vendored
2
.gitignore
vendored
@@ -5,3 +5,5 @@
|
||||
/examples/example-list.xml
|
||||
/node_modules/
|
||||
/dist/
|
||||
/src_instrumented/
|
||||
/coverage/
|
||||
|
||||
@@ -6,3 +6,5 @@ before_script:
|
||||
- "rm src/ol/renderer/webgl/*shader.js"
|
||||
|
||||
script: "./build.py ci"
|
||||
|
||||
after_success: "npm run test-coverage"
|
||||
|
||||
@@ -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": {
|
||||
@@ -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",
|
||||
|
||||
@@ -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);
|
||||
|
||||
15
test/phantom_hooks.js
Normal file
15
test/phantom_hooks.js
Normal file
@@ -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');
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user