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

mocha-lcov-reporter

v1.3.0

Published

LCOV reporter for Mocha

Downloads

736,334

Readme

mocha-lcov-reporter

LCOV reporter for Mocha.

LCOV format can be found in this geninfo manpage. This LCOV reporter was built after Sonar Javascript Plugin LCOVParser class.

Usage

The mocha-lcov-reporter is a reporter for mocha. In order to get coverage data, the same instructions are to be followed as for the JSONCov and HTMLCov reporters:

  • Install jscover or node-jscoverage
  • Instrument your library with jscover (or node-jscoverage)
  • Run your tests against your instrumented library and save the output

For example, the following script can be part of your build process (add jscover, mocha, and mocha-lcov-reporter as devDependencies to your package.json file and run npm install):

#!/usr/bin/env bash
rm -rf coverage
rm -rf lib-cov

mkdir coverage

node_modules/.bin/jscover lib lib-cov
mv lib lib-orig
mv lib-cov lib
node_modules/.bin/mocha -R mocha-lcov-reporter > coverage/coverage.lcov
rm -rf lib
mv lib-orig lib

This script instruments your sources (source 'lib', target 'lib-cov'), temporarily replaces your library by the instrumented version, run the tests against the instrumented version of your sources, and undoes the replacing of the original library by the instrumented library.

A safer and better approach is to instrument your library (target 'lib-cov'), and include that directory from your tests directly. Instead of doing a 'require("../lib")' do a 'require("../lib-cov")'. This saves the hassle of replacing directory 'lib' with directory 'lib-cov' and undoing it afterwards. You can use an environment variable to check if the instrumented library should be included or the normal version:

var lib = process.env.JSCOV ? require('../lib-cov') : require('../lib');

And to get the test-coverage, run mocha as follows:

JSCOV=1 mocha -R mocha-lcov-reporter > coverage/coverage.lcov

See the SaXPath project for an example on how to do this.

Incomplete paths in LCOV output

Unfortunately, when the code is instrumented using jscover or node-jscoverage, the output of the reporter will have incomplete paths for the covered files. A quick fix is to update the paths after running the tests with the mocha-lcov-reporter, like so:

# run the tests
JS_COV=1 ./node_modules/.bin/mocha -R mocha-lcov-reporter > coverage/coverage_temp.lcov

# fix the paths
sed 's,SF:,SF:lib/,' coverage/coverage_temp.lcov > coverage/coverage.lcov

The reason this is that jscover runs on the directory you specify (e.g., lib/) and regards that as the root for the project.

Blanket support

Blanket.js can be used as well. After the lcov file, be sure to fix the paths for the covered files. The path will be an URL, having file: as its protocol. Using the same manner as above, the path can be fixed using sed.

Example output

What does LCOV output look like? LCOV is meant to be interpreted by other programs and not meant to be readable by humans. This is an example:

SF:base_unit.js
DA:1,1
DA:4,1
DA:5,155
DA:7,155
DA:8,140
DA:9,140
DA:12,155
DA:13,155
DA:16,1
DA:17,1
DA:20,1
DA:21,9
DA:24,1
DA:25,40
DA:28,1
DA:29,26
DA:32,1
DA:33,7
DA:36,1
DA:37,6
DA:40,1
DA:41,45
DA:44,1
DA:45,52
DA:51,1
DA:52,3
DA:55,1
end_of_record

If you are looking for something human readable, the HTMLCov reporter can be used.