Skip to content
Merged
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
10 changes: 10 additions & 0 deletions packages/cli-repl/test/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
12 changes: 12 additions & 0 deletions packages/cli-repl/test/fixtures/asi-script.js
Original file line number Diff line number Diff line change
@@ -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);
}
});
});