From 99f80949ac0ae2a4673f9432cc015f0deeb2ae99 Mon Sep 17 00:00:00 2001 From: Avital Oliver Date: Wed, 2 Jan 2013 16:54:45 -0800 Subject: [PATCH] Bundler option change: testPackages instead of include_tests Also, eliminated some dead code. This should be the last bundler change necessary for implementing `meteor test-packages` --- lib/bundler.js | 30 +++++++++++------------------- lib/tests/test_bundler.js | 17 +++++++++++++++++ 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/lib/bundler.js b/lib/bundler.js index 28403f2a27..9095df837c 100644 --- a/lib/bundler.js +++ b/lib/bundler.js @@ -125,19 +125,6 @@ var PackageInstance = function (pkg, bundle) { return _.map(ret, function (x) {return "." + x;}); }, - // Add the tests for another package. Mostly for internal - // use. Like use in that it can take either the package name or a - // package object, and can take an array. - include_tests: function (names) { - if (!(names instanceof Array)) - names = [names]; - - _.each(names, function (name) { - var pkg = packages.get(bundle.manifest, name); - self.bundle.include_tests(pkg); - }); - }, - // Report an error. It should be a single human-readable // string. If any errors are reported, the bundling is considered // to have failed. @@ -228,6 +215,9 @@ var Bundle = function () { // Packages that have had tests included. Map from package id to instance self.tests_included = {}; + // release manifest + self.manifest = null; + // map from environment, to list of filenames self.js = {client: [], server: []}; @@ -394,8 +384,9 @@ _.extend(Bundle.prototype, { pkg.on_use_handler(inst.api, where); }, - include_tests: function (pkg) { + includeTests: function (packageName) { var self = this; + var pkg = packages.get(self.manifest, packageName); if (self.tests_included[pkg.id]) return; self.tests_included[pkg.id] = true; @@ -718,7 +709,8 @@ _.extend(Bundle.prototype, { * 'symlink' : symlink from a prebuild local installation. used * by `meteor run` * - * - include_tests : include tests for the project + * - testPackages : array of package names whose tests should be included + * in this bundle * * - versionOverride : (for tests) a meteor release version to use * instead of reading from .meteor/version @@ -747,10 +739,10 @@ exports.bundle = function (app_dir, output_path, options) { bundle.use(app); // Include tests if requested - if (options.include_tests) { - // in the future, let use specify the driver, instead of hardcoding? - bundle.use(packages.get(manifest, 'test-in-browser')); - bundle.include_tests(app); + if (options.testPackages) { + _.each(options.testPackages, function(packageName) { + bundle.includeTests(packageName); + }); } // Minify, if requested diff --git a/lib/tests/test_bundler.js b/lib/tests/test_bundler.js index 4bbdbb4611..5245b4b868 100644 --- a/lib/tests/test_bundler.js +++ b/lib/tests/test_bundler.js @@ -67,6 +67,23 @@ assert.doesNotThrow(inFiber(function () { assert(!(/src=\"\/[0-9a-f]{40,40}.js\"/.test(appHtml))); assert(/src=\"\/packages\/meteor/.test(appHtml)); assert(/src=\"\/packages\/deps/.test(appHtml)); + // verify that tests aren't included + assert(!(/src=\"\/packages\/meteor\/url_tests.js/.test(appHtml))); +})); + +// versioned app, nodeModules: 'skip', noMinify, testPackages: ['meteor'] +assert.doesNotThrow(inFiber(function () { + var tmpOutputDir = tmpDir(); + var errors = bundler.bundle( + versionedAppDir, tmpOutputDir, {nodeModulesMode: 'skip', noMinify: true, testPackages: ['meteor']}); + assert.strictEqual(errors, undefined); + + // sanity check -- main.js has expected contents. + assert.strictEqual(fs.readFileSync(path.join(tmpOutputDir, "main.js"), "utf8").trim(), + "require(require('path').join(__dirname, 'server', 'server.js'));"); + // verify that tests for the meteor package are included + var appHtml = fs.readFileSync(path.join(tmpOutputDir, "app.html")); + assert(/src=\"\/packages\/meteor\/url_tests.js/.test(appHtml)); })); // versioned app, nodeModules: 'copy'