Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running JSCoverage with Jasmine

A little new to Javascript coding, so please bear with me.

I read through the following link jasmine with jscoverage automated testing

However, since I don't have a Ruby project, it didn't seem to be what I wanted.

Here are the steps I executed:

  1. Copy my js file to be tested to a directory 'input'
  2. Run the following command 'jscoverage input output'
  3. Copy my spec and src folders for Jasmine as well as SpecRunner.html into 'output'
  4. Copy the instrumented source file into src
  5. Open jscoverage.html in Chrome
  6. Open SpecRunner.html in the 'Browser' tab

At this point, the browser page displays my Jasmine tests. However, the 'Summary' page shows 0 files tested and the 'Source' tab is grayed out.

I know I messed up somewhere but am not sure where. Please help me out. Thanks!

like image 536
Chetter Hummin Avatar asked Mar 05 '12 15:03

Chetter Hummin


2 Answers

The correct steps to be followed are as follows:

  • Copy the jasmine files (spec and src folders for Jasmine as well as SpecRunner.html) to a directory 'input'
  • Run the following command 'jscoverage input output'
  • Open jscoverage.html in Firefox (Chrome will not show the individual files that were tested)
  • Open SpecRunner.html in the 'Browser' tab

This approach has the drawback that all the files including jasmine related js show up. But you can select your js file that's being tested and just look at the code coverage for it.

like image 138
Chetter Hummin Avatar answered Sep 30 '22 17:09

Chetter Hummin


The standard jscoverage approach is to instrument the entire codebase you want to get coverage on, then run a suite a tests and generate a report. This approach is a bit heavy handed since a codebase only needs a coverage report on a set frequency. Unlike CI tests, how often does the dev really need to know the coverage percentage change, weekly?

The node.js jscoverage project uses the same 'instrumentation' approach as the larger jscoverage project, but it can be run from the node CLI on an individual file, or from code on one or more files, as they are called from the tests themselves. In place of separate step to 'instrument' a batch of files, the jscoverage (confusing name), 'instruments' at test runtime.

I have been working towards a pattern that allows jasmine tests and testing in either a browser or at the CLI using the same source code setup and test configuration. Still beta. The jasmine just-in-time 'instrumentation' is not done yet.

https://github.com/d1b1/jasmine-jscoverage

like image 28
d1b1 Avatar answered Sep 30 '22 17:09

d1b1