1 | import libCoverage from "istanbul-lib-coverage";
|
2 | import urlMod from "url";
|
3 | import { GetTextSync, getTextSync as defaultGetTextSync } from "./get-text";
|
4 | import { Reporter, StreamReporter, VinylReporter } from "./reporter";
|
5 | import { ReporterRegistry } from "./reporter-registry";
|
6 | import { CompoundReporter } from "./reporters/compound";
|
7 |
|
8 | export function createReporter(registry: ReporterRegistry, ids: ReadonlyArray<string>, options: any): Reporter {
|
9 | const reporters: Reporter[] = [];
|
10 | for (const id of ids) {
|
11 | reporters.push(registry.create(id, options));
|
12 | }
|
13 | return reporters.length === 1 ? reporters[0] : new CompoundReporter(reporters);
|
14 | }
|
15 |
|
16 | export function reportVinyl(
|
17 | reporter: VinylReporter,
|
18 | covMap: libCoverage.CoverageMap,
|
19 | getTextSync: GetTextSync = defaultGetTextSync,
|
20 | ): NodeJS.ReadableStream {
|
21 | return reporter.reportVinyl({map: covMap, sourceFinder: (url => getTextSync(new urlMod.URL(url)))});
|
22 | }
|
23 |
|
24 | export function reportStream(
|
25 | reporter: StreamReporter,
|
26 | covMap: libCoverage.CoverageMap,
|
27 | getTextSync: GetTextSync = defaultGetTextSync,
|
28 | ): NodeJS.ReadableStream {
|
29 | return reporter.reportStream({map: covMap, sourceFinder: (url => getTextSync(new urlMod.URL(url)))});
|
30 | }
|