Code Monkey home page Code Monkey logo

jcov's Introduction

JCov

Coverage reports on your Javascript tests!

Supports:

  • Jasmine

  • JSpec

  • Any other Javascript with a custom runner file.

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

jcov run

Runs the tests. Also the default command (just type ‘jcov’)

jcov check

Check the configuration.

jcov help

Show help docs.

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.

  • The JCov object

    • JCov.tests: An Array of tests to execute (the list of everything from your test directory filtered by the –test switch)

    • JCov.config: The configuration loaded from jcov.yaml (see above)

    • JCov.options: Passed in command line options (see above)

  • Global Methods

    • print(): Print to the console.

    • println(): Print to the console with a carriage return.

    • load(): load and execute the given file.

    • readFile(): load file and return it as a string.

    • putc(): Print a single character to the console.

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.

Maintainers

License

Copyright © YP Intellectual Property, LLC 2012. JCov is licensed under the MIT License.

jcov's People

Contributors

jmervine avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

tamimsaeedi

jcov's Issues

Coverage report shows the wrong line covered in a few cases

Function assignments not in any block:

var foo = function () {
  // stuff
};

And anonymous function arguments:

foo(function () {
  // stuff
});

Show coverage on the last line of the function and not the first.
Coverage calculation is correct, it's just not highlighted properly.

invalid syntax javascript is not caught correctly during coverage calculation

If a javascript file with invalid syntax is not loaded by tests, but it loaded at the end for coverage calculations, a cryptic error message is returned from rkelly:

/Users/dmcinnes/.rvm/gems/ruby-1.9.2-p320/gems/rkelly-1.0.7/lib/rkelly/visitors/visitor.rb:38:in accept': undefined methodaccept' for nil:NilClass (NoMethodError)

jcov check shows weird output with command line switches

We have duplicate-ish lines:
dump: false
:dump: true

$ jcov check --dump
Using configuration file: ./jcov.yml

---
test_directory: tests
source_directory: javascripts
test_runner: jasmine/runner.js
error_field: results
report_output_directory: jcov
verbose: false
color: true
coverage: true
report: false
dump: false
:dump: true
ignore:
- jasmine
- tests

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.