mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
feat(testrunner): improve reporting of unhandled errors/rejections (#1697)
This commit is contained in:
parent
a7ae205254
commit
39e06f0286
@ -383,15 +383,32 @@ class TestRunner {
|
|||||||
}, totalTimeout);
|
}, totalTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
const terminations = [
|
const handleSIGINT = () => this._terminate(TestResult.Terminated, 'SIGINT received', false, null);
|
||||||
createTermination.call(this, 'SIGINT', TestResult.Terminated, 'SIGINT received'),
|
const handleSIGHUP = () => this._terminate(TestResult.Terminated, 'SIGHUP received', false, null);
|
||||||
createTermination.call(this, 'SIGHUP', TestResult.Terminated, 'SIGHUP received'),
|
const handleSIGTERM = () => this._terminate(TestResult.Terminated, 'SIGTERM received', true, null);
|
||||||
createTermination.call(this, 'SIGTERM', TestResult.Terminated, 'SIGTERM received'),
|
const handleRejection = error => {
|
||||||
createTermination.call(this, 'unhandledRejection', TestResult.Crashed, 'UNHANDLED PROMISE REJECTION'),
|
let message = 'UNHANDLED PROMISE REJECTION';
|
||||||
createTermination.call(this, 'uncaughtException', TestResult.Crashed, 'UNHANDLED ERROR'),
|
if (!(error instanceof Error)) {
|
||||||
];
|
message += ': ' + error;
|
||||||
for (const termination of terminations)
|
error = new Error();
|
||||||
process.on(termination.event, termination.handler);
|
error.stack = '';
|
||||||
|
}
|
||||||
|
this._terminate(TestResult.Crashed, message, false, error);
|
||||||
|
};
|
||||||
|
const handleException = error => {
|
||||||
|
let message = 'UNHANDLED ERROR';
|
||||||
|
if (!(error instanceof Error)) {
|
||||||
|
message += ': ' + error;
|
||||||
|
error = new Error();
|
||||||
|
error.stack = '';
|
||||||
|
}
|
||||||
|
this._terminate(TestResult.Crashed, message, false, error);
|
||||||
|
};
|
||||||
|
process.on('SIGINT', handleSIGINT);
|
||||||
|
process.on('SIGHUP', handleSIGHUP);
|
||||||
|
process.on('SIGTERM', handleSIGTERM);
|
||||||
|
process.on('unhandledRejection', handleRejection);
|
||||||
|
process.on('uncaughtException', handleException);
|
||||||
|
|
||||||
const workerCount = Math.min(parallel, testRuns.length);
|
const workerCount = Math.min(parallel, testRuns.length);
|
||||||
const workerPromises = [];
|
const workerPromises = [];
|
||||||
@ -401,8 +418,11 @@ class TestRunner {
|
|||||||
}
|
}
|
||||||
await Promise.all(workerPromises);
|
await Promise.all(workerPromises);
|
||||||
|
|
||||||
for (const termination of terminations)
|
process.removeListener('SIGINT', handleSIGINT);
|
||||||
process.removeListener(termination.event, termination.handler);
|
process.removeListener('SIGHUP', handleSIGHUP);
|
||||||
|
process.removeListener('SIGTERM', handleSIGTERM);
|
||||||
|
process.removeListener('unhandledRejection', handleRejection);
|
||||||
|
process.removeListener('uncaughtException', handleException);
|
||||||
|
|
||||||
if (testRuns.some(run => run.isFailure()))
|
if (testRuns.some(run => run.isFailure()))
|
||||||
this._result.setResult(TestResult.Failed, '');
|
this._result.setResult(TestResult.Failed, '');
|
||||||
@ -410,14 +430,6 @@ class TestRunner {
|
|||||||
clearTimeout(timeoutId);
|
clearTimeout(timeoutId);
|
||||||
await this._delegate.onFinished(this._result);
|
await this._delegate.onFinished(this._result);
|
||||||
|
|
||||||
function createTermination(event, result, message) {
|
|
||||||
return {
|
|
||||||
event,
|
|
||||||
message,
|
|
||||||
handler: error => this._terminate(result, message, event === 'SIGTERM', event.startsWith('SIG') ? null : error),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = this._result;
|
const result = this._result;
|
||||||
this._result = null;
|
this._result = null;
|
||||||
this._workers = [];
|
this._workers = [];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user