Skip to content

Commit 64e90fc

Browse files
committed
chore(e2e-test): add regression test for dynamic import() MONGOSH-1062
1 parent 8421ecc commit 64e90fc

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,22 +1170,39 @@ 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+
it('import() works when interleaved with GC', async function () {
1199+
await shell.executeLine('importESM = () => import("b-esm")');
1200+
expect(await shell.executeLine('globalThis.gc(); "ran gc"')).to.include(
1201+
'ran gc'
1202+
);
1203+
const result = await shell.executeLine('importESM().then(m => m.value)');
1204+
expect(result).to.match(/^B-ESM$/m);
1205+
shell.assertNoErrors();
11891206
});
11901207

11911208
it('Can use Node.js APIs without any extra effort', async function () {
@@ -1194,6 +1211,7 @@ describe('e2e', function () {
11941211
`fs.readFileSync(${JSON.stringify(__filename)}, 'utf8')`
11951212
);
11961213
expect(result).to.include('Too lazy to write a fixture');
1214+
shell.assertNoErrors();
11971215
});
11981216
});
11991217

0 commit comments

Comments
 (0)