diff --git a/packages/karma-typescript/README.md b/packages/karma-typescript/README.md index 21e9f0fd..4810dd38 100644 --- a/packages/karma-typescript/README.md +++ b/packages/karma-typescript/README.md @@ -270,6 +270,19 @@ If the defaults aren't enough, the settings can be configured from `karma.conf.j } ``` +* **karmaTypescriptConfig.coverageOptions.watermarks** - An object with custom istanbul watermarks. Each value is an array consisting of + a lower and upper bound. If code coverage is above the upper bound, this is considered "healthy", and many reports will print output in green. + If code coverage is below the lower bound, this is considered "unhealthy", and many reports will print output in red. Yellow output is reserved + for coverage in between the lower and upper bound. + ```javascript + watermarks: { + lines: [75, 90], + functions: [75, 90], + branches: [75, 90], + statements: [75, 90] + } + ``` + * **karmaTypescriptConfig.exclude** - File string patterns to be excluded by the compiler. This property may be an `array` or an `object` for more fine-grained control. * Array: The string values will be merged with existing options. * Object: The string values will be merged with or replace existing options: @@ -577,7 +590,7 @@ Typescript files and JavaScript files from `node_modules`, making each plugin im context before performing any logic, for example by checking the file name, module name or the existence of an ast object etc. Each transforming function will be executed before resolving dependencies, which means paths in `import` or `require` statements -or anywhere in the code can be rewritten before bundling, to fit the Karma execution environment. +or anywhere in the code can be rewritten before bundling, to fit the Karma execution environment. Example of a simple inline transforming function replacing the contents of a `.css` file, mimicking the behavior of Css Modules: diff --git a/packages/karma-typescript/src/api/configuration.ts b/packages/karma-typescript/src/api/configuration.ts index 57eb7108..56a50322 100644 --- a/packages/karma-typescript/src/api/configuration.ts +++ b/packages/karma-typescript/src/api/configuration.ts @@ -78,6 +78,7 @@ export interface CoverageOptions { instrumenterOptions?: any; exclude?: RegExp | RegExp[]; threshold?: ThresholdOptions; + watermarks?: any; } export interface Reports { diff --git a/packages/karma-typescript/src/karma/reporter.ts b/packages/karma-typescript/src/karma/reporter.ts index 5e53ed4a..5d924d95 100644 --- a/packages/karma-typescript/src/karma/reporter.ts +++ b/packages/karma-typescript/src/karma/reporter.ts @@ -70,11 +70,13 @@ export class Reporter { that.log.debug("Writing coverage to %s", directory); } - const context = istanbulReport.createContext({ + const istanbulReportOptions = { coverageMap: remappedCoverageMap, dir: directory, - sourceFinder: sourceMapStore.sourceFinder - }); + sourceFinder: sourceMapStore.sourceFinder, + watermarks: config.coverageOptions.watermarks + }; + const context = istanbulReport.createContext(istanbulReportOptions); istanbulReports .create(reportType, { file: reportConfig ? reportConfig.filename : undefined }) @@ -83,9 +85,9 @@ export class Reporter { .execute(context); }); - - return results - && config.hasCoverageThreshold + + return results + && config.hasCoverageThreshold && !threshold.check(browser, remappedCoverageMap); });