Skip to content

Commit cf82e2c

Browse files
authored
fix(testrunner): await terminations before reporting test results (#1855)
This way we ensure that all errors are picked up.
1 parent 1912fbf commit cf82e2c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

utils/testrunner/TestRunner.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,16 +395,17 @@ class TestRunner {
395395
this._result = new Result();
396396
this._result.runs = testRuns;
397397

398+
const terminationPromises = [];
398399
const handleSIGINT = () => this._terminate(TestResult.Terminated, 'SIGINT received', false, null);
399400
const handleSIGHUP = () => this._terminate(TestResult.Terminated, 'SIGHUP received', false, null);
400401
const handleSIGTERM = () => this._terminate(TestResult.Terminated, 'SIGTERM received', true, null);
401402
const handleRejection = e => {
402403
const { message, error } = this._toError('UNHANDLED PROMISE REJECTION', e);
403-
this._terminate(TestResult.Crashed, message, false, error);
404+
terminationPromises.push(this._terminate(TestResult.Crashed, message, false, error));
404405
};
405406
const handleException = e => {
406407
const { message, error } = this._toError('UNHANDLED ERROR', e);
407-
this._terminate(TestResult.Crashed, message, false, error);
408+
terminationPromises.push(this._terminate(TestResult.Crashed, message, false, error));
408409
};
409410
process.on('SIGINT', handleSIGINT);
410411
process.on('SIGHUP', handleSIGHUP);
@@ -415,7 +416,7 @@ class TestRunner {
415416
let timeoutId;
416417
if (totalTimeout) {
417418
timeoutId = setTimeout(() => {
418-
this._terminate(TestResult.Terminated, `Total timeout of ${totalTimeout}ms reached.`, true /* force */, null /* error */);
419+
terminationPromises.push(this._terminate(TestResult.Terminated, `Total timeout of ${totalTimeout}ms reached.`, true /* force */, null /* error */));
419420
}, totalTimeout);
420421
}
421422
await this._runDelegateCallback(this._delegate.onStarted, [testRuns]);
@@ -427,6 +428,7 @@ class TestRunner {
427428
workerPromises.push(this._runWorker(initialTestRunIndex, testRuns, i));
428429
}
429430
await Promise.all(workerPromises);
431+
await Promise.all(terminationPromises);
430432

431433
if (testRuns.some(run => run.isFailure()))
432434
this._result.setResult(TestResult.Failed, '');

0 commit comments

Comments
 (0)