Skip to content

Commit 5e1f1bc

Browse files
authored
Fix failing Node.js 20 tests (#17191)
* add itSatisfies, itNegate and describeSatisfies * replace ">=22.12.0" by "^20.19.0 || >= 22.12.0" * update helper-define-polyfill-provider * update test fixtures * small cleanup to retry CI * Revert "small cleanup to retry CI" This reverts commit 7ebc905. * try builtin npm version * use versionHasRequireESM
1 parent d6c5081 commit 5e1f1bc

14 files changed

Lines changed: 170 additions & 143 deletions

File tree

eslint.config.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,12 @@ export default [
278278
"itNoESM",
279279
"itNoWin32",
280280
"itESM",
281+
"itNegate",
282+
"itSatisfies",
281283
"nodeGte8",
282284
"nodeGte14",
283285
"nodeGte12",
284286
"nodeGte20",
285-
"nodeGte22_12",
286-
"nodeLt22_12",
287287
"nodeLt23_6",
288288
"nodeGte23_6",
289289
"nodeGte12NoESM",

packages/babel-core/test/async.js

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@ import {
99
supportsESM,
1010
} from "./helpers/esm.js";
1111

12-
import { itGte, itESM, itLt } from "$repo-utils";
12+
import { itGte, itESM, itNegate, itSatisfies } from "$repo-utils";
1313

1414
// "minNodeVersion": "8.0.0" <-- For Ctrl+F when dropping node 6
1515
const nodeGte8 = itGte("8.0.0");
1616
const nodeGte14 = itGte("14.8.0");
1717

1818
// "minNodeVersion": "22.0.0" <-- For Ctrl+F when dropping node 20
19-
const nodeGte22_12 = itGte("22.12.0");
20-
const nodeLt22_12 = itLt("22.12.0");
19+
const versionHasRequireESM = "^20.19.0 || >= 22.12.0";
2120

2221
describe("asynchronicity", () => {
2322
const base = path.join(
@@ -252,16 +251,19 @@ describe("asynchronicity", () => {
252251
});
253252

254253
(supportsESM ? describe : describe.skip)(".mjs files", () => {
255-
nodeLt22_12("called synchronously", async () => {
256-
process.chdir("plugin-mjs-native");
254+
itNegate(itSatisfies(versionHasRequireESM))(
255+
"called synchronously",
256+
async () => {
257+
process.chdir("plugin-mjs-native");
257258

258-
await expect(spawnTransformSync()).rejects.toThrow(
259-
`[BABEL]: You appear to be using a native ECMAScript module plugin, which is` +
260-
` only supported when running Babel asynchronously`,
261-
);
262-
});
259+
await expect(spawnTransformSync()).rejects.toThrow(
260+
`[BABEL]: You appear to be using a native ECMAScript module plugin, which is` +
261+
` only supported when running Babel asynchronously`,
262+
);
263+
},
264+
);
263265

264-
nodeGte22_12("called asynchronously", async () => {
266+
itSatisfies(versionHasRequireESM)("called asynchronously", async () => {
265267
process.chdir("plugin-mjs-native");
266268

267269
await expect(spawnTransformSync()).resolves.toMatchObject({
@@ -344,16 +346,19 @@ describe("asynchronicity", () => {
344346
});
345347

346348
(supportsESM ? describe : describe.skip)(".mjs files", () => {
347-
nodeLt22_12("called synchronously", async () => {
348-
process.chdir("preset-mjs-native");
349+
itNegate(itSatisfies(versionHasRequireESM))(
350+
"called synchronously",
351+
async () => {
352+
process.chdir("preset-mjs-native");
349353

350-
await expect(spawnTransformSync()).rejects.toThrow(
351-
`[BABEL]: You appear to be using a native ECMAScript module preset, which is` +
352-
` only supported when running Babel asynchronously`,
353-
);
354-
});
354+
await expect(spawnTransformSync()).rejects.toThrow(
355+
`[BABEL]: You appear to be using a native ECMAScript module preset, which is` +
356+
` only supported when running Babel asynchronously`,
357+
);
358+
},
359+
);
355360

356-
nodeGte22_12("called synchronously", async () => {
361+
itSatisfies(versionHasRequireESM)("called synchronously", async () => {
357362
process.chdir("preset-mjs-native");
358363

359364
await expect(spawnTransformSync()).resolves.toMatchObject({

packages/babel-core/test/config-chain.js

Lines changed: 50 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@ import path from "path";
44
import { fileURLToPath } from "url";
55
import * as babel from "../lib/index.js";
66
import rimraf from "rimraf";
7-
import { itBabel7, itBabel8, itGte, itLt } from "$repo-utils";
7+
import { itBabel7, itBabel8, itSatisfies, itNegate } from "$repo-utils";
88

99
import _getTargets from "@babel/helper-compilation-targets";
1010
const getTargets = _getTargets.default || _getTargets;
1111

1212
const dirname = path.dirname(fileURLToPath(import.meta.url));
1313

1414
// "minNodeVersion": "22.0.0" <-- For Ctrl+F when dropping node 20
15-
const nodeGte22_12 = itGte("22.12.0");
16-
const nodeLt22_12 = itLt("22.12.0");
15+
const versionHasRequireESM = "^20.19.0 || >= 22.12.0";
1716

1817
import { isMJS, loadOptionsAsync, skipUnsupportedESM } from "./helpers/esm.js";
1918

@@ -1169,7 +1168,7 @@ describe("buildConfigChain", function () {
11691168
},
11701169
);
11711170

1172-
nodeLt22_12(
1171+
itNegate(itSatisfies(versionHasRequireESM))(
11731172
"should not load babel.config.mjs synchronously",
11741173
async () => {
11751174
const { cwd, tmp, config } = await getTemp(
@@ -1185,22 +1184,25 @@ describe("buildConfigChain", function () {
11851184
},
11861185
);
11871186

1188-
nodeGte22_12("should load babel.config.mjs synchronously", async () => {
1189-
const { cwd, tmp, config } = await getTemp(
1190-
"babel-test-load-config-sync-babel.config.mjs",
1191-
);
1192-
const filename = tmp("src.js");
1187+
itSatisfies(versionHasRequireESM)(
1188+
"should load babel.config.mjs synchronously",
1189+
async () => {
1190+
const { cwd, tmp, config } = await getTemp(
1191+
"babel-test-load-config-sync-babel.config.mjs",
1192+
);
1193+
const filename = tmp("src.js");
11931194

1194-
await config("babel.config.mjs");
1195+
await config("babel.config.mjs");
11951196

1196-
expect(loadOptionsSync({ filename, cwd })).toEqual({
1197-
...getDefaults(),
1198-
filename,
1199-
cwd,
1200-
root: cwd,
1201-
comments: true,
1202-
});
1203-
});
1197+
expect(loadOptionsSync({ filename, cwd })).toEqual({
1198+
...getDefaults(),
1199+
filename,
1200+
cwd,
1201+
root: cwd,
1202+
comments: true,
1203+
});
1204+
},
1205+
);
12041206

12051207
test.each([
12061208
"babel.config.json",
@@ -1285,35 +1287,41 @@ describe("buildConfigChain", function () {
12851287
});
12861288
});
12871289

1288-
nodeLt22_12("should not load .babelrc.mjs synchronously", async () => {
1289-
const { cwd, tmp, config } = await getTemp(
1290-
"babel-test-load-config-sync-.babelrc.mjs",
1291-
);
1292-
const filename = tmp("src.js");
1290+
itNegate(itSatisfies(versionHasRequireESM))(
1291+
"should not load .babelrc.mjs synchronously",
1292+
async () => {
1293+
const { cwd, tmp, config } = await getTemp(
1294+
"babel-test-load-config-sync-.babelrc.mjs",
1295+
);
1296+
const filename = tmp("src.js");
12931297

1294-
await config(".babelrc.mjs");
1298+
await config(".babelrc.mjs");
12951299

1296-
expect(() => loadOptionsSync({ filename, cwd })).toThrow(
1297-
/is only supported when running Babel asynchronously/,
1298-
);
1299-
});
1300+
expect(() => loadOptionsSync({ filename, cwd })).toThrow(
1301+
/is only supported when running Babel asynchronously/,
1302+
);
1303+
},
1304+
);
13001305

1301-
nodeGte22_12("should load .babelrc.mjs synchronously", async () => {
1302-
const { cwd, tmp, config } = await getTemp(
1303-
"babel-test-load-config-sync-.babelrc.mjs",
1304-
);
1305-
const filename = tmp("src.js");
1306+
itSatisfies(versionHasRequireESM)(
1307+
"should load .babelrc.mjs synchronously",
1308+
async () => {
1309+
const { cwd, tmp, config } = await getTemp(
1310+
"babel-test-load-config-sync-.babelrc.mjs",
1311+
);
1312+
const filename = tmp("src.js");
13061313

1307-
await config(".babelrc.mjs");
1314+
await config(".babelrc.mjs");
13081315

1309-
expect(loadOptionsSync({ filename, cwd })).toEqual({
1310-
...getDefaults(),
1311-
filename,
1312-
cwd,
1313-
root: cwd,
1314-
comments: true,
1315-
});
1316-
});
1316+
expect(loadOptionsSync({ filename, cwd })).toEqual({
1317+
...getDefaults(),
1318+
filename,
1319+
cwd,
1320+
root: cwd,
1321+
comments: true,
1322+
});
1323+
},
1324+
);
13171325

13181326
test.each(
13191327
[

packages/babel-core/test/config-ts.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ const shouldSkip = semver.lt(process.version, "14.0.0");
1313
// Node.js 23.6 unflags --experimental-strip-types
1414
const nodeLt23_6 = itLt("23.6.0");
1515
const nodeGte23_6 = itGte("23.6.0");
16+
const versionHasRequireESM = "^20.19.0 || >=22.12.0";
1617

1718
const nodeLt23_6_andRequireBabelPackages =
1819
semver.lt(process.version, "23.6.0") &&
19-
(!USE_ESM || semver.gt(process.version, "22.12.0"))
20+
(!USE_ESM || semver.satisfies(process.version, versionHasRequireESM))
2021
? it
2122
: it.skip;
2223

packages/babel-core/test/esm-cjs-integration.js

Lines changed: 65 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import { execFile } from "child_process";
22
import { createRequire } from "module";
3-
import { describeESM, describeGte, itLt } from "$repo-utils";
3+
import {
4+
describeESM,
5+
describeSatisfies,
6+
itNegate,
7+
itSatisfies,
8+
} from "$repo-utils";
49

510
const require = createRequire(import.meta.url);
611

712
// "minNodeVersion": "22.0.0" <-- For Ctrl+F when dropping node 20
8-
const nodeLt22_12 = itLt("22.12.0");
13+
const versionHasRequireESM = "^20.19.0 || >=22.12.0";
914

1015
async function run(name, ...flags) {
1116
return new Promise((res, rej) => {
@@ -116,61 +121,70 @@ describeESM("usage from cjs", () => {
116121
});
117122

118123
describeESM("sync loading of ESM plugins", () => {
119-
nodeLt22_12("without --experimental-require-module flag", async () => {
120-
await expect(run("transform-sync-esm-plugin.mjs")).rejects.toThrow(
121-
"You appear to be using a native ECMAScript module plugin, which is " +
122-
"only supported when running Babel asynchronously or when using the " +
123-
"Node.js `--experimental-require-module` flag.",
124-
);
125-
});
126-
127-
describeGte("22.12.0")("without --experimental-require-module flag", () => {
128-
it("sync", async () => {
129-
const { stdout } = await run(
130-
"transform-sync-esm-plugin.mjs",
131-
"--experimental-require-module",
124+
itNegate(itSatisfies(versionHasRequireESM))(
125+
"without --experimental-require-module flag",
126+
async () => {
127+
await expect(run("transform-sync-esm-plugin.mjs")).rejects.toThrow(
128+
"You appear to be using a native ECMAScript module plugin, which is " +
129+
"only supported when running Babel asynchronously or when using the " +
130+
"Node.js `--experimental-require-module` flag.",
132131
);
133-
expect(stdout).toMatchInlineSnapshot(`
132+
},
133+
);
134+
135+
describeSatisfies(versionHasRequireESM)(
136+
"without --experimental-require-module flag",
137+
() => {
138+
it("sync", async () => {
139+
const { stdout } = await run(
140+
"transform-sync-esm-plugin.mjs",
141+
"--experimental-require-module",
142+
);
143+
expect(stdout).toMatchInlineSnapshot(`
134144
"\\"Replaced!\\";
135145
"
136146
`);
137-
});
138-
139-
it("top-level await", async () => {
140-
await expect(
141-
run(
142-
"transform-sync-esm-plugin-tla.mjs",
147+
});
148+
149+
it("top-level await", async () => {
150+
await expect(
151+
run(
152+
"transform-sync-esm-plugin-tla.mjs",
153+
"--experimental-require-module",
154+
),
155+
).rejects.toThrow(
156+
"You appear to be using a plugin that contains top-level await, " +
157+
"which is only supported when running Babel asynchronously.",
158+
);
159+
});
160+
},
161+
);
162+
163+
describeSatisfies(">=20.0.0 < 20.19.0")(
164+
"with --experimental-require-module flag",
165+
() => {
166+
it("sync with --experimental-require-module flag", async () => {
167+
const { stdout } = await run(
168+
"transform-sync-esm-plugin.mjs",
143169
"--experimental-require-module",
144-
),
145-
).rejects.toThrow(
146-
"You appear to be using a plugin that contains top-level await, " +
147-
"which is only supported when running Babel asynchronously.",
148-
);
149-
});
150-
});
151-
152-
describeGte("20.0.0")("with --experimental-require-module flag", () => {
153-
it("sync with --experimental-require-module flag", async () => {
154-
const { stdout } = await run(
155-
"transform-sync-esm-plugin.mjs",
156-
"--experimental-require-module",
157-
);
158-
expect(stdout).toMatchInlineSnapshot(`
170+
);
171+
expect(stdout).toMatchInlineSnapshot(`
159172
"\\"Replaced!\\";
160173
"
161174
`);
162-
});
163-
164-
it("top-level await with --experimental-require-module flag", async () => {
165-
await expect(
166-
run(
167-
"transform-sync-esm-plugin-tla.mjs",
168-
"--experimental-require-module",
169-
),
170-
).rejects.toThrow(
171-
"You appear to be using a plugin that contains top-level await, " +
172-
"which is only supported when running Babel asynchronously.",
173-
);
174-
});
175-
});
175+
});
176+
177+
it("top-level await with --experimental-require-module flag", async () => {
178+
await expect(
179+
run(
180+
"transform-sync-esm-plugin-tla.mjs",
181+
"--experimental-require-module",
182+
),
183+
).rejects.toThrow(
184+
"You appear to be using a plugin that contains top-level await, " +
185+
"which is only supported when running Babel asynchronously.",
186+
);
187+
});
188+
},
189+
);
176190
});

packages/babel-preset-env/test/fixtures/corejs2-babel-7/usage-regenerator-used-async/output.mjs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@ import "core-js/modules/es6.object.to-string.js";
44
import "core-js/modules/es6.promise.js";
55
import "core-js/modules/es6.object.define-property.js";
66
import "core-js/modules/es6.symbol.js";
7-
import "core-js/modules/es6.string.iterator.js";
8-
import "core-js/modules/es6.array.iterator.js";
9-
import "core-js/modules/web.dom.iterable.js";
10-
import "core-js/modules/es7.symbol.async-iterator.js";
117
import "core-js/modules/es6.object.create.js";
128
import "core-js/modules/es6.object.get-prototype-of.js";
139
import "core-js/modules/es6.array.for-each.js";
1410
import "core-js/modules/es6.function.name.js";
1511
import "core-js/modules/es6.object.set-prototype-of.js";
1612
import "core-js/modules/es6.array.slice.js";
13+
import "core-js/modules/es6.string.iterator.js";
14+
import "core-js/modules/es6.array.iterator.js";
15+
import "core-js/modules/web.dom.iterable.js";
1716
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
1817
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
1918
function a() {

0 commit comments

Comments
 (0)