From 02c504ca59155825cec4d828bbdd2a790ffdf05f Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Thu, 9 Jan 2020 16:37:19 +0000 Subject: [PATCH] feat(testrunner): "sourcemapify" crash error stacktraces (#441) Whenever test runner crashes due to UnhandledPromiseRejection, the related error should be run through "sourcemap decoding". --- utils/testrunner/TestRunner.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/utils/testrunner/TestRunner.js b/utils/testrunner/TestRunner.js index 91aba6d9d6..dd4867f83c 100644 --- a/utils/testrunner/TestRunner.js +++ b/utils/testrunner/TestRunner.js @@ -260,7 +260,7 @@ class TestPass { test.result = TestResult.Crashed; this._runner._didFinishTest(test, workerId); if (this._breakOnFailure && test.result !== TestResult.Ok) - this._terminate(TestResult.Terminated, `Terminating because a test has failed and |testRunner.breakOnFailure| is enabled`, null); + await this._terminate(TestResult.Terminated, `Terminating because a test has failed and |testRunner.breakOnFailure| is enabled`, null); } async _runHook(workerId, suite, hookName, ...args) { @@ -273,19 +273,21 @@ class TestPass { if (error === TimeoutError) { const location = `${hook.location.fileName}:${hook.location.lineNumber}:${hook.location.columnNumber}`; const message = `${location} - Timeout Exceeded ${hook.timeout}ms while running "${hookName}" in suite "${suite.fullName}"`; - return this._terminate(TestResult.Crashed, message, null); + return await this._terminate(TestResult.Crashed, message, null); } if (error) { const location = `${hook.location.fileName}:${hook.location.lineNumber}:${hook.location.columnNumber}`; const message = `${location} - FAILED while running "${hookName}" in suite "${suite.fullName}"`; - return this._terminate(TestResult.Crashed, message, error); + return await this._terminate(TestResult.Crashed, message, error); } return false; } - _terminate(result, message, error) { + async _terminate(result, message, error) { if (this._termination) return false; + if (error && error.stack) + await this._runner._sourceMapSupport.rewriteStackTraceWithSourceMaps(error); this._termination = {result, message, error}; for (const userCallback of this._runningUserCallbacks.valuesArray()) userCallback.terminate(); @@ -408,10 +410,10 @@ class TestRunner extends EventEmitter { return result; } - terminate() { + async terminate() { if (!this._runningPass) return; - this._runningPass._terminate(TestResult.Terminated, 'Terminated with |TestRunner.terminate()| call', null); + await this._runningPass._terminate(TestResult.Terminated, 'Terminated with |TestRunner.terminate()| call', null); } timeout() {