Skip to content

Commit 29ce7f7

Browse files
authored
add ability to specify coverage watermark thresholds (#405)
1 parent 8b8f14a commit 29ce7f7

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

packages/karma-typescript/README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,19 @@ If the defaults aren't enough, the settings can be configured from `karma.conf.j
270270
}
271271
```
272272

273+
* **karmaTypescriptConfig.coverageOptions.watermarks** - An object with custom istanbul watermarks. Each value is an array consisting of
274+
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.
275+
If code coverage is below the lower bound, this is considered "unhealthy", and many reports will print output in red. Yellow output is reserved
276+
for coverage in between the lower and upper bound.
277+
```javascript
278+
watermarks: {
279+
lines: [75, 90],
280+
functions: [75, 90],
281+
branches: [75, 90],
282+
statements: [75, 90]
283+
}
284+
```
285+
273286
* **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.
274287
* Array: The string values will be merged with existing options.
275288
* 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
577590
context before performing any logic, for example by checking the file name, module name or the existence of an ast object etc.
578591

579592
Each transforming function will be executed before resolving dependencies, which means paths in `import` or `require` statements
580-
or anywhere in the code can be rewritten before bundling, to fit the Karma execution environment.
593+
or anywhere in the code can be rewritten before bundling, to fit the Karma execution environment.
581594

582595
Example of a simple inline transforming function replacing the contents of a `.css` file, mimicking the behavior of Css Modules:
583596

packages/karma-typescript/src/api/configuration.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export interface CoverageOptions {
7878
instrumenterOptions?: any;
7979
exclude?: RegExp | RegExp[];
8080
threshold?: ThresholdOptions;
81+
watermarks?: any;
8182
}
8283

8384
export interface Reports {

packages/karma-typescript/src/karma/reporter.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,13 @@ export class Reporter {
7070
that.log.debug("Writing coverage to %s", directory);
7171
}
7272

73-
const context = istanbulReport.createContext({
73+
const istanbulReportOptions = {
7474
coverageMap: remappedCoverageMap,
7575
dir: directory,
76-
sourceFinder: sourceMapStore.sourceFinder
77-
});
76+
sourceFinder: sourceMapStore.sourceFinder,
77+
watermarks: config.coverageOptions.watermarks
78+
};
79+
const context = istanbulReport.createContext(istanbulReportOptions);
7880

7981
istanbulReports
8082
.create(reportType, { file: reportConfig ? reportConfig.filename : undefined })
@@ -83,9 +85,9 @@ export class Reporter {
8385
.execute(context);
8486

8587
});
86-
87-
return results
88-
&& config.hasCoverageThreshold
88+
89+
return results
90+
&& config.hasCoverageThreshold
8991
&& !threshold.check(browser, remappedCoverageMap);
9092
});
9193

0 commit comments

Comments
 (0)