What is @types/istanbul-lib-report?
The @types/istanbul-lib-report package provides TypeScript type definitions for istanbul-lib-report, which is a library for generating code coverage reports in various formats. It is part of the Istanbul code coverage tooling ecosystem. These type definitions enable TypeScript developers to use istanbul-lib-report in a type-safe manner, benefiting from compile-time type checks and IntelliSense in their IDE.
Creating a report context
This feature allows you to create a report context specifying the output directory and watermarks for coverage metrics. The context is used to generate reports.
import { createContext } from 'istanbul-lib-report';
const context = createContext({
dir: './coverage',
watermarks: {
statements: [50, 80],
functions: [50, 80],
branches: [50, 80],
lines: [50, 80]
}
});
Generating a report
After creating a report context, you can generate a report in various formats (e.g., HTML, JSON) using the istanbul-reports package. This example demonstrates generating an HTML report.
import { create } from 'istanbul-reports';
const report = create('html', context);
report.execute(summarizer);