separated-coverage

Coverage toolkit designed to collect coverage information separately for each test.

Usage no npm install needed!

<script type="module">
  import separatedCoverage from 'https://cdn.skypack.dev/separated-coverage';
</script>

README

separated-coverage

Build Status Coverage Status Dependency Status devDependency Status

Coverage toolkit designed to collect coverage information separately for each test.

Unlike most coverage tools, separated-coverage keeps connection between source file and its test file. For each source file coverage is beeing computed only when its tests are running. This ensures you have correct test coverage for each file beeing tested.

For example you have file source.js and its test: source.test.js. separated-coverage collects coverage for source.js only when source.test.js is running.

The way source file and test file are beeing linked is configurable.

Installation

npm install separated-coverage --save-dev

Coveralls integration example

First, install coveralls module:

npm install coveralls --save-dev

Create run script for Travis in package.json. Assuming you are using mocha, your sources are in lib directory and tests in test:

"scripts": {
    "test": "...",
    "travis": "npm test && scov run -q -r lcov -a lib -s 'lib/**/*.js' -a test -t 'test/**/*.js' -- lib test | coveralls"
}

Change default Travis action from npm test to npm run travis in .travis.yml:

language: node_js
script: "npm run travis"
#...

More about coveralls: https://coveralls.io/ More about coveralls npm package: https://github.com/cainus/node-coveralls

CLI Usage

Usage:

  scov run [-p <profile>] [-d <driver>] [-b <filename>] [-r <reporter>] [-f <filename>]
      [-q] [-A <name>] [-I] [-S <file-set> [-O <name>]...] [-o <filename>]
      [-e <mask>]... [-s <mask>]... [-t <mask>]... [-a <mask>]... [-- <runner-args>...]

  scov instrument [-p <profile>] [-d <driver>] [-A <name>] [-I] [-q] [-f <filename>]
      [-S <file-set> [-O <name>]...]
      [-e <mask>]... [-s <mask>]... [-t <mask>]... <path>...

  scov report [-p <profile>] [-a <path>]... [-e <mask>]... [-s <mask>]... [-t <mask>]...
      [-q] [-S <file-set> [-O <name>]...]
      [-r <reporter>] [-o <filename>] <coverage-file>

  scov --version

  scov --help

Options:

  -s --sources=<mask>          Source files masks. Example: "lib/**".

  -t --tests=<mask>            Test files masks. Example: "test/**".

  -e --excludes=<mask>         Excluded file mask. Example: "lib/**.tmp.js".

  -a --additional=<path>       Additional files for the coverage report.
                               Useful when tests do not affect all the files.

  -b --bin=<filename>          Specifies executable file for test driver.

  -d --driver=<driver>         Specifies driver [default: mocha].

  -r --reporter=<name>         Reporer name: html, lcov, summary, teamcity, tree [default: tree].

  -o --output=<filename>       Report output filename.

  -f --file=<filename>         Saves "json"-coverage information to specified file.

  -X --no-export               Do not include json-save action into instrumented file.

  -p --profile=<profile>       Reads profile from "package.json".

  -S --set=<set>               File set. Test name source for input files [default: basename].

  -O --set-opt <name>=<val>    File set option.

  -A --api-object-name=<name>  Export API to an object in instrumented files.

  -I --include-init-coverage   Includes initialization coverage information.

  -q --quiet                   Runs quietly.

  --help                       Show this screen.

  --version                    Show version.