From 32ab324eee133c034325c46c9d6eae66b15d814f Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Fri, 2 Jan 2015 18:18:03 -0800 Subject: [PATCH] [Framework] Update test runner Update test runner to provide analogous require configuration behavior, such that scripts which utilize libraries exposed from bundles via bundle.json can be unit tested appropriately. Necessary after capabilities added by WTD-568. --- test.html | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/test.html b/test.html index 8477edefd5..612633b0b3 100644 --- a/test.html +++ b/test.html @@ -110,7 +110,9 @@ // Run all test suites contained in all bundles function runSuites(bundles) { - var components = [], count = 0; + var components = [], + configuration = { baseUrl: "" }, + count = 0; function addSuite(bundle) { function fixPath(name) { @@ -124,6 +126,7 @@ components = components.concat(suiteSpecs.map(fixPath)); count += 1; if (count === bundles.length) { + require.config(configuration); runSpecs(components); } } @@ -131,7 +134,36 @@ loadJSON(bundle + "/test/suite.json", addSpecs); } - bundles.forEach(addSuite); + // Some AMD modules are configured in bundle.json files, + // so those need to be read and a require definition built + function readConfig(bundle, definition) { + var lib = bundle.libraries || "lib", + bundleConfig = definition.configuration || {}; + + // Merge in paths + Object.keys(bundleConfig.paths || {}).forEach(function (path) { + configuration.paths = configuration.paths || {}; + configuration.paths[path] = + bundle + "/" + lib + "/" + bundleConfig.paths[path]; + }); + + // Merge in shims + Object.keys(bundleConfig.shim || {}).forEach(function (shim) { + configuration.shim = configuration.shim || {}; + configuration.shim[shim] = bundleConfig.shim[shim]; + }); + } + + function addBundle(bundle) { + function readConfigAndContinue(definition) { + readConfig(bundle, definition); + addSuite(bundle); + } + + loadJSON(bundle + "/bundle.json", readConfigAndContinue); + } + + bundles.forEach(addBundle); } // Set the ball rolling; load and run all test suites