Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

istanbul-lib-instrument

Package Overview
Dependencies
Maintainers
1
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

istanbul-lib-instrument

Core istanbul API for JS code coverage

  • 1.1.0-alpha.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
52M
increased by3.87%
Maintainers
1
Weekly downloads
 
Created

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

Keywords

FAQs

Package last updated on 25 Jun 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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc