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AAC,cAAc,CAAC,YAAY,CAAC,IAAI,CAAC;gCAA/C,CAA+C;gCACjD,UAAU,EAAE,IAAI,CAAC,UAAU;6BAC5B,CAAC,CAAC;4BACH,yBAAM,CAAC,IAAI,EAAE,IAAI,CAAC,kBAAkB,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;;;;;SAC1D;QAGD,yBAAM,GAAN;YACE,IAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC;YACtC,IAAI,GAAG,CAAC,KAAK,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE;gBAC1B,OAAO,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;aACxD;QACH,CAAC;QALD;YADC,YAAY,EAAE;8CAMd;QACH,eAAC;KAAA,AAhED,CACU,kBAAQ,GA+DjB;sBAhE6B,QAAQ;IA+EtC,SAAS,aAAa,CAAC,KAAU;QAC/B,OAAO,KAAK,IAAI,IAAI,IAAI,OAAO,KAAK,CAAC,KAAK,KAAK,UAAU,CAAC;IAC5D,CAAC","sourcesContent":["import {\n CoverageMap,\n CoverageMapData,\n createCoverageMap,\n} from 'istanbul-lib-coverage';\nimport { createContext, Watermarks } from 'istanbul-lib-report';\nimport { create, ReportType } from 'istanbul-reports';\nimport Reporter, { createEventHandler, ReporterProperties } from './Reporter';\nimport Node, { NodeEvents } from '../executors/Node';\n\nexport { ReportType };\n\nconst eventHandler = createEventHandler<NodeEvents>();\n\nexport default abstract class Coverage\n extends Reporter\n implements CoverageProperties\n{\n abstract readonly reportType: ReportType;\n readonly executor!: Node;\n\n filename?: string;\n directory?: string;\n watermarks?: Watermarks;\n\n constructor(executor: Node, options: CoverageOptions = {}) {\n super(executor, options);\n\n if (options.filename) {\n this.filename = options.filename;\n }\n if (options.directory) {\n this.directory = options.directory;\n }\n if (options.watermarks) {\n this.watermarks = options.watermarks;\n }\n }\n\n getReporterOptions(): { [key: string]: any } {\n return {\n file: this.filename,\n };\n }\n\n async createCoverageReport(\n type: ReportType,\n data: CoverageMapData | CoverageMap\n ) {\n let map: CoverageMap;\n\n if (isCoverageMap(data)) {\n map = data;\n } else {\n map = createCoverageMap(data);\n }\n\n const transformed = await this.executor.sourceMapStore.transformCoverage(\n map\n );\n\n const context = createContext({\n coverageMap: transformed,\n dir: this.directory,\n sourceFinder: (path: string) =>\n this.executor.sourceMapStore.sourceFinder(path),\n watermarks: this.watermarks,\n });\n create(type, this.getReporterOptions()).execute(context);\n }\n\n @eventHandler()\n runEnd(): void | Promise<any> {\n const map = this.executor.coverageMap;\n if (map.files().length > 0) {\n return this.createCoverageReport(this.reportType, map);\n }\n }\n}\n\nexport interface CoverageProperties extends ReporterProperties {\n /** A filename to write coverage data to */\n filename?: string;\n\n /** A direcotry to write coverage data to */\n directory?: string;\n\n /** Watermarks used to check coverage */\n watermarks?: Watermarks;\n}\n\nexport type CoverageOptions = Partial<CoverageProperties>;\n\nfunction isCoverageMap(value: any): value is CoverageMap {\n return value != null && typeof value.files === 'function';\n}\n"]}
\No newline at end of file