3.0.1 • Published 6 years ago

istanbul-instrumenter-loader v3.0.1

Weekly downloads
487,663
License
MIT
Repository
github
Last release
6 years ago

npm node deps tests coverage chat

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

npm i -D istanbul-instrumenter-loader

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$/,
}

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

NameTypeDefaultDescription
debug{Boolean}falseTurn on debugging mode
compact{Boolean}trueGenerate compact code
autoWrap{Boolean}falseSet to true to allow return statements outside of functions
esModules{Boolean}falseSet to true to instrument ES2015 Modules
coverageVariable{String}__coverage__Name of global coverage variable
preserveComments{Boolean}falsePreserve comments in output
produceSourceMap{Boolean}falseSet to true to produce a source map for the instrumented code
sourceMapUrlCallback{Function}nullA 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}
  }
}
@jframe/iockelvin-id-generator-aws-xrayotel-aws-xray-id-generatorpeach-clicustom-angular-clifragrans-clifrag-cling2workspace-addon-webpack-karma@infinitebrahmanuniverse/nolb-istmost-dependencies@everything-registry/sub-chunk-1938zoom-intro-cligulp-core-build-karmagrumbler-scriptsreact-boilerplate-app-scriptsreact-basisxes-webpack-corefoglet-scriptsxiaoliang2233angularcli@thinkeloquent/npm-build-script@stone-payments/emd-clireact-scripts-xiag-sm@steinwei/builder-webpack-demo@speedray/cliwebdevkit-gugfeng-rc-toolsfhir2feflow-devkit-ivweb-examplefiredev-frameworkprokure_blueprintqualifysghs-umami-tonkotsu-curator-compilerghs-umami-tonkotsu-curator-devtoolsquang-cliplusnew-webpack-configpoi-plugin-karmapoi-preset-karmahornet-js-builder-newsearch-list-detail@webank/fes-clirunpack@bb-cli/bb-testaegis-tools@blackbaud-bobbyearl/skyux-builder@blackbaud/skyux-builder@blueprint-modernized/karma-build-scripts@blueprintjs/karma-build-scripts@canvest/canvest-cliangrepeatkeep-observersshark-testangular-devkit-web3angular-devkit_build-angular_v7-no-vuln@ckeditor/ckeditor5-package-toolsslim-cli1000-packages@tylertech/forge-clirebird-https-letsencryptrocktime-webpack@vue2do/test@yolkai/nx-web@dojo/cli-build-app@dojo/cli-build-widget@dolphin-ocean/cli-uiloading-infoavaility-workflow-angularspmhsprout-web-uistandard-dev-dependenciesbabel-buildaxios-yet-another-proxy-fix@framing/bizbasebuild-componentbee-toolsbee-tools-testbee-tools1mathcalculatorbs3-breakpoint@hai-ui/karma-build-scriptsangular-library-seed-og-testkarma-jasmine-istanbul-webpack-angularjskarma-config-rentpathangularcli-patched-cryptiles@axio/react-scriptsangular2-example-http-loginangular2-common-pkgantd-binkamilkisiela-angular-cli@cashfarm/angular-advanced-cli@caplin/karma-test-runnerangular-build-web3angular-build-web3-fixangular-cli-patchedangular-cli-pugangular-cli-with-use-yarnkenya-project-pkgangular-cli-europlanangular-cli-extrs-react-notification-systemrsc-test
3.0.1

6 years ago

3.0.0

7 years ago

3.0.0-rc.1

7 years ago

3.0.0-rc.0

7 years ago

3.0.0-beta.1

7 years ago

3.0.0-beta.0

7 years ago

2.0.0

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.0

8 years ago

0.2.0

8 years ago

0.1.3

9 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago