Skip to content

Commit bf76379

Browse files
authored
chore(cli-repl): add async-rewriter library integration test (#767)
Load lodash (all of it) and moment.js into the shell and perform a basic test that verifies that they can be used with the new async rewriter.
1 parent 84c32bd commit bf76379

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

packages/cli-repl/package-lock.json

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

packages/cli-repl/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@
7575
"@types/read": "^0.0.28",
7676
"@types/text-table": "^0.2.1",
7777
"@types/yargs-parser": "^15.0.0",
78-
"chai-as-promised": "^7.1.1"
78+
"chai-as-promised": "^7.1.1",
79+
"lodash": "^4.17.21",
80+
"moment": "^2.29.1"
7981
},
8082
"optionalDependencies": {
8183
"macos-export-certificate-and-key": "^1.0.0",

packages/cli-repl/test/e2e.spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,34 @@ describe('e2e', function() {
364364
expect(result).to.include('{ _id: 1, value: 4 }');
365365
});
366366

367+
it('rewrites async properly for common libraries', async function() {
368+
this.timeout(120_000);
369+
// This is being run under the new async rewriter because the old one
370+
// did not support these libraries at all (for various reasons).
371+
// Once the new async rewriter is the default, this block can be removed.
372+
shell = TestShell.start({
373+
args: [ await testServer.connectionString() ],
374+
env: { ...process.env, MONGOSH_ASYNC_REWRITER2: '1' }
375+
});
376+
await shell.waitForPrompt();
377+
shell.assertNoErrors();
378+
379+
await shell.executeLine('Date.now = () => new Date().getTime()'); // MONGOSH-597 hack
380+
await shell.executeLine(`use ${dbName}`);
381+
await shell.executeLine('db.test.insertOne({ d: new Date("2021-04-07T11:24:54+02:00") })');
382+
shell.writeInputLine(`load(${JSON.stringify(require.resolve('lodash'))})`);
383+
shell.writeInputLine(`load(${JSON.stringify(require.resolve('moment'))})`);
384+
shell.writeInputLine('print("loaded" + "scripts")');
385+
await eventually(() => {
386+
// Use eventually explicitly to get a bigger timeout, lodash is
387+
// quite “big” in terms of async rewriting
388+
shell.assertContainsOutput('loadedscripts');
389+
}, { timeout: 60_000 });
390+
const result = await shell.executeLine(
391+
'moment(_.first(_.map(db.test.find().toArray(), "d"))).format("X")');
392+
expect(result).to.include('1617787494');
393+
});
394+
367395
it('expands explain output indefinitely', async() => {
368396
await shell.executeLine('explainOutput = db.test.find().explain()');
369397
await shell.executeLine('explainOutput.a = {b:{c:{d:{e:{f:{g:{h:{i:{j:{}}}}}}}}}}');

0 commit comments

Comments
 (0)