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N,CAAC,CAAC;QAED,IAAI,CAAC,MAAc,CAAC,OAAO,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC9C,CAAC;IAEO,uCAAoB,GAA5B,UAA6B,OAAY,EAAE,OAAY,EAAE,UAAe;QAEpE,IAAM,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;QAEzC,IAAI,MAAM,CAAC,aAAa,CAAC,YAAY,CAAC,EAAE;YACpC,IAAI,YAAY,GAAG,YAAY,CAAC,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;YAC7D,IAAI,OAAO,YAAY,KAAK,UAAU,EAAE;gBACpC,YAAY,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;aACxC;YAED,OAAO,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,SAAS,IAAI,UAAU,EACpC,YAAY,EACZ,YAAY,CAAC,QAAQ,IAAI,UAAU,CAAC,CAAC;SACzD;QAED,IAAI,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE;YAC1D,OAAO,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;SAC5D;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;IACL,eAAC;AAAD,CAAC,AAtGD,IAsGC;AAtGY,4BAAQ","sourcesContent":["import * as lodash from \"lodash\";\nimport * as path from \"path\";\n\nimport { Collector, Store } from \"istanbul\";\nimport { ConfigOptions } from \"karma\";\nimport { Logger } from \"log4js\";\n\nimport { Threshold } from \"../istanbul/threshold\";\nimport { Configuration } from \"../shared/configuration\";\nimport { SharedProcessedFiles } from \"../shared/shared-processed-files\";\n\nexport class Reporter {\n\n public create: (karmaConfig: ConfigOptions, helper: any, logger: any, emitter: any) => void;\n\n private log: Logger;\n private remap = require(\"remap-istanbul/lib/remap\");\n private writeReport = require(\"remap-istanbul/lib/writeReport\");\n\n constructor(config: Configuration, sharedProcessedFiles: SharedProcessedFiles, threshold: Threshold) {\n\n const self = this;\n\n // tslint:disable-next-line:only-arrow-functions\n this.create = function(logger: any) {\n\n let coverageMap: WeakMap<any, any>;\n\n self.log = logger.create(\"reporter.karma-typescript\");\n this.adapters = [];\n\n this.onRunStart = () => {\n coverageMap = new WeakMap<any, any>();\n };\n\n this.onBrowserComplete = (browser: any, result: any) => {\n if (!result || !result.coverage) {\n return;\n }\n coverageMap.set(browser, result.coverage);\n };\n\n this.onRunComplete = (browsers: any[], results: any) => {\n\n browsers.forEach((browser: any) => {\n\n const coverage = coverageMap.get(browser);\n const unmappedCollector = new Collector();\n\n if (!coverage) {\n return;\n }\n\n unmappedCollector.add(coverage);\n\n const sourceStore = (Store as any).create(\"memory\");\n config.remapOptions.sources = sourceStore;\n config.remapOptions.readFile = (filepath: string) => {\n return sharedProcessedFiles[filepath];\n };\n const collector = self.remap((unmappedCollector as any).getFinalCoverage(), config.remapOptions);\n\n if (results && config.hasCoverageThreshold && !threshold.check(browser, collector)) {\n results.exitCode = 1;\n }\n\n Promise\n .all(Object.keys(config.reports)\n .map((reportType) => {\n\n const destination = self.getReportDestination(browser, config.reports, reportType);\n\n if (destination) {\n self.log.debug(\"Writing coverage to %s\", destination);\n }\n\n return self.writeReport(collector, reportType, {}, destination, sourceStore);\n }))\n .catch((error: any) => {\n self.log.error(error);\n })\n .then(() => {\n collector.dispose();\n coverageMap = null;\n });\n });\n };\n };\n\n (this.create as any).$inject = [\"logger\"];\n }\n\n private getReportDestination(browser: any, reports: any, reportType: any) {\n\n const reportConfig = reports[reportType];\n\n if (lodash.isPlainObject(reportConfig)) {\n let subdirectory = reportConfig.subdirectory || browser.name;\n if (typeof subdirectory === \"function\") {\n subdirectory = subdirectory(browser);\n }\n\n return path.join(reportConfig.directory || \"coverage\",\n subdirectory,\n reportConfig.filename || reportType);\n }\n\n if (lodash.isString(reportConfig) && reportConfig.length > 0) {\n return path.join(reportConfig, browser.name, reportType);\n }\n\n return null;\n }\n}\n"]}