@samitouri / QOS-React-2 / commits / 5e0dba9012

[test262] Always return a pseudo Error object

For unknown reasons I didn't have the energy to dig into, some Babel Error objects can't be written to so despite formatting the error message, the original one would still be used. To get around this I'm just constructing a fake object with a `name` and `message` so the correctly formatted messages are used.

Lauren Tan committed Dec 22, 2022 at 17:40 UTC 5e0dba9012af93733c07ca143be2d32fa1befb15
1 file changed +11 -5
compiler/forget/scripts/test262-preprocessor.js
+11 -5
@@ -16,13 +16,19 @@ module.exports = (test) => {
16 }
17 } catch (error) {
18 // We use the `stderr` output to group errors so we can count them, so we need to dedupe errors
19 - // that are the same but differ slightly
20 - error.message = error.message.replace(/ \(\d+:\d+\)/, ""); // some errors report line numbers
21 - error.message = error.message.replace(/\/.*\.js:\s/, ""); // babel seems to output filenames
19 + // that are the same but differ slightly.
20 + let { name, message } = error;
21 + message = message.replace(/\/.*\.js:\s/, ""); // babel seems to output filenames
22 + message = message.split(/\(\d+:\d+\)/)[0]; // some errors report line numbers and codeframes
23 + message = message.trim();
24 +
25 + // For unknown reasons I don't have the energy to dig into some Babel error instances can't be
26 + // written to, so we construct a psedudo object here so the correctly formatted error messages
27 + // are emitted
28 test.result = {
23 - stderr: `${error.name}: ${error.message}\n`,
29 + stderr: `${name}: ${message}\n`,
30 stdout: "",
25 - error,
31 + error: { name, message },
32 };
33 }
34