From bb29469856abe621275fe7bb520470a5ceb5edda Mon Sep 17 00:00:00 2001 From: Emily Stark Date: Wed, 8 Oct 2014 14:26:38 -0700 Subject: [PATCH] Replace runtime config regression selftest with simpler unit test --- packages/webapp/webapp_server.js | 10 +++++-- packages/webapp/webapp_tests.js | 22 +++++++++++++++ tools/tests/run.js | 48 -------------------------------- 3 files changed, 29 insertions(+), 51 deletions(-) diff --git a/packages/webapp/webapp_server.js b/packages/webapp/webapp_server.js index b4c7d9053a..694f07002f 100644 --- a/packages/webapp/webapp_server.js +++ b/packages/webapp/webapp_server.js @@ -316,8 +316,11 @@ var getBoilerplate = function (request, arch) { return memoizedBoilerplate[memHash]; }; -var generateBoilerplateInstance = function (arch, manifest, additionalOptions) { +WebAppInternals.generateBoilerplateInstance = function (arch, + manifest, + additionalOptions) { additionalOptions = additionalOptions || {}; + var runtimeConfig = _.extend( _.clone(__meteor_runtime_config__), additionalOptions.runtimeConfigOverrides || {} @@ -575,8 +578,9 @@ var runWebAppServer = function () { syncQueue.runTask(function() { _.each(WebApp.clientPrograms, function (program, archName) { boilerplateByArch[archName] = - generateBoilerplateInstance(archName, program.manifest, - defaultOptionsForArch[archName]); + WebAppInternals.generateBoilerplateInstance( + archName, program.manifest, + defaultOptionsForArch[archName]); }); // Clear the memoized boilerplate cache. diff --git a/packages/webapp/webapp_tests.js b/packages/webapp/webapp_tests.js index 358dcd563e..97df3a3dfc 100644 --- a/packages/webapp/webapp_tests.js +++ b/packages/webapp/webapp_tests.js @@ -144,3 +144,25 @@ Tinytest.add("webapp - valid pid check", function (test) { test.isFalse(WebAppInternals.validPid("foobar")); test.isFalse(WebAppInternals.validPid("123foo")); }); + +// Regression test: `generateBoilerplateInstance` should not change +// `__meteor_runtime_config__`. +Tinytest.add("webapp - generating boilerplate should not change runtime config", function (test) { + // Set a dummy key in the runtime config served in the + // boilerplate. Test that the dummy key appears in the boilerplate, + // but not in __meteor_runtime_config__ after generating the + // boilerplate. + + test.isFalse(__meteor_runtime_config__.WEBAPP_TEST_KEY); + + var boilerplate = WebAppInternals.generateBoilerplateInstance( + "web.browser", + {}, // empty manifest + { runtimeConfigOverrides: { WEBAPP_TEST_KEY: true } } + ); + + var boilerplateHtml = boilerplate.toHTML(); + test.isFalse(boilerplateHtml.indexOf("WEBAPP_TEST_KEY") === -1); + + test.isFalse(__meteor_runtime_config__.WEBAPP_TEST_KEY); +}); diff --git a/tools/tests/run.js b/tools/tests/run.js index 59c7775501..5532ff2278 100644 --- a/tools/tests/run.js +++ b/tools/tests/run.js @@ -409,51 +409,3 @@ selftest.define("'meteor run --port' requires a port", function () { run.matchErr("--port must include a port"); run.expectExit(1); }); - -// Regression test: previously, if ROOT_URL was set, then the process of -// generating the cordova boilerplate would change -// __meteor_runtime_config__, resulting in an incorrect browser -// boilerplate being generated the next time boilerplate generation -// occurs. -selftest.define("generating boilerplate does not change runtime config", function () { - var s = new Sandbox(); - var run; - - s.createApp("myapp", "standard-app"); - s.cd("myapp"); - - // Add 'android' to the .meteor/platforms file, just so that the - // Cordova boilerplate will be generated and served, without having - // to download the whole Android sdk. - var platforms = s.read(".meteor/platforms"); - s.write(".meteor/platforms", platforms + "\nandroid\n"); - - s.set("ROOT_URL", "http://127.0.0.1:3000"); - run = s.run(); - run.waitSecs(30); - run.match("Started your app"); - - var body = httpHelpers.getUrl("http://localhost:3000"); - var rootUrlRegExp = /"ROOT_URL":"http:\/\/127.0.0.1:3000"/; - if (! body.match(rootUrlRegExp)) { - selftest.fail("Incorrect ROOT_URL"); - } - - s.mkdir("client"); - s.cd("client"); - s.write("foo.js", "console.log(1);\n"); - - run.waitSecs(30); - // We don't expect the server to restart; we're testing that - // __meteor_runtime_config__ does not get modified over the life of - // a single server process. - run.forbidAll("restarted"); - run.match("Client modified"); - - body = httpHelpers.getUrl("http://localhost:3000"); - if (! body.match(rootUrlRegExp)) { - selftest.fail("Incorrect ROOT_URL after modifying client"); - } - - run.stop(); -});