Skip to content

Commit

Permalink
fix: set correct process exit code when thresholds are not met
Browse files Browse the repository at this point in the history
Fixes #80
  • Loading branch information
mattlewis92 committed May 4, 2020
1 parent b6632e2 commit 9ba3fe0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ All notable changes to this project will be documented in this file. See [standa

* node 6 and node 8 are no longer supported. To use this package you must upgrade to node 10 or higher.

* If using threshold reporting and the programmatic karma api, then the exitCode will no longer be returned as 1 when thresholds are not met.

### Features

* upgrade to latest istanbul api ([28cbbfb](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/commit/28cbbfb2cf8bd5b9533ceb489cc5047ff3def730))
Expand Down Expand Up @@ -217,4 +219,4 @@ All notable changes to this project will be documented in this file. See [standa

# 0.1.0

* Initial release
* Initial release
16 changes: 8 additions & 8 deletions src/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function CoverageIstanbulReporter(baseReporterDecorator, logger, config) {
}
}

async function createReport(browserOrBrowsers, results) {
async function createReport(browserOrBrowsers) {
const reportConfigOverride =
!coverageConfig.combineBrowserReports && coverageConfig.dir
? {
Expand Down Expand Up @@ -196,8 +196,10 @@ function CoverageIstanbulReporter(baseReporterDecorator, logger, config) {
});
});

if (thresholdCheckFailed && results && !thresholds.emitWarning) {
results.exitCode = 1;
if (thresholdCheckFailed && !thresholds.emitWarning && config.singleRun) {
process.on('exit', () => {
process.exit(1);
});
}
}

Expand Down Expand Up @@ -226,15 +228,13 @@ function CoverageIstanbulReporter(baseReporterDecorator, logger, config) {
};

const baseReporterOnRunComplete = this.onRunComplete;
this.onRunComplete = async function (browsers, results) {
this.onRunComplete = async function (browsers) {
Reflect.apply(baseReporterOnRunComplete, this, arguments);

if (coverageConfig.combineBrowserReports) {
await createReport(browsers, results);
await createReport(browsers);
} else {
await Promise.all(
browsers.map((browser) => createReport(browser, results))
);
await Promise.all(browsers.map((browser) => createReport(browser)));
}
};
}
Expand Down

0 comments on commit 9ba3fe0

Please sign in to comment.