Skip to content

Custom Watermark Thresholds #405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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