10

Had been looking at the jsunit and jcoverage demos here (click on coverage report link. Open this in a new tab).

I was wondering if any one had done anything similar with Jasmine and JSCoverage ? I'm a little unsure on how to proceed.

[EDIT] I am wondering if there is something I can do with a jasmine reporter. My Jasmine "hello world" example makes reference to a TrivialReporter. Maybe this can be extended ??

[EDIT] I've wired up js-test-runner with jasmine right now. Now If I could think of a way to get coverage ??

wmitchell
  • 5,665
  • 10
  • 37
  • 62

2 Answers2

4

If you're working on a ruby project and using jasmine via jasmine-gem, I have a patch that adds jscoverage support[1].

If you're using bundler, you can use this version of jasmine with the following command in your Gemfile:

  gem 'jasmine',
    :git        => 'git://github.com/hjdivad/jasmine-gem',
    :submodules => true,
    :branch     => 'jscoverage'

Make sure you've downloaded jscoverage and it's in your $PATH.

You can then add the following to jasmine.yml

coverage:
  enabled:    true
  encoding:   utf-8
  tmp_dir:    tmp
  report_dir: public/coverage
  skip_paths:
    - public/javascripts/vendor

If this works for you, you may want to speak up on the pull request[2] to get it, or some variation, into jasmine-gem proper.

hjdivad
  • 388
  • 2
  • 10
  • 1
    If you're not working on a ruby project, you should be able to take a look at the two commits in the pull request and extract the stuff you need for a standalone js project. 1. copy jscoverage.js and add it as a helper. 2. When running tests i. run jscoverage to instrument your javascript and put the instrumented files into some directory. ii. Have jasmine run against this directory iii. After the tests complete, save the results of `jasmine.coverageReport()` as `jscoverage.json` iv. modify the generated `jscoverage.js`, appending `jscoverage_isReport = true;` at the bottom. – hjdivad Jun 01 '11 at 21:38
1

If you're not using the jasmine-gem, or don't want to have to run a server to check coverage, I've written a gem that pulls together jscoverage and jasmine. It can run as a rake task in your CI builds.

It can be found here: https://github.com/firstbanco/jasmine-coverage

Install it, then just run

bundle exec rake jasmine:coverage

You're done.

EDIT: As the author of jasmine-coverage, I feel duty bound to to tell you about a better alternative: teaspoon. It requires more setup, but also allows running in the browser so you can use the Chrome debugger.

hlascelles
  • 1,061
  • 11
  • 15