UNPKG

5.11 kBTypeScriptView Raw
1import { CoverageMap, CoverageSummary, FileCoverage } from "istanbul-lib-coverage";
2
3/**
4 * returns a reporting context for the supplied options
5 */
6export function createContext(options?: Partial<ContextOptions>): Context;
7/**
8 * returns the default watermarks that would be used when not
9 * overridden
10 */
11export function getDefaultWatermarks(): Watermarks;
12export class ReportBase {
13 constructor(options?: Partial<ReportBaseOptions>);
14 execute(context: Context): void;
15}
16
17export interface ReportBaseOptions {
18 summarizer: Summarizers;
19}
20
21export type Summarizers = "flat" | "nested" | "pkg" | "defaultSummarizer";
22
23export interface ContextOptions {
24 coverageMap: CoverageMap;
25 defaultSummarizer: Summarizers;
26 dir: string;
27 watermarks: Partial<Watermarks>;
28 sourceFinder(filepath: string): string;
29}
30
31export interface Context {
32 data: any;
33 dir: string;
34 sourceFinder(filepath: string): string;
35 watermarks: Watermarks;
36 writer: FileWriter;
37 /**
38 * returns the coverage class given a coverage
39 * types and a percentage value.
40 */
41 classForPercent(type: keyof Watermarks, value: number): string;
42 /**
43 * returns the source code for the specified file path or throws if
44 * the source could not be found.
45 */
46 getSource(filepath: string): string;
47 getTree(summarizer?: Summarizers): Tree;
48 /**
49 * returns a full visitor given a partial one.
50 */
51 getVisitor<N extends Node = Node>(visitor: Partial<Visitor<N>>): Visitor<N>;
52 /**
53 * returns a FileWriter implementation for reporting use. Also available
54 * as the `writer` property on the context.
55 */
56 getWriter(): FileWriter;
57 /**
58 * returns an XML writer for the supplied content writer
59 */
60 getXmlWriter(contentWriter: ContentWriter): XmlWriter;
61}
62
63/**
64 * Base class for writing content
65 */
66export class ContentWriter {
67 /**
68 * returns the colorized version of a string. Typically,
69 * content writers that write to files will return the
70 * same string and ones writing to a tty will wrap it in
71 * appropriate escape sequences.
72 */
73 colorize(str: string, clazz?: string): string;
74 /**
75 * writes a string appended with a newline to the destination
76 */
77 println(str: string): void;
78 /**
79 * closes this content writer. Should be called after all writes are complete.
80 */
81 close(): void;
82}
83
84/**
85 * a content writer that writes to a file
86 */
87export class FileContentWriter extends ContentWriter {
88 constructor(fileDescriptor: number);
89 write(str: string): void;
90}
91
92/**
93 * a content writer that writes to the console
94 */
95export class ConsoleWriter extends ContentWriter {
96 write(str: string): void;
97}
98
99/**
100 * utility for writing files under a specific directory
101 */
102export class FileWriter {
103 constructor(baseDir: string);
104 static startCapture(): void;
105 static stopCapture(): void;
106 static getOutput(): string;
107 static resetOutput(): void;
108 /**
109 * returns a FileWriter that is rooted at the supplied subdirectory
110 */
111 writeForDir(subdir: string): FileWriter;
112 /**
113 * copies a file from a source directory to a destination name
114 */
115 copyFile(source: string, dest: string, header?: string): void;
116 /**
117 * returns a content writer for writing content to the supplied file.
118 */
119 writeFile(file: string | null): ContentWriter;
120}
121
122export interface XmlWriter {
123 indent(str: string): string;
124 /**
125 * writes the opening XML tag with the supplied attributes
126 */
127 openTag(name: string, attrs?: any): void;
128 /**
129 * closes an open XML tag.
130 */
131 closeTag(name: string): void;
132 /**
133 * writes a tag and its value opening and closing it at the same time
134 */
135 inlineTag(name: string, attrs?: any, content?: string): void;
136 /**
137 * closes all open tags and ends the document
138 */
139 closeAll(): void;
140}
141
142export type Watermark = [number, number];
143
144export interface Watermarks {
145 statements: Watermark;
146 functions: Watermark;
147 branches: Watermark;
148 lines: Watermark;
149}
150
151export interface Node {
152 isRoot(): boolean;
153 visit(visitor: Visitor, state: any): void;
154}
155
156export interface ReportNode extends Node {
157 path: string;
158 parent: ReportNode | null;
159 fileCoverage: FileCoverage;
160 children: ReportNode[];
161 addChild(child: ReportNode): void;
162 asRelative(p: string): string;
163 getQualifiedName(): string;
164 getRelativeName(): string;
165 getParent(): Node;
166 getChildren(): Node[];
167 isSummary(): boolean;
168 getFileCoverage(): FileCoverage;
169 getCoverageSummary(filesOnly: boolean): CoverageSummary;
170 visit(visitor: Visitor<ReportNode>, state: any): void;
171}
172
173export interface Visitor<N extends Node = Node> {
174 onStart(root: N, state: any): void;
175 onSummary(root: N, state: any): void;
176 onDetail(root: N, state: any): void;
177 onSummaryEnd(root: N, state: any): void;
178 onEnd(root: N, state: any): void;
179}
180
181export interface Tree<N extends Node = Node> {
182 getRoot(): N;
183 visit(visitor: Partial<Visitor<N>>, state: any): void;
184}