Giter Club home page Giter Club logo

jscovreporter's Introduction

JSCovReporter

This is a testing framework agnostic in-browser Javascript coverage reporter. It works with CoverJS instrumented code. The UX and appearance of the report mimic Mocha's HTMLCov runner which only works with nodejs. JSCovReporter should work with any testing framework such as QUnit, Jasmine, Mocha, Buster or anything you use.

The files included here are borrowed from Mocha project and have been slightly modified to work with the HTML produced by this reporter and work well with Mocha's HTML runner, currently the only Mocha in-browser runner. This is what Mocha looks like when used with JSCovRepoter:

Setup

  • JSCovRepoter depends on Backbone (Tested with version 0.9.2) and Underscore (or Lodash). So make sure you include those in your HTML test runner file.

  • Download from this repository and include reporter.js, reporter.css and JSCovReporter.js files in your runner.

  • Your test runner body will need to contain this DOM, besides the one that your testing framework needs. Most likely you want these after the div for your framework, so that coverage appears after testing results:

    <div id="coverage"></div>
    <div id="menu"></div>

Usage

Instrument your Javascript code

You will first need to instrument your javascript code using CoverJS. Install it using nodejs npm package manager:

npm install coverjs

Add coverjs bin to your PATH and then do:

coverjs mylibrary.js --output instrumented

This will create an instrumenteddirectory, containing an instrumented mylibrary.js, these are the files you have to link in your HTML test runner.

Generate a report

When the testing suite is done, just create a JSCovReporter instance passing it CoverJS' global coverObject as coverObject argument:

    if (typeof window.__$coverObject !== 'undefined') {
        var reporter = new JSCovReporter({ coverObject: window.__$coverObject });
    }

In this case we are making sure coverObject exists, this way your runner will work with or without instrumented code.

Mocha usage example

For example in Mocha you can easily plug it in using run callback:

    mocha.run(function () {
        if (typeof window.__$coverObject !== 'undefined') {
            var reporter = new JSCovReporter({ coverObject: window.__$coverObject });
        }
    });

jscovreporter's People

Contributors

maraujop avatar

Watchers

 avatar

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.