Skip to content

Instantly share code, notes, and snippets.

@Fresheyeball
Created July 25, 2013 23:15
Show Gist options
  • Save Fresheyeball/6084675 to your computer and use it in GitHub Desktop.
Save Fresheyeball/6084675 to your computer and use it in GitHub Desktop.
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