Skip to content

Commit

Permalink
add ability to specify coverage watermark thresholds (#405)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanvall authored Sep 17, 2020
1 parent 8b8f14a commit 29ce7f7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
15 changes: 14 additions & 1 deletion packages/karma-typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:

Expand Down
1 change: 1 addition & 0 deletions packages/karma-typescript/src/api/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export interface CoverageOptions {
instrumenterOptions?: any;
exclude?: RegExp | RegExp[];
threshold?: ThresholdOptions;
watermarks?: any;
}

export interface Reports {
Expand Down
14 changes: 8 additions & 6 deletions packages/karma-typescript/src/karma/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand All @@ -83,9 +85,9 @@ export class Reporter {
.execute(context);

});
return results
&& config.hasCoverageThreshold

return results
&& config.hasCoverageThreshold
&& !threshold.check(browser, remappedCoverageMap);
});

Expand Down

0 comments on commit 29ce7f7

Please sign in to comment.