Skip to content

Commit cdddd21

Browse files
authored
chore(test): add ASI script test (#592)
This verifies that the behavior is the same as in the old shell.
1 parent a83b40f commit cdddd21

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,16 @@ describe('e2e', function() {
416416
shell.assertContainsOutput("{ _id: 'xyz', totalSaleAmount: 150 }");
417417
});
418418
});
419+
420+
it('treats piping a script into stdin line by line', async() => {
421+
// This script doesn't work if evaluated as a whole, only when evaluated
422+
// line-by-line, due to Automatic Semicolon Insertion (ASI).
423+
createReadStream(path.resolve(__dirname, 'fixtures', 'asi-script.js'))
424+
.pipe(shell.process.stdin);
425+
await eventually(() => {
426+
shell.assertContainsOutput('admin;system.version;');
427+
});
428+
});
419429
});
420430

421431
describe('Node.js builtin APIs in the shell', () => {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* eslint-disable */
2+
print("Database Name;Collection Name;Documents;Documents Size;Documents Avg;Indexes;Index Size;Index Avg")
3+
db.getSiblingDB('admin').runCommand({ listDatabases: 1, nameOnly: true }).databases.forEach(function (d) {
4+
if ( ["local", "config"].indexOf(d.name) > -1 ) { return; }
5+
var curr_db = db.getSiblingDB(d.name);
6+
curr_db.getCollectionNames().forEach(function(coll) {
7+
var c = curr_db.getCollection(coll);
8+
if ( typeof c != "function") {
9+
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);
10+
}
11+
});
12+
});

0 commit comments

Comments
 (0)