UNPKG

2.14 kBTypeScriptView Raw
1// Type definitions for istanbul-lib-instrument 1.7
2// Project: https://istanbul.js.org, https://github.com/istanbuljs/istanbuljs
3// Definitions by: Jason Cheatham <https://github.com/jason0x43>
4// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5// TypeScript Version: 2.8
6
7import { FileCoverage, FileCoverageData, Range } from 'istanbul-lib-coverage';
8import { RawSourceMap } from 'source-map';
9import * as babelTypes from 'babel-types';
10
11export interface InstrumenterOptions {
12 coverageVariable: string;
13 preserveComments: boolean;
14 compact: boolean;
15 esModules: boolean;
16 autoWrap: boolean;
17 produceSourceMap: boolean;
18 sourceMapUrlCallback(filename: string, url: string): void;
19 debug: boolean;
20}
21
22export type InstrumenterCallback = (error: Error | null, code: string) => void;
23
24export class Instrumenter {
25 fileCoverage: FileCoverage;
26 sourceMap: RawSourceMap | null;
27 opts: InstrumenterOptions;
28
29 constructor(options?: Partial<InstrumenterOptions>);
30
31 normalizeOpts(options?: Partial<InstrumenterOptions>): InstrumenterOptions;
32
33 instrumentSync(
34 code: string,
35 filename: string,
36 inputSourceMap?: RawSourceMap
37 ): string;
38
39 instrument(
40 code: string,
41 filenameOrCallback: string | InstrumenterCallback,
42 callback?: InstrumenterCallback,
43 inputSourceMap?: RawSourceMap
44 ): void;
45
46 lastFileCoverage(): FileCoverageData;
47 lastSourceMap(): RawSourceMap;
48}
49
50export function createInstrumenter(
51 options?: Partial<InstrumenterOptions>
52): Instrumenter;
53
54export interface InitialCoverage {
55 path: string;
56 hash: string;
57 gcv: any;
58 coverageData: any;
59}
60
61export function readInitialCoverage(code: string): InitialCoverage;
62
63export interface Visitor {
64 enter(path: string): void;
65 exit(path: string): { fileCoverage: FileCoverage; sourceMappingURL: string };
66}
67
68export interface VisitorOptions {
69 coverageVariable: string;
70 inputSourceMap: RawSourceMap;
71}
72
73export function programVisitor(
74 types: typeof babelTypes,
75 sourceFilePath?: string,
76 opts?: Partial<VisitorOptions>
77): Visitor;