Skip to content

Commit 5e991bd

Browse files
authored
add require-esm babel-register test (#17206)
1 parent e0acfea commit 5e991bd

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

packages/babel-core/test/async.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { itGte, itESM, itNegate, itSatisfies } from "$repo-utils";
1515
const nodeGte8 = itGte("8.0.0");
1616
const nodeGte14 = itGte("14.8.0");
1717

18-
// "minNodeVersion": "22.0.0" <-- For Ctrl+F when dropping node 20
18+
// "minNodeVersion": "22.0.0" <-- For Ctrl+F when dropping node 22
1919
const versionHasRequireESM = "^20.19.0 || >= 22.12.0";
2020

2121
describe("asynchronicity", () => {

packages/babel-register/test/index.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ import { Module } from "module";
22
import path from "path";
33
import fs from "fs";
44
import child from "child_process";
5-
import { USE_ESM, commonJS, describeGte } from "$repo-utils";
5+
import { USE_ESM, commonJS, describeGte, itSatisfies } from "$repo-utils";
66

77
const { __dirname, require } = commonJS(import.meta.url);
88

9+
// "minNodeVersion": "22.0.0" <-- For Ctrl+F when dropping node 22
10+
const versionHasRequireESM = "^20.19.0 || >= 22.12.0";
11+
912
const testCacheFilename = path.join(__dirname, ".index.babel");
1013
const testFile = require.resolve("./fixtures/babelrc/es2015");
1114
const testFileLog = require.resolve("./fixtures/babelrc/log");
@@ -137,7 +140,7 @@ describe("@babel/register", function () {
137140
{
138141
babelrc: true,
139142
sourceMaps: false,
140-
cwd: path.dirname(testFileMjs),
143+
cwd: path.dirname(testFile),
141144
extensions: [".js"],
142145
},
143146
proxyHandler,
@@ -150,6 +153,21 @@ describe("@babel/register", function () {
150153
expect(proxyHandler.deleteProperty).not.toHaveBeenCalled();
151154
expect(proxyHandler.set).not.toHaveBeenCalled();
152155
});
156+
157+
itSatisfies(versionHasRequireESM)(
158+
"works with mjs config files without top-level await",
159+
() => {
160+
setupRegister({
161+
babelrc: true,
162+
sourceMaps: false,
163+
cwd: path.dirname(testFileMjs),
164+
});
165+
166+
const result = currentHook(testFileMjsContent, testFileMjs);
167+
168+
expect(result).toBe('"use strict";\n\nrequire("assert");');
169+
},
170+
);
153171
});
154172
}
155173

0 commit comments

Comments
 (0)