Closed stevetarver closed 9 years ago
Of course, after I create the issue, I figure out a solution. This may be an interesting scenario you would want to document.
Scenario: Backbone SPA with browserified coffee built with grunt: How to collect client side (html page) istanbul test coverage on mocha tests linked to coffee files?
Use browserify-coffee-coverage with istanbul instrumentor
browserify:
test:
src: "#{spec}/spec-main.coffee"
dest: "#{testbuild}/js/spec-main.js"
options:
transform: [['browserify-coffee-coverage', {instrumentor: 'istanbul'}], 'jadeify']
debug: true
Use grunt-mocha-pahtom-istanbul to run the tests and generate reports
mocha:
test:
src: "#{testbuild}/index.html"
options:
run: true
reporter: 'Spec'
log: true
logErrors: true
coverage:
lcovReport: 'coverage/'
Really simple once you get the right collection of packages. It is amazing how many kludgy, inelegant solutions there are out there.
Thanks for the great code.
Created an example project showing how to hook all of this together here: https://github.com/stevetarver/example-grunt-browserify-coffee-coverage
Thanks for all the info, Steve. Re: 'It is amazing how many kludgy, inelegant solutions there are out there.', yeah... I feel like all of this should be much, much easier to make work.
Big fan of coffee-coverage, thanks. Have a backbone SPA grunt-mocha/grunt-mocha-phantomjs project that has an html page including all tests via script tag for the browserify-coffee-coverage'd tests. Bundle looks good but can't wrap my head around how to get the mocha run's coverage info out of the page. Alternative: browserify-istanbul writes this to a window.coverage variable and expects a web hook to write the contents out to a file for later istanbul report. This cannot generate an html coverage report because the coverage info references coffee files, but they don't match the transpiled javascript line numbers (other reports work OK). I would love a more CoffeeScripty solution and have a little time to spend on it... any pointers?