istanbul-instrumenter-loader

WebJar for istanbul-instrumenter-loader

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

istanbul-instrumenter-loader
Last Version

Last Version

3.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

istanbul-instrumenter-loader
WebJar for istanbul-instrumenter-loader
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/webpack-contrib/istanbul-instrumenter-loader

Download istanbul-instrumenter-loader

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/istanbul-instrumenter-loader/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>istanbul-instrumenter-loader</artifactId>
    <version>3.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/istanbul-instrumenter-loader/
implementation 'org.webjars.npm:istanbul-instrumenter-loader:3.0.0'
// https://jarcasting.com/artifacts/org.webjars.npm/istanbul-instrumenter-loader/
implementation ("org.webjars.npm:istanbul-instrumenter-loader:3.0.0")
'org.webjars.npm:istanbul-instrumenter-loader:jar:3.0.0'
<dependency org="org.webjars.npm" name="istanbul-instrumenter-loader" rev="3.0.0">
  <artifact name="istanbul-instrumenter-loader" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='istanbul-instrumenter-loader', version='3.0.0')
)
libraryDependencies += "org.webjars.npm" % "istanbul-instrumenter-loader" % "3.0.0"
[org.webjars.npm/istanbul-instrumenter-loader "3.0.0"]

Dependencies

compile (4)

Group / Artifact Type Version
org.webjars.npm : convert-source-map jar [1.5.0,2)
org.webjars.npm : istanbul-lib-instrument jar [1.7.3,2)
org.webjars.npm : loader-utils jar [1.1.0,2)
org.webjars.npm : schema-utils jar [0.3.0,0.4)

Project Modules

There are no modules declared in this project.

npm node deps tests coverage chat

Istanbul Instrumenter Loader

Instrument JS files with istanbul-lib-instrument for subsequent code coverage reporting

Install

npm i -D istanbul-instrumenter-loader

Usage

References

Structure

├─ src
│ |– components
│ | |– bar
│ | │ |─ index.js
│ | |– foo/
│     |– index.js
|– test
| |– src
| | |– components
| | | |– foo
| | | | |– index.js

To create a code coverage report for all components (even for those for which you have no tests yet) you have to require all the 1) sources and 2) tests. Something like it's described in "alternative usage" of karma-webpack

test/index.js

// requires all tests in `project/test/src/components/**/index.js`
const tests = require.context('./src/components/', true, /index\.js$/);

tests.keys().forEach(tests);

// requires all components in `project/src/components/**/index.js`
const components = require.context('../src/components/', true, /index\.js$/);

components.keys().forEach(components);

ℹ️ This file will be the only entry point for karma

karma.conf.js

config.set({
  ...
  files: [
    'test/index.js'
  ],
  preprocessors: {
    'test/index.js': 'webpack'
  },
  webpack: {
    ...
    module: {
      rules: [
        // instrument only testing sources with Istanbul
        {
          test: /\.js$/,
          use: { loader: 'istanbul-instrumenter-loader' },
          include: path.resolve('src/components/')
        }
      ]
    }
    ...
  },
  reporters: [ 'progress', 'coverage-istanbul' ],
  coverageIstanbulReporter: {
    reports: [ 'text-summary' ],
    fixWebpackSourcePaths: true
  }
  ...
});

with Babel

You must run the instrumentation as a post step

webpack.config.js

{
  test: /\.js$|\.jsx$/,
  use: {
    loader: 'istanbul-instrumenter-loader',
    options: { esModules: true }
  },
  enforce: 'post',
  exclude: /node_modules|\.spec\.js$/,
}

Options

The loader supports all options supported by istanbul-lib-instrument

Name Type Default Description
debug {Boolean} false Turn on debugging mode
compact {Boolean} true Generate compact code
autoWrap {Boolean} false Set to true to allow return statements outside of functions
esModules {Boolean} false Set to true to instrument ES2015 Modules
coverageVariable {String} __coverage__ Name of global coverage variable
preserveComments {Boolean} false Preserve comments in output
produceSourceMap {Boolean} false Set to true to produce a source map for the instrumented code
sourceMapUrlCallback {Function} null A callback function that is called when a source map URL is found in the original code. This function is called with the source filename and the source map URL

webpack.config.js

{
  test: /\.js$/,
  use: {
    loader: 'istanbul-instrumenter-loader',
    options: {...options}
  }
}

Maintainers


Kir Belevich

Juho Vepsäläinen

Joshua Wiens

Michael Ciniawsky

Matt Lewis
org.webjars.npm

webpack-contrib

Community supported 3rd party packages for webpack

Versions

Version
3.0.0
2.0.0