Skip to content

Commit 86db49a

Browse files
authored
chore(e2e-test): add regression test for dynamic import() MONGOSH-1062 (#2458)
1 parent dc72a14 commit 86db49a

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

packages/e2e-tests/test/e2e.spec.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,22 +1170,40 @@ describe('e2e', function () {
11701170
env: {
11711171
...process.env,
11721172
NODE_PATH: path.resolve(__dirname, 'fixtures', 'node-path'),
1173+
NODE_OPTIONS: '--expose-gc',
11731174
},
11741175
});
11751176
await shell.waitForPrompt();
11761177
shell.assertNoErrors();
11771178
});
11781179

1179-
it('require() searches the current working directory according to Node.js rules', async function () {
1180-
let result;
1180+
it('require() and import() search the current working directory according to Node.js rules', async function () {
1181+
let result: string;
11811182
result = await shell.executeLine('require("a")');
11821183
expect(result).to.match(/Error: Cannot find module 'a'/);
11831184
result = await shell.executeLine('require("./a")');
11841185
expect(result).to.match(/^A$/m);
11851186
result = await shell.executeLine('require("b")');
11861187
expect(result).to.match(/^B$/m);
1188+
result = await shell.executeLine('require("b-esm").value');
1189+
expect(result).to.match(/^B-ESM$/m);
11871190
result = await shell.executeLine('require("c")');
11881191
expect(result).to.match(/^C$/m);
1192+
result = await shell.executeLine('import("b").then(m => m.default)');
1193+
expect(result).to.match(/^B$/m);
1194+
result = await shell.executeLine('import("b-esm").then(m => m.value)');
1195+
expect(result).to.match(/^B-ESM$/m);
1196+
});
1197+
1198+
// Regression test for https://github.com/nodejs/node/issues/38695
1199+
it('import() works when interleaved with GC', async function () {
1200+
await shell.executeLine('importESM = () => import("b-esm")');
1201+
expect(await shell.executeLine('globalThis.gc(); "ran gc"')).to.include(
1202+
'ran gc'
1203+
);
1204+
const result = await shell.executeLine('importESM().then(m => m.value)');
1205+
expect(result).to.match(/^B-ESM$/m);
1206+
shell.assertNoErrors();
11891207
});
11901208

11911209
it('Can use Node.js APIs without any extra effort', async function () {
@@ -1194,6 +1212,7 @@ describe('e2e', function () {
11941212
`fs.readFileSync(${JSON.stringify(__filename)}, 'utf8')`
11951213
);
11961214
expect(result).to.include('Too lazy to write a fixture');
1215+
shell.assertNoErrors();
11971216
});
11981217
});
11991218

packages/e2e-tests/test/fixtures/require-base/node_modules/b-esm/index.mjs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/e2e-tests/test/fixtures/require-base/node_modules/b-esm/package.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)