From 8ce6a75939b8694e4dd7daf84637ab0fa08997b5 Mon Sep 17 00:00:00 2001 From: Christopher Willis-Ford <7019101+cwillisf@users.noreply.github.com> Date: Thu, 19 Oct 2023 15:33:09 -0700 Subject: [PATCH] test: strip regenerator-runtime from stack traces --- test/integration/selenium-helpers.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/test/integration/selenium-helpers.js b/test/integration/selenium-helpers.js index 0f5b700f1..033b9a755 100644 --- a/test/integration/selenium-helpers.js +++ b/test/integration/selenium-helpers.js @@ -19,6 +19,23 @@ const {By, Key, until} = webdriver; // The Jasmine default timeout is 30 seconds so make sure this is lower. const DEFAULT_TIMEOUT_MILLISECONDS = 20 * 1000; +// This removes confusing `regenerator-runtime` noise from stack traces. +// This is V8-specific code. Please don't use it in a browser or any production code. +const oldPrepareStackTrace = Error.prepareStackTrace; +Error.prepareStackTrace = function (error, stack) { + stack = stack.filter(callsite => { + const filename = callsite.getFileName(); + return filename && !filename.includes('regenerator-runtime'); + }); + if (oldPrepareStackTrace) { + return oldPrepareStackTrace(error, stack); + } + return [ + `${error.constructor.name}: ${error.message}`, + ...stack.map(callsite => ` at ${callsite.toString()}`) + ].join('\n'); +}; + /** * An error that can be chained to another error. * @extends Error @@ -88,7 +105,7 @@ class SeleniumHelperError extends ChainableError { constructor (message, kvList = []) { const baseMessage = [ message, - ...kvList.map(kv => `\t${Object.keys(kv)[0]}: ${Object.values(kv)[0]}`) + ...kvList.map(kv => ` ${Object.keys(kv)[0]}: ${Object.values(kv)[0]}`) ].join('\n'); super(baseMessage); Object.setPrototypeOf(this, SeleniumHelperError.prototype); // see https://stackoverflow.com/a/41102306