Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Support outputting HTML code coverage from PhantomJS #127

Closed
wants to merge 5 commits into from

Conversation

maxbeatty
Copy link

I came up with a way to generate HTML code coverage reports from a coverage object in PhantomJS. I'll admit it feels like a hack, but it works so I thought I'd present it for feedback and consideration since I know it's been a long time ask (#44).

Background: We write CoffeeScript and use grunt-mocha to run our client tests. We use coffee-coverage to generate JSCoverage style instrumentation which Mocha can use to produce really nice HTML coverage reports.

Problem: The global coverage object is in PhantomJS and not available until Mocha's run has ended.

Solution:

  1. Don't end the PhantomJS process when Mocha initially ends
  2. Alert the coverage data (properly JSONified) and listen to the event to assign the global in Node. This global is what Mocha's JSONCov reporter uses (which is what HTMLCov) uses.
  3. Fire another mocha.end event to actually end the process which will emit to the reporter which can now write it's HTML file

Potential Issues:

I know this reintroduces hijacking process.stdout which could cause backwards compatibility issues, but, HTMLCov, like XUnit, now uses it

I did my best to provide tests. Happy to add more. Would appreciate any feedback!

@maxbeatty maxbeatty closed this Jun 20, 2016
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant