istanbul-instrumenter-loader

raw JSON →
0.2.0 verified Sat Apr 25 auth: no javascript deprecated

Webpack loader that instruments JavaScript files with Istanbul for code coverage reporting. Version 0.2.0 is the latest stable release. This package is deprecated in favor of the official Istanbul monorepo loaders. It works with webpack 1 only and uses preLoaders. For webpack 2+, use babel-plugin-istanbul or the @istanbuljs/load-nyc-loader. Differentiator: it supports legacy webpack 1 projects; modern projects should use the official Istanbul toolchain.

error Module not found: Error: Cannot resolve module 'istanbul-instrumenter'
cause Loader name is missing the '-loader' suffix in webpack config.
fix
Use 'istanbul-instrumenter-loader' in the loader field, or ensure webpack resolves the loader correctly.
error Module parse failed: Unexpected token (1:0) You may need an appropriate loader to handle this file type.
cause Loader is not applied because it's placed in loaders instead of preLoaders (webpack 1).
fix
Move the loader configuration to the preLoaders property.
error Cannot find module 'istanbul'
cause Istanbul is not listed as a dependency, but it is a peer dependency.
fix
Run npm i -D istanbul to install Istanbul explicitly.
deprecated This package is deprecated. Use babel-plugin-istanbul or @istanbuljs/load-nyc-loader instead.
fix Migrate to babel-plugin-istanbul: install and add to babel plugins.
breaking In webpack 2+, preLoaders are no longer supported.
fix Use the rules property with enforce: 'pre' or use a custom plugin.
gotcha The package name on npm is 'istanbul-instrumenter-loader', but the repository URL points to 'sourcemap-istanbul-instrumenter-loader'. This discrepancy can cause confusion.
fix Install using npm i -D istanbul-instrumenter-loader, not sourcemap-istanbul-instrumenter-loader.
gotcha This loader only works with Istanbul v0.x, not Istanbul v1+ (nyc).
fix Use @istanbuljs/load-nyc-loader for nyc compatibility.
npm install sourcemap-istanbul-instrumenter-loader
yarn add sourcemap-istanbul-instrumenter-loader
pnpm add sourcemap-istanbul-instrumenter-loader

Shows webpack 1 karma setup with istanbul-instrumenter-loader in preLoaders for code coverage.

// Install: npm i -D istanbul-instrumenter-loader istanbul karma karma-webpack karma-coverage

// karma.conf.js
config.set({
  files: ['test/index.js'],
  preprocessors: { 'test/index.js': 'webpack' },
  webpack: {
    module: {
      preLoaders: [
        {
          test: /\.js$/,
          include: path.resolve('src/components/'),
          loader: 'istanbul-instrumenter'
        }
      ]
    }
  },
  reporters: ['progress', 'coverage'],
  coverageReporter: { type: 'text' }
});

// test/index.js
const testsContext = require.context('./src/components/', true, /\.js$/);
testsContext.keys().forEach(testsContext);
const componentsContext = require.context('../src/components/', true, /\.js$/);
componentsContext.keys().forEach(componentsContext);