Skip to content

chore(e2e-test): add regression test for dynamic import() MONGOSH-1062 #2458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions packages/e2e-tests/test/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1170,22 +1170,39 @@ describe('e2e', function () {
env: {
...process.env,
NODE_PATH: path.resolve(__dirname, 'fixtures', 'node-path'),
NODE_OPTIONS: '--expose-gc',
},
});
await shell.waitForPrompt();
shell.assertNoErrors();
});

it('require() searches the current working directory according to Node.js rules', async function () {
let result;
it('require() and import() search the current working directory according to Node.js rules', async function () {
let result: string;
result = await shell.executeLine('require("a")');
expect(result).to.match(/Error: Cannot find module 'a'/);
result = await shell.executeLine('require("./a")');
expect(result).to.match(/^A$/m);
result = await shell.executeLine('require("b")');
expect(result).to.match(/^B$/m);
result = await shell.executeLine('require("b-esm").value');
expect(result).to.match(/^B-ESM$/m);
result = await shell.executeLine('require("c")');
expect(result).to.match(/^C$/m);
result = await shell.executeLine('import("b").then(m => m.default)');
expect(result).to.match(/^B$/m);
result = await shell.executeLine('import("b-esm").then(m => m.value)');
expect(result).to.match(/^B-ESM$/m);
});

it('import() works when interleaved with GC', async function () {
await shell.executeLine('importESM = () => import("b-esm")');
expect(await shell.executeLine('globalThis.gc(); "ran gc"')).to.include(
'ran gc'
);
const result = await shell.executeLine('importESM().then(m => m.value)');
expect(result).to.match(/^B-ESM$/m);
shell.assertNoErrors();
});

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

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.