Last active
December 29, 2015 08:38
-
-
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…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/' | |
} | |
} | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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