View on GitHub

JCov

The Lightweight, Headless Javascript Test Runner that Reports Code Coverage

Download this project as a .zip file Download this project as a tar.gz file

Benefits:

Installation

gem install jcov

Getting Started

There are both JSpec and Jasmine example projects in the examples directory -- these are a good place to start.

You will need at least a Javascript runner file for JCov to work.

Command Line

Global Options:

-c, --config FILE    Specify a configuration file to use 
-h, --help           Display help documentation 
-v, --version        Display version information 
-t, --trace          Display backtrace when an error occurs 

Run Options:

-t, --test REGEX     Limit the tests to only the ones that match the regular expression 
--verbose            Verbose test execution 
--[no-]color         Enable/Disable color output -- default enabled when executed from the command-line 
--[no-]coverage      Enable/Disable coverage output -- default enabled 
--report             Report test coverage 

Running with the --report switch will output an HTML coverage report that shows line-by-line coverage.

If your testing framework supports color output your runner file must pass the color boolean value from the JCov object (JCov.options.color) to the framework (see the Jasmine and JCov examples).

The --verbose switch is another option your framework must support (see the JCov example).

Run will also return with a non-zero code when the tests don't pass so it can be easily integrated into continuous integration suites.

jcov.yaml

Configure JCov by creating a jcov.yaml file. JCov also has some "intelligent" defaults and you can see the how the jcov.yaml file works with those defaults using the check command to output the combined configuration:

jcov check

JCov will look for the jcov.yaml file in a config directory and the current directory.

Example jcov check output:

Using configuration file: ./jcov.yml
--- 
test_directory: tests
source_directory: javascripts
test_runner: jasmine/runner.js
error_field: results
report_output_directory: jcov
ignore: 
- jasmine
- tests

Configuration Keys

test_directory: Where the test files are kept. (Default test/javascripts) source_directory: Where the source files are kept. (Default public/javascripts) test_runner: The Javascript file JCov executes to run your tests. (Default test/javascripts/runner.js) error_field: The Javascript variable that JCov examines to find out how many failures occurred while running the test suite. (Default error_count) report_output_directory: Where the HTML coverage reports will be written. (Default jcov)

Runner Files

You will need a Javascript runner file to tell JCov how to run your tests. This is usually a simple script that loads your testing framework, the source and test files, and calls whatever execute() method your framework needs. After the tests are run it needs to This is intentionally left open to make it easier for JCov to support arbitrary frameworks.

See the examples directory for examples.

Runner API

JCov provides some methods and a data object to the runner file.

Headless Browser Testing

Headless browser testing can be supported with something like the env.js project which mimics the browser/DOM interface in a pure Javascript way.

License

Copyright (c) YP Intellectual Property, LLC 2012. JCov is licensed under the MIT License.