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:22 UTC

[3/4] git commit: Moving test management from app to plugin

Moving test management from app to plugin


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

Branch: refs/heads/cdvtest
Commit: 9f765bcf7f008c69eff8f4755f2eb40ac741cc06
Parents: f695e4b
Author: Michal Mocny <mm...@gmail.com>
Authored: Mon Apr 28 09:35:53 2014 -0400
Committer: Michal Mocny <mm...@gmail.com>
Committed: Mon Apr 28 09:45:13 2014 -0400

----------------------------------------------------------------------
 cordova-app-test-harness/www/index.html   |   1 -
 cordova-app-test-harness/www/main.js      |   6 +-
 cordova-app-test-harness/www/tests.js     |  83 ------------
 cordova-plugin-test-framework/www/test.js | 176 ++++++++++---------------
 4 files changed, 71 insertions(+), 195 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-labs/blob/9f765bcf/cordova-app-test-harness/www/index.html
----------------------------------------------------------------------
diff --git a/cordova-app-test-harness/www/index.html b/cordova-app-test-harness/www/index.html
index a379892..61be191 100644
--- a/cordova-app-test-harness/www/index.html
+++ b/cordova-app-test-harness/www/index.html
@@ -17,7 +17,6 @@
     <script type="text/javascript" src="cordova.js"></script>
 
     <!-- App scripts -->
-    <script type="text/javascript" src="tests.js"></script>
     <script type="text/javascript" src="jasmine_helpers.js"></script>
     <script type="text/javascript" src="jasmine-medic.js"></script>
     <script type="text/javascript" src="medic.js"></script>

http://git-wip-us.apache.org/repos/asf/cordova-labs/blob/9f765bcf/cordova-app-test-harness/www/main.js
----------------------------------------------------------------------
diff --git a/cordova-app-test-harness/www/main.js b/cordova-app-test-harness/www/main.js
index 256ac09..89a250a 100644
--- a/cordova-app-test-harness/www/main.js
+++ b/cordova-app-test-harness/www/main.js
@@ -86,7 +86,8 @@ function runAutoTests() {
   for (var property in jasmineInterface) {
     window[property] = jasmineInterface[property];
   }
-  window.defineAutoTests(jasmineInterface);
+  var cdvtest = cordova.require('org.apache.cordova.test-framework.test');
+  cdvtest.defineAutoTests(jasmineInterface);
 
   // Run the tests!
   var jasmineEnv = jasmine.getEnv();
@@ -107,7 +108,8 @@ function runManualTests() {
     createActionButton('Reset App', location.reload.bind(location));
     createActionButton('Back', setMode.bind(null, 'manual'));
   }
-  window.defineManualTests(contentEl, beforeEach, createActionButton);
+  var cdvtest = cordova.require('org.apache.cordova.test-framework.test');
+  cdvtest.defineManualTests(contentEl, beforeEach, createActionButton);
 }
 
 /******************************************************************************/

http://git-wip-us.apache.org/repos/asf/cordova-labs/blob/9f765bcf/cordova-app-test-harness/www/tests.js
----------------------------------------------------------------------
diff --git a/cordova-app-test-harness/www/tests.js b/cordova-app-test-harness/www/tests.js
deleted file mode 100644
index 8a1f21f..0000000
--- a/cordova-app-test-harness/www/tests.js
+++ /dev/null
@@ -1,83 +0,0 @@
-(function() {
-
-'use strict';
-
-var exports = window;
-
-exports.tests = Object.create(null);
-
-function getTestsObject(api) {
-  return window.tests[api] = window.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
-  var test_modules = cordova.require('cordova/plugin_list')
-    .map(function(jsmodule) {
-      return jsmodule.id;
-    })
-    .filter(function(id) {
-      return /.tests$/.test(id);
-    });
-  test_modules.forEach(function(id) {
-    try {
-      // This runs the tests
-      cordova.require(id);
-    } catch(ex) {
-      logger('Failed to load:', id);
-      return;
-    }
-    logger('Loaded:', id);
-  });
-
-  Object.keys(exports.tests).forEach(function(key) {
-    if (!exports.tests[key].enabled)
-      return;
-    if (!exports.tests[key].hasOwnProperty('defineAutoTests'))
-      return;
-    exports.tests[key].defineAutoTests(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) {
-  Object.keys(exports.tests).forEach(function(key) {
-    if (!exports.tests[key].enabled)
-      return;
-    if (!exports.tests[key].hasOwnProperty('defineManualTests'))
-      return;
-    createActionButton(key, function() {
-      beforeEach();
-      exports.tests[key].defineManualTests(contentEl, createActionButton);
-    });
-  });
-};
-
-}());

http://git-wip-us.apache.org/repos/asf/cordova-labs/blob/9f765bcf/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 68b3108..4c067b0 100644
--- a/cordova-plugin-test-framework/www/test.js
+++ b/cordova-plugin-test-framework/www/test.js
@@ -19,120 +19,78 @@
  *
 */
 
-/******************************************************************************/
-/******************************************************************************/
-/******************************************************************************/
-// Common
-
-var contentEl,
-    createActionButtonFn,
-    logFn;
-
-/******************************************************************************/
-
-exports.init = function(contentEl_, createActionButtonFn_, logFn_) {
-  contentEl = contentEl_;
-  createActionButtonFn = createActionButtonFn_;
-  logFn = logFn_;
+exports.tests = Object.create(null);
+
+function getTestsObject(api) {
+  return window.tests[api] = window.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
+    });
+  };
 };
 
-/******************************************************************************/
-
-Object.defineProperty(exports, "log", {
-    get: function() { return logFn; }
-});
-
-/******************************************************************************/
-/******************************************************************************/
-/******************************************************************************/
-// Auto Tests
-
-(function() {
-
-var jasmine,
-    jasmineInterface;
-
-/******************************************************************************/
-
-exports.initForAutoTests = function(jasmine_) {
-  jasmine = jasmine_;
-  jasmineInterface = {};
-
-  var jasmineEnv = jasmine.getEnv();
-
-  // Fill in jasmineInterface
-  var jasmine_functions = ['describe',
-                           'xdescribe',
-                           'it',
-                           'xit',
-                           'beforeEach',
-                           'afterEach',
-                           'expect',
-                           'pending',
-                           'addMatchers',
-                           'spyOn'];
-  jasmine_functions.forEach(function(fn) {
-    jasmineInterface[fn] = jasmineEnv[fn].bind(jasmineEnv);
+exports.defineAutoTests = function(jasmineInterface) {
+  // one time
+  var test_modules = cordova.require('cordova/plugin_list')
+    .map(function(jsmodule) {
+      return jsmodule.id;
+    })
+    .filter(function(id) {
+      return /.tests$/.test(id);
+    });
+  test_modules.forEach(function(id) {
+    try {
+      // This runs the tests
+      cordova.require(id);
+    } catch(ex) {
+      logger('Failed to load:', id);
+      return;
+    }
+    logger('Loaded:', id);
   });
-  jasmineInterface.clock = jasmineEnv.clock;
-  jasmineInterface.jsApiReporter = new jasmine.JsApiReporter({ timer: new jasmine.Timer() });
-  jasmineInterface.jasmine = jasmine;
-  jasmineInterface.log = exports.log;
-
-  jasmineEnv.addReporter(jasmineInterface.jsApiReporter);
-};
-
-/******************************************************************************/
-
-exports.runAutoTests = function() {
-  jasmine.getEnv().execute();
-};
 
-/******************************************************************************/
-
-exports.injectJasmineInterface = function(target, targetName) {
-  var ret = "";
-  for (var property in jasmineInterface) {
-    target[property] = jasmineInterface[property];
-    ret += 'var ' + property + ' = this[\'' + property + '\'];\n';
-  }
-  return ret;
-};
-
-/******************************************************************************/
-
-}());
-
-/******************************************************************************/
-/******************************************************************************/
-/******************************************************************************/
-// Manual Tests
-
-(function () {
-
-/******************************************************************************/
-
-exports.initForManualTests = function() {
-};
-
-/******************************************************************************/
-
-exports.addManualTestFn = function(title, fn) {
-  createActionButtonFn(title, fn);
+  Object.keys(exports.tests).forEach(function(key) {
+    if (!exports.tests[key].enabled)
+      return;
+    if (!exports.tests[key].hasOwnProperty('defineAutoTests'))
+      return;
+    exports.tests[key].defineAutoTests(jasmineInterface);
+  });
 };
 
-/******************************************************************************/
-
-exports.addManualTestPage = function(title, url) {
-  createActionButtonFn(title, function() {
-    // TODO: This should probably have a way to get back.
-    // Perhaps open the page in a frame?
-    window.href = url;
+// 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) {
+  Object.keys(exports.tests).forEach(function(key) {
+    if (!exports.tests[key].enabled)
+      return;
+    if (!exports.tests[key].hasOwnProperty('defineManualTests'))
+      return;
+    createActionButton(key, function() {
+      beforeEach();
+      exports.tests[key].defineManualTests(contentEl, createActionButton);
+    });
   });
 };
-
-/******************************************************************************/
-
-}());
-
-/******************************************************************************/