Socket
Socket
Sign inDemoInstall

istanbul

Package Overview
Dependencies
Maintainers
2
Versions
95
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

istanbul

Yet another JS code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests. Supports all JS coverage use cases including unit tests, server side functional tests


Version published
Weekly downloads
569K
increased by5.03%
Maintainers
2
Weekly downloads
 
Created

What is istanbul?

Istanbul is a popular JavaScript code coverage tool that helps developers measure how much of their code is being tested. It provides detailed reports and integrates well with various testing frameworks.

What are istanbul's main functionalities?

Code Coverage

Istanbul can be used to generate code coverage reports in various formats such as HTML, lcov, and text. This helps developers understand which parts of their code are covered by tests.

const istanbul = require('istanbul');
const collector = new istanbul.Collector();
const reporter = new istanbul.Reporter();
reporter.addAll(['html', 'lcov', 'text']);
reporter.write(collector, true, () => {
  console.log('Coverage report generated');
});

Instrumenting Code

Istanbul can instrument your code, which means it adds hooks to your code to track which parts are executed during a test run. This is essential for generating accurate coverage reports.

const istanbul = require('istanbul');
const instrumenter = new istanbul.Instrumenter();
const fs = require('fs');
const code = fs.readFileSync('path/to/your/file.js', 'utf8');
instrumenter.instrument(code, 'path/to/your/file.js', (err, instrumentedCode) => {
  if (err) {
    console.error(err);
  } else {
    fs.writeFileSync('path/to/your/instrumentedFile.js', instrumentedCode);
  }
});

Integration with Testing Frameworks

Istanbul integrates well with various testing frameworks like Mocha, Jasmine, and Jest. This allows you to run your tests and generate coverage reports seamlessly.

const Mocha = require('mocha');
const istanbul = require('istanbul');
const mocha = new Mocha();
const collector = new istanbul.Collector();
const reporter = new istanbul.Reporter();
mocha.addFile('test/yourTestFile.js');
mocha.run(() => {
  reporter.addAll(['html', 'lcov', 'text']);
  reporter.write(collector, true, () => {
    console.log('Coverage report generated');
  });
});

Other packages similar to istanbul

Keywords

FAQs

Package last updated on 05 Oct 2015

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