Socket
Socket
Sign inDemoInstall

istanbul-lib-instrument

Package Overview
Dependencies
7
Maintainers
2
Versions
75
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

istanbul-lib-instrument


Version published
Weekly downloads
41M
decreased by-0.62%
Maintainers
2
Created
Weekly downloads
 

Package description

What is istanbul-lib-instrument?

The 'istanbul-lib-instrument' package is a core library for instrumenting JavaScript code for coverage analysis. It is part of the Istanbul toolset, which is widely used for code coverage reporting in JavaScript projects. The library provides functionality to instrument code, which means it adds additional code to track which parts of the original code are executed during a test run.

What are istanbul-lib-instrument's main functionalities?

Instrumenting Code

This feature allows you to instrument JavaScript code. The `createInstrumenter` function creates an instrumenter instance, which can then be used to instrument code synchronously using the `instrumentSync` method. The instrumented code will include additional statements to track execution.

const { createInstrumenter } = require('istanbul-lib-instrument');
const instrumenter = createInstrumenter();
const originalCode = 'function add(a, b) { return a + b; }';
const instrumentedCode = instrumenter.instrumentSync(originalCode, 'filename.js');
console.log(instrumentedCode);

Generating Coverage Maps

This feature allows you to generate a coverage map for the instrumented code. After instrumenting the code, you can call the `lastFileCoverage` method to get a coverage map, which provides detailed information about which parts of the code were executed.

const { createInstrumenter } = require('istanbul-lib-instrument');
const instrumenter = createInstrumenter();
const originalCode = 'function add(a, b) { return a + b; }';
instrumenter.instrumentSync(originalCode, 'filename.js');
const coverageMap = instrumenter.lastFileCoverage();
console.log(coverageMap);

Other packages similar to istanbul-lib-instrument

Readme

Source

istanbul-lib-instrument

Build Status

Istanbul instrumenter library.

Version 1.1.x now implements instrumentation using Babel. The implementation is inspired by prior art by @dtinth as demonstrated in the __coverage__ babel plugin.

It provides 2 "modes" of instrumentation.

  • The old API that is mostly unchanged (except for incompatibilities noted) and performs the instrumentation using babel as a library.

  • A programVisitor function for the Babel AST that can be used by a Babel plugin to emit instrumentation for ES6 code directly without any source map processing. This is the preferred path for babel users. The Babel plugin is called babel-plugin-istanbul.

Incompatibilities and changes to instrumentation behavior can be found in v0-changes.md.

Keywords

FAQs

Last updated on 25 Oct 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc