Seamless integration between Rollup and Istanbul
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.github
src
test
.babelrc
.eslintrc
.gitignore
.travis.yml
CHANGELOG.md
LICENSE
README.md
package.json
rollup.config.js

README.md

rollup-plugin-istanbul

Build Status Maintainability Last version Total Downloads Downloads Last Month Dependencies Status License

Seamless integration between Rollup and Istanbul.

Why?

If you're using Rollup to generate a standalone bundle you will probably need also to bundle your tests before running them, and if you want the code coverage report, you will need to instrument the program files before the bundle is generated to avoid instrumenting also the code of the test files.

That is the reason why rollup-plugin-istanbul exists.

Installation

npm install --save-dev rollup-plugin-istanbul

Usage

import { rollup } from 'rollup';
import istanbul from 'rollup-plugin-istanbul';

rollup({
  entry: 'main.js',
  plugins: [
    istanbul({
      exclude: ['test/**/*.js']
    })
  ]
}).then(...)

Options

All options are optional.

include

Can be a minimatch pattern or an array of minimatch patterns. If is omitted or of zero length, files should be included by default; otherwise they should only be included if the ID matches one of the patterns.

exclude

Can be a minimatch pattern or an array of minimatch patterns. Files to exclude, commonly the test files.

instrumenterConfig

An object of options that will be passed to the instrumenter.

Default value:

{
  esModules: true,
  codeGenerationOptions: {
    sourceMap: id,
    sourceMapWithCode: true
  }
}

More info about options.

instrumenter

Can be a replacement for the istanbul library, for example isparta. It should implement the same API as istanbul.

Other usage options

rollup-plugin-istanbul can be used with karma or other test runners that allow preprocessors. Here you can see how to implement it with Karma with the help of the karma-rollup-preprocessor and karma-coverage:

// karma.conf.js
var istanbul = require('rollup-plugin-istanbul');

module.exports = function (config) {
  config.set({
    files: [
      'test/*.js'
    ],
    preprocessors: {
      'test/*.js': ['rollup']
    },
    rollupPreprocessor: {
      rollup: {
        plugins: [
          istanbul({
            exclude: ['test/*.js']
          })
        ]
      }
    },
    reporters: ['coverage']
  });
};

Going further, this is how you can implement it when you are using babel because you are writing ES2015 code:

// karma.conf.js

var babelrc = require('babelrc-rollup').default,
    babel = require('rollup-plugin-babel'),
    istanbul = require('rollup-plugin-istanbul');

module.exports = function (config) {
  config.set({
    files: [
      'test/*.js'
    ],
    preprocessors: {
      'test/*.js': ['rollup']
    },
    rollupPreprocessor: {
        plugins: [
            istanbul({
                exclude: ['test/*.js']
            }),
            babel(babelrc())
        ],
        format: 'iife',
        sourceMap: 'inline'
    },
    reporters: ['coverage']
  });
};

Example of implementation with Mocha provided by @piuccio: https://github.com/artberri/rollup-plugin-istanbul/issues/11

License

MIT