Skip to content

Commit

Permalink
Return exit code 1 if coverage threshold requirements are not met (je…
Browse files Browse the repository at this point in the history
…stjs#1974)

* determine if a run is successful after onRunComplete

* Update TestRunner.js
  • Loading branch information
lazywithclass authored and okonet committed Nov 11, 2016
1 parent 6066435 commit b9a3c8c
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions packages/jest-cli/src/TestRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,7 @@ class TestRunner {
)
);

const finalizeResults = () => {
// Update snapshot state.
const updateSnapshotState = () => {
const status =
snapshot.cleanup(this._hasteContext.hasteFS, config.updateSnapshot);
aggregatedResults.snapshot.filesRemoved += status.filesRemoved;
Expand All @@ -238,21 +237,6 @@ class TestRunner {
aggregatedResults.snapshot.filesRemoved
)
);

aggregatedResults.wasInterrupted = watcher.isInterrupted();

// Check if the test run was successful or not.
const anyTestFailures = !(
aggregatedResults.numFailedTests === 0 &&
aggregatedResults.numRuntimeErrorTestSuites === 0
);
const anyReporterErrors = this._dispatcher.hasErrors();

aggregatedResults.success = !(
anyTestFailures ||
aggregatedResults.snapshot.failure ||
anyReporterErrors
);
};

const runInBand = shouldRunInBand();
Expand All @@ -278,8 +262,23 @@ class TestRunner {
}
})
.then(() => {
finalizeResults();
updateSnapshotState();
aggregatedResults.wasInterrupted = watcher.isInterrupted();

this._dispatcher.onRunComplete(config, aggregatedResults);

const anyTestFailures = !(
aggregatedResults.numFailedTests === 0 &&
aggregatedResults.numRuntimeErrorTestSuites === 0
);
const anyReporterErrors = this._dispatcher.hasErrors();

aggregatedResults.success = !(
anyTestFailures ||
aggregatedResults.snapshot.failure ||
anyReporterErrors
);

this._cacheTestResults(aggregatedResults);
return aggregatedResults;
});
Expand Down

2 comments on commit b9a3c8c

@tushardhole
Copy link

@tushardhole tushardhole commented on b9a3c8c Nov 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lazywithclass @okonet This not failing on my machine as well as CI of my project. Curious to know how it will perform exit with exit code 1, as i do not see process.exit(1). Also i was not able to figure out who reads this value -> aggregatedResults.success

Any help is much appreciated..

Thanks..

@tushardhole
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This worked after clean install to 17.0.2, but still curious to know where is aggregatedResults.success used. Thanks for this fix, it helped.

Please sign in to comment.