Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Cake task to output code-coverage using coffeeCoverage mocha and jscoverage
generateServerReport = (server) ->
# 1. Copy server source into a new directory to be instrumented by [`jscoverage`](http://siliconforks.com/jscoverage/)
coverageDir = "#{server}-instrumented"
console.log "copying #{server} source to #{coverageDir} ..."
exec "mkdir #{coverageDir} && cp -r #{server}/* #{coverageDir} && cd #{coverageDir}", (err, stdout, stderr) ->
# 2. Use [`coffeeCoverage`](https://github.com/benbria/coffee-coverage) to instrument `.coffee` files
exclude = excludes[server].join ','
console.log "instrumenting #{coverageDir} excluding #{exclude} ..."
exec "coffeeCoverage --exclude #{exclude} . .", (er, out, err) ->
# 3. Run mocha tests with jscoverage integration sending output to an html file
reportFile = "#{server}-coverage.html"
mochaServerArgs = mochaArgs.slice 0
mochaServerArgs.push testPath[server]
mochaServerArgs.push "> #{reportFile}"
console.log "running #{server} mocha tests ..."
console.log "mocha #{mochaServerArgs.join(' ')}"
exec "mocha #{mochaServerArgs.join(' ')}", (er, out, err) ->
console.log "#{reportFile} generated! WOOT!"
# 4. Remove instrumented code leaving report behind
console.log "removing #{coverageDir} ..."
exec "rm -r #{coverageDir}", (er, out, err) ->
# 5. Signal success
console.log "#{server} coverage reporting process complete"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.