Skip to content

NeoPhi/jscoverage-reporter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Recommendation

I highly recommend switching to using Istanbul for code coverage. With the simple line "test": "istanbul test jasmine-node -- test" in your package.json scripts block you get optional code coverage integrated with jasmine, without the need to run a separate instrumentation step. Istanbul includes detailed branch and function metrics which JSCoverage does not.

jscoverage-reporter - JSCoverage Report for Jasmine

A Jasmine reporter that will capture code coverage metrics generated by JSCoverage. Works well with jasmine-node and PhantomJS.

At this point the reporter requires a little setup to use as it assumes you are already using jasmine-node for testing. A simple wrapper script described below makes it easy to add this reporter to an out of the box jasmine-node install.

Installation

npm install jscoverage-reporter

You will also need a version of JSCoverage installed to generate the covered files. My preference is to download and install from http://siliconforks.com/jscoverage/ as we also test non node.js code.

Usage

Core Syntax

require('jscoverage-reporter');
jasmine.getEnv().addReporter(new jasmine.JSCoverageReporter('./reports'));

jasmine-node wrapper

Create a file called coverage.js:

require('jasmine-node');
require('jscoverage-reporter');
var jasmineEnv = jasmine.getEnv();
// Adjust output directory as needed
jasmineEnv.addReporter(new jasmine.JSCoverageReporter('./reports'));
require('./node_modules/jasmine-node/lib/jasmine-node/cli.js');

After running JSCoverage on the code to test:

npm install jasmine-node
node coverage.js <jasmine-node options>

JSCoverage wrapper

To run a single command that executes JSCoverage and runs the tests, an example can be found at tools/coverage.js.

In package.json you can then define your test script as:

"test": "node tools/coverage --junitreport build/test",

Viewing the Report

Two files jscoverage.json and coverage.xml will be produced. The jscoverage.json file can be used with the modified JSCoverage template to view the coverage. As JSCoverage complains about file based paths, to view the data a simple node.js based HTTP report server can be found in tools/report.js. The coverage.xml is suitable for Emma report tracking such as with Emma Jenkins Plugin.


Copyright (c) 2012 Daniel Rinehart. This software is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published