Skip to content

Instantly share code, notes, and snippets.

@webpro
Last active December 29, 2015 08:38
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webpro/7644285 to your computer and use it in GitHub Desktop.
Save webpro/7644285 to your computer and use it in GitHub Desktop.
* Gruntfile.js contains configuration for the `testem` task, but could also be in a `testem.json` file. * If you have Istanbul installed as a local dependency, just replace `istanbul` with `node_modules/istanbul/lib/cli.js`. * The collect-coverage.js is some local server that simply saves any data it receives to `coverage.json`. Within the Teste…
var server = require('http').createServer(function(req, res) {
var body = '';
req.on('data', function(chunk) {
body += chunk;
});
req.on('end', function() {
require('fs').writeFile('coverage/data/coverage.json', body, function() {
res.writeHead(200);
res.end();
server.close();
});
});
});
module.exports = function(config, data, done) {
server.listen(8181);
done();
}
testem: {
coverage: {
options: {
test_page: 'test/index.html#testem,coverage',
parallel: 2,
launch_in_ci: ['PhantomJS'],
on_start: require('./collect-coverage'),
before_tests: 'istanbul instrument src/ --complete-copy --output src_instrumented/',
after_tests: 'istanbul report --root coverage/data/ --dir coverage/report/'
}
}
},
<script>
if (location.hash.indexOf('coverage') > -1) {
require.config({
paths: {
'src': 'src_instrumented'
}
});
jasmineEnv.addReporter(new function(){
this.jasmineDone = function() {
$.post('http://localhost:8181/collect', JSON.stringify(window.__coverage__));
}
});
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment