You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by mm...@apache.org on 2014/04/30 17:44:23 UTC

[4/4] git commit: Change plugin test definitions to use module exports

Change plugin test definitions to use module exports


Project: http://git-wip-us.apache.org/repos/asf/cordova-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-labs/commit/e0df895f
Tree: http://git-wip-us.apache.org/repos/asf/cordova-labs/tree/e0df895f
Diff: http://git-wip-us.apache.org/repos/asf/cordova-labs/diff/e0df895f

Branch: refs/heads/cdvtest
Commit: e0df895f314d7b9eaddc99fbf64594d9e042255a
Parents: 9f765bc
Author: Michal Mocny <mm...@gmail.com>
Authored: Mon Apr 28 10:48:32 2014 -0400
Committer: Michal Mocny <mm...@gmail.com>
Committed: Mon Apr 28 10:48:32 2014 -0400

----------------------------------------------------------------------
 cordova-plugin-test-framework/www/test.js | 56 ++++++++++----------------
 1 file changed, 21 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-labs/blob/e0df895f/cordova-plugin-test-framework/www/test.js
----------------------------------------------------------------------
diff --git a/cordova-plugin-test-framework/www/test.js b/cordova-plugin-test-framework/www/test.js
index 4c067b0..d6fe220 100644
--- a/cordova-plugin-test-framework/www/test.js
+++ b/cordova-plugin-test-framework/www/test.js
@@ -22,26 +22,11 @@
 exports.tests = Object.create(null);
 
 function getTestsObject(api) {
-  return window.tests[api] = window.tests[api] || { enabled: true };
+  return exports.tests[api] = exports.tests[api] || { enabled: true };
 }
 
-// Usage:
-// registerAutoTests('apiName', function() {
-//   define('foo', function() {
-//     .. jasmine tests ..
-//   });
-// });
-exports.registerAutoTests = function(api, fn) {
-  var apiTests = getTestsObject(api);
-  apiTests.defineAutoTests = function(jasmineInterface) {
-    jasmineInterface.describe(api + ' >>', function() {
-      fn(jasmineInterface); // Note: don't pass fn directly to jasmine.describe, since describe does async magic if fn takes an arg
-    });
-  };
-};
-
-exports.defineAutoTests = function(jasmineInterface) {
-  // one time
+exports.init = function() {
+  // This finds all js-modules named "tests" regadless of plugin it came from
   var test_modules = cordova.require('cordova/plugin_list')
     .map(function(jsmodule) {
       return jsmodule.id;
@@ -49,17 +34,30 @@ exports.defineAutoTests = function(jasmineInterface) {
     .filter(function(id) {
       return /.tests$/.test(id);
     });
+
+  // Map auto / manual test definitions for each, but without actually running the handlers
   test_modules.forEach(function(id) {
     try {
-      // This runs the tests
-      cordova.require(id);
+      var plugintests = cordova.require(id);
+
+      if (plugintests.hasOwnProperty('defineAutoTests')) {
+        getTestsObject(id).defineAutoTests = function(jasmineInterface) {
+          jasmineInterface.describe(id + ' >>', plugintests.defineAutoTests.bind(plugintests));
+        };
+      }
+
+      if (plugintests.hasOwnProperty('defineManualTests')) {
+        getTestsObject(id).defineManualTests = plugintests.defineManualTests.bind(plugintests);
+      }
     } catch(ex) {
-      logger('Failed to load:', id);
+      console.warn('Failed to load tests: ', id);
       return;
     }
-    logger('Loaded:', id);
   });
+}
 
+exports.defineAutoTests = function(jasmineInterface) {
+  exports.init();
   Object.keys(exports.tests).forEach(function(key) {
     if (!exports.tests[key].enabled)
       return;
@@ -69,20 +67,8 @@ exports.defineAutoTests = function(jasmineInterface) {
   });
 };
 
-// Usage:
-// registerManualTests('apiName', function(contentEl, addButton) {
-//   .. setup ..
-//   addButton('Test Description', function() { ... });
-//   addButton('Test 2', function() { ... });
-// });
-exports.registerManualTests = function(api, fn) {
-  var apiTests = getTestsObject(api);
-  apiTests.defineManualTests = function(contentEl, addButton) {
-    fn(contentEl, addButton);
-  };
-}
-
 exports.defineManualTests = function(contentEl, beforeEach, createActionButton) {
+  exports.init();
   Object.keys(exports.tests).forEach(function(key) {
     if (!exports.tests[key].enabled)
       return;