Skip to content

Commit

Permalink
Fix Node.js 8 and 6 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Aug 24, 2022
1 parent b08d515 commit fae9608
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/babel-core/test/errors-stacks.js
@@ -1,5 +1,8 @@
import * as babel from "../lib/index.js";

// TODO: Remove this in Babel 8, once we drop Node.js 8
import { URL } from "url";

const replaceAll = "".replaceAll
? Function.call.bind("".replaceAll)
: (str, find, replace) => str.split(find).join(replace);
Expand Down Expand Up @@ -33,6 +36,7 @@ function expectError(run) {
// are quite different from newer stack traces.
// TODO(Babel 8): Delete this code
{
// Node.js <= 10
stack = replaceAll(stack, "Object.parseSync", "Module.parseSync");
stack = stack.replace(
/(?:run|Object\.<anonymous>) \((<CWD>[^)]+)\)/g,
Expand All @@ -48,6 +52,13 @@ function expectError(run) {
"\n at ... internal jest frames ...\n at new Promise (<anonymous>)",
"",
);
// Node.js 8
stack = stack.replace(/\n\s*at <anonymous>$/g, "");
// Node.js 6
stack = stack.replace(
/(at (\w+) \([^)]+\)\n\s*at) next \(native\)/g,
"$1 $2.next (<anonymous>)",
);
}

return expect(stack);
Expand Down

0 comments on commit fae9608

Please sign in to comment.