From c49a441d3d199a46db475bfb8c226a426bec3217 Mon Sep 17 00:00:00 2001 From: David Glasser Date: Mon, 1 Dec 2014 12:36:09 -0800 Subject: [PATCH] self-test: prepare apps after createApp This means that the first command won't need to do a big build (and print lots of package changed notifications). Similar to what 'meteor create' does. Also add --prepare-app command. --- tools/commands-packages.js | 19 +++++++++++++++++++ tools/selftest.js | 23 +++++++++++++++++++++-- tools/tests/autoupdate.js | 5 ++--- tools/tests/npm.js | 2 +- tools/tests/releases.js | 2 +- tools/tests/report-stats.js | 7 +++---- tools/tests/run.js | 3 +-- 7 files changed, 48 insertions(+), 13 deletions(-) diff --git a/tools/commands-packages.js b/tools/commands-packages.js index e65e7f6ce19..a2c3c937f09 100644 --- a/tools/commands-packages.js +++ b/tools/commands-packages.js @@ -158,6 +158,25 @@ main.registerCommand({ }); +// Internal use only. A simpler version of --get-ready which doesn't try to also +// build/download local and release packages that aren't currently used. Just +// builds and downloads packages used by the current app. +main.registerCommand({ + name: '--prepare-app', + pretty: true, + requiresApp: true, + catalogRefresh: new catalog.Refresh.OnceAtStart({ ignoreErrors: false }) +}, function (options) { + var projectContext = new projectContextModule.ProjectContext({ + projectDir: options.appDir + }); + main.captureAndExit("=> Errors while initializing project:", function () { + projectContext.prepareProjectForBuild(); + }); + projectContext.packageMapDelta.displayOnConsole(); +}); + + /////////////////////////////////////////////////////////////////////////////// // publish a package /////////////////////////////////////////////////////////////////////////////// diff --git a/tools/selftest.js b/tools/selftest.js index f1f3f0e0f1f..33718c4c107 100644 --- a/tools/selftest.js +++ b/tools/selftest.js @@ -561,16 +561,35 @@ _.extend(Sandbox.prototype, { // For example: // s.createApp('myapp', 'empty'); // s.cd('myapp'); - createApp: function (to, template) { + createApp: function (to, template, options) { var self = this; + options = options || {}; files.cp_r(path.join(__dirname, 'tests', 'apps', template), path.join(self.cwd, to), { ignore: [/^local$/] }); // If the test isn't explicitly managing a mock warehouse, ensure that apps // run with our release by default. - if (!self.warehouse && release.current.isProperRelease()) { + if (options.release) { + self.write(path.join(to, '.meteor/release'), options.release); + } else if (!self.warehouse && release.current.isProperRelease()) { self.write(path.join(to, '.meteor/release'), release.current.name); } + + if (options.dontPrepareApp) + return; + + // Prepare the app (ie, build or download packages). We give this a nice + // long timeout, which allows the next command to not need a bloated + // timeout. (meteor create does this anyway.) + self.cd(to, function () { + var run = self.run("--prepare-app"); + // XXX Can we cache the output of running this once somewhere, so that + // multiple calls to createApp with the same template get the same cache? + // This is a little tricky because isopack-buildinfo.json uses absolute + // paths. + run.waitSecs(20); + run.expectExit(0); + }); }, // Same as createApp, but with a package. diff --git a/tools/tests/autoupdate.js b/tools/tests/autoupdate.js index 9a464114b97..27364e2515a 100644 --- a/tools/tests/autoupdate.js +++ b/tools/tests/autoupdate.js @@ -48,17 +48,16 @@ selftest.define("autoupdate", ['checkout'], function () { // manages to run. So stop mongo from starting so that it goes faster. s.set("MONGO_URL", "whatever"); - s.createApp('myapp', 'packageless'); + s.createApp('myapp', 'packageless', { release: 'METEOR@v2' }); s.cd('myapp', function () { setBanner(s, "v2", "=> New hotness v2 being downloaded.\n"); - s.write('.meteor/release', 'METEOR@v2'); // console.log("WE ARE READY NOW", s.warehouse, s.cwd) // require('../utils.js').sleepMs(1000*10000) // Run it and see the banner for the current version. run = s.run("--port", "21000"); - run.waitSecs(5); + run.waitSecs(30); run.match("New hotness v2 being downloaded"); run.match("running at"); run.stop(); diff --git a/tools/tests/npm.js b/tools/tests/npm.js index bae1219d4b2..a5347772625 100644 --- a/tools/tests/npm.js +++ b/tools/tests/npm.js @@ -13,7 +13,7 @@ selftest.define("npm", ["net"], function () { var s = new Sandbox({ fakeMongo: true }); var run; - s.createApp("npmtestapp", "npmtest"); + s.createApp("npmtestapp", "npmtest", { dontPrepareApp: true }); s.cd("npmtestapp"); // Ensure that we don't lose the executable bits of npm modules. diff --git a/tools/tests/releases.js b/tools/tests/releases.js index 040c177f5e5..5460578be2d 100644 --- a/tools/tests/releases.js +++ b/tools/tests/releases.js @@ -220,7 +220,7 @@ selftest.define("unknown release", [], function () { s.set("METEOR_OFFLINE_CATALOG", "t"); var run; - s.createApp('myapp', 'packageless'); + s.createApp('myapp', 'packageless', { dontPrepareApp: true }); s.cd('myapp'); run = s.run("--release", "bad"); run.matchErr("Meteor bad: unknown release"); diff --git a/tools/tests/report-stats.js b/tools/tests/report-stats.js index 97ca60aeb54..a0469437cf0 100644 --- a/tools/tests/report-stats.js +++ b/tools/tests/report-stats.js @@ -47,11 +47,10 @@ selftest.define("report-stats", ["slow", "net"], function () { var run; - s.createApp("foo", "package-stats-tests"); + s.createApp("foo", "package-stats-tests", { + release: useFakeRelease ? 'METEOR@v1' : undefined + }); s.cd("foo"); - if (useFakeRelease) { - s.write('.meteor/release', 'METEOR@v1'); - } var projectContext = new projectContextModule.ProjectContext({ projectDir: s.cwd diff --git a/tools/tests/run.js b/tools/tests/run.js index 840cb3bc70e..2c786e233d0 100644 --- a/tools/tests/run.js +++ b/tools/tests/run.js @@ -226,11 +226,10 @@ selftest.define("update during run", ["checkout"], function () { }); var run; - s.createApp("myapp", "packageless"); + s.createApp("myapp", "packageless", { release: 'METEOR@v1' }); s.cd("myapp"); // If the app version changes, we exit with an error message. - s.write('.meteor/release', 'METEOR@v1'); run = s.run(); run.tellMongo(MONGO_LISTENING); run.waitSecs(10);