npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

coverify

v1.5.1

Published

code coverage browserify transform

Downloads

7,295

Readme

coverify

code coverage browserify transform

build status

example

Suppose we have a test.js:

var test = require('tape');
var foo = require('./foo.js');

test('beep boop', function (t) {
    t.plan(1);
    
    foo(function (err, x) {
        if (err) deadCode();
        t.equal(x * 5, 555);
    });
});

and a foo.js:

module.exports = function (cb) {
    var i = 0;
    var iv = setInterval(function () {
        if (i++ === 10 || (false && neverFires())) {
            clearInterval(iv);
            cb(null, 111);
        }
    }, 10);
};

Now with browserify just do:

$ browserify -t coverify example/test.js --bare | node | coverify
TAP version 13
# beep boop
ok 1 should be equal

1..1
# tests 1
# pass  1

# ok

# /home/substack/projects/coverify/example/test.js: line 7, column 16-28

  if (err) deadCode();
           ^^^^^^^^^^^

# /home/substack/projects/coverify/example/foo.js: line 3, column 35-48

  if (i++ === 10 || (false && neverFires())) {
                              ^^^^^^^^^^^^

# coverage: 34/36 (94.4400%)

browserify compiled our test.js file, then testling ran our code in a local headless browser (we also could have used node), and then coverify parsed the test output for code coverage data and printed some nicely formatted results on stderr. Hooray!

and the exit code is non-zero because the coverage wasn't 100%:

$ echo $?
1

If you want to run code coverage for browser tests, you can use the testling command:

$ browserify -t coverify example/test.js | testling | coverify

and the output and exit codes work exactly the same, except the code is running in a browser instead of node.

methods

var coverify = require('coverify')
var parse = require('coverify/parse')

Usually you can just do browserify -t coverify to get code coverage but you can also use the api directly if you want to use this code directly.

var stream = coverify(file, opts={})

Return a transform stream for file that will instrument the input source file using console.log().

To use a different function from console.log(), pass in opts.output.

var stream = parse(cb)

Return a transform stream that accepts test output as input and looks for lines starting with COVERAGE and COVERED to generate a coverage report in cb(err, coverage, counts).

coverage is an object that maps filenames from the bundle files to arrays of coverage data.

counts is an object mapping filenames to objects with expr and total fields for how many expressions were covered and how many expressions were present.

All of the non-/^(COVERAGE|COVERED)\s/ lines are passed through from the input to the output.

Here is some example coverage data that you can generate with coverify --json:

{
  "/home/substack/projects/coverify/example/test.js": [
    {
      "range": [
        158,
        169
      ],
      "lineNum": 7,
      "column": [
        16,
        28
      ],
      "line": "        if (err) deadCode();",
      "code": "deadCode();"
    }
  ],
  "/home/substack/projects/coverify/example/foo.js": [
    {
      "range": [
        123,
        135
      ],
      "lineNum": 3,
      "column": [
        35,
        48
      ],
      "line": "        if (i++ === 10 || (false && neverFires())) {",
      "code": "neverFires()"
    }
  ]
}

usage

usage: coverify OPTIONS

OPTIONS are:

  --json

    Suppress normal output and print json coverage data to stdout.

  -q, --quiet

    Don't print non-coverage input back out to stdout and print coverage
    output to stdout instead of stderr.

  -c, --color

    Use color in the output. Default: true if stdout is a TTY.

  --stdout

    Always print non-coverage input back out to stdout.

  -o FILE, --output FILE

    Print coverage data to FILE. Use "@2" for stderr (the default) and
    "@1" or "-" for stdout.

install

With npm do:

npm install coverify

to get the browserify transform module.

When you compile your tests with browserify you can just do:

browserify -t coverify ...

You will also need the coverify command for parsing the test output:

npm install -g coverify

license

MIT