From ba118085dc4b3a656cb29349d97dd605d878238c Mon Sep 17 00:00:00 2001 From: Jesse Rosenberger Date: Thu, 30 Nov 2017 19:15:25 +0200 Subject: [PATCH] Test which ensures that the global `_` isn't compromised. As demonstrated in https://github.com/meteor/meteor/issues/9276. This test wouldn't have caught the regression in the previous solution since the lack of a TTY in the `self-test` test harness caused the tests themselves to take the path through `shell-server`'s `evaluateAndExit` logic, which didn't use the `global` scope in the same way as the interactive shell. That is no longer the case as of e0682c553ddf0a9. --- tools/tests/apps/shell/server/main.js | 11 +++++++++++ tools/tests/shell-tests.js | 13 +++++++++++++ 2 files changed, 24 insertions(+) diff --git a/tools/tests/apps/shell/server/main.js b/tools/tests/apps/shell/server/main.js index b0dbc0ed81..8a58877acf 100644 --- a/tools/tests/apps/shell/server/main.js +++ b/tools/tests/apps/shell/server/main.js @@ -3,3 +3,14 @@ import { Meteor } from 'meteor/meteor'; Meteor.startup(() => { Meteor.checkMeFromShell = "oky dok"; }); + +// Create a global underscore variable which should be preserved, +// not overriden by the special REPL `_` variable, when a command +// is executed on the shell. The method will allow the test to call +// back and confirm it's still set. +_ = {_specialUnderscoreTestObject: true }; +Meteor.methods({ + "__meteor__/__self_test__/shell-tests/underscore"() { + return typeof _ === "object" && Object.keys(_); + } +}) diff --git a/tools/tests/shell-tests.js b/tools/tests/shell-tests.js index 8ea4c3c04c..037106c245 100644 --- a/tools/tests/shell-tests.js +++ b/tools/tests/shell-tests.js @@ -18,6 +18,19 @@ selftest.define("meteor shell", function () { shell.match('{"server":true}'); shell.expectExit(0); + shell = s.run("shell"); + // Make sure that the special Node REPL _ variable is not stomping on any + // global `_` (i.e. Underscore) since the default `repl` behavior sets the + // special variable `_` to the result of the last operation. This method + // call to the server will make sure our special `_` remains intact after + // the shell is launched. + shell.write( + "Meteor.call('__meteor__/__self_test__/shell-tests/underscore')\n"); + shell.proc.stdin.end(); + shell.waitSecs(10); + shell.match('["_specialUnderscoreTestObject"]'); + shell.expectExit(0); + shell = s.run("shell"); // Now try with a bunch of newlines in the input. shell.write("500+\n4000\n+60\n\n+\n7\n");