From 20326322d72765beb32960a913d622db44e2340e Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Mon, 1 Feb 2021 11:29:39 +0100 Subject: [PATCH] chore(test): add ASI script test This verifies that the behavior is the same as in the old shell. --- packages/cli-repl/test/e2e.spec.ts | 10 ++++++++++ packages/cli-repl/test/fixtures/asi-script.js | 12 ++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 packages/cli-repl/test/fixtures/asi-script.js diff --git a/packages/cli-repl/test/e2e.spec.ts b/packages/cli-repl/test/e2e.spec.ts index c9b5f9df4d..278c73a124 100644 --- a/packages/cli-repl/test/e2e.spec.ts +++ b/packages/cli-repl/test/e2e.spec.ts @@ -416,6 +416,16 @@ describe('e2e', function() { shell.assertContainsOutput("{ _id: 'xyz', totalSaleAmount: 150 }"); }); }); + + it('treats piping a script into stdin line by line', async() => { + // This script doesn't work if evaluated as a whole, only when evaluated + // line-by-line, due to Automatic Semicolon Insertion (ASI). + createReadStream(path.resolve(__dirname, 'fixtures', 'asi-script.js')) + .pipe(shell.process.stdin); + await eventually(() => { + shell.assertContainsOutput('admin;system.version;'); + }); + }); }); describe('Node.js builtin APIs in the shell', () => { diff --git a/packages/cli-repl/test/fixtures/asi-script.js b/packages/cli-repl/test/fixtures/asi-script.js new file mode 100644 index 0000000000..4f19e92719 --- /dev/null +++ b/packages/cli-repl/test/fixtures/asi-script.js @@ -0,0 +1,12 @@ +/* eslint-disable */ +print("Database Name;Collection Name;Documents;Documents Size;Documents Avg;Indexes;Index Size;Index Avg") +db.getSiblingDB('admin').runCommand({ listDatabases: 1, nameOnly: true }).databases.forEach(function (d) { + if ( ["local", "config"].indexOf(d.name) > -1 ) { return; } + var curr_db = db.getSiblingDB(d.name); + curr_db.getCollectionNames().forEach(function(coll) { + var c = curr_db.getCollection(coll); + if ( typeof c != "function") { + print(d.name + ";" + coll + ";" + c.stats().count + ";" + c.stats().size + ";" + c.stats().avgObjSize + ";" + c.stats().nindexes + ";" + c.stats().totalIndexSize + ";" + c.stats().totalIndexSize / c.stats().nindexes); + } + }); +});