cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [44/50] js commit: [blackberry] modulemapper refactor for app plugin.
Date Tue, 12 Feb 2013 19:33:07 GMT
[blackberry] modulemapper refactor for app plugin.

- Removes the last usage of cordova/builder.
- Refactors tests a bit.
- Introduces test helpers: modulereplacer & propertyreplacer

https://issues.apache.org/jira/browse/CB-2227


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

Branch: refs/heads/symbolmapping
Commit: 543a5783cf5751809bc9648488ae3fe39419ae8b
Parents: 6d3da39
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Fri Jan 25 15:36:35 2013 -0500
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Tue Feb 12 14:24:33 2013 -0500

----------------------------------------------------------------------
 lib/blackberry/platform.js                  |   12 ++----
 lib/blackberry/plugin/java/app/bbsymbols.js |   24 +++++++++++
 lib/blackberry/plugin/java/platform.js      |    9 ----
 lib/common/builder.js                       |   24 +++++-----
 lib/scripts/bootstrap-test.js               |   30 +++++++++++++
 lib/test/modulereplacer.js                  |   33 +++++++++++++++
 lib/test/propertyreplacer.js                |   48 ++++++++++++++++++++++
 test/blackberry/qnx/test.platform.js        |    7 ---
 test/blackberry/test.platform.js            |   39 ++++++++++++-----
 9 files changed, 178 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/543a5783/lib/blackberry/platform.js
----------------------------------------------------------------------
diff --git a/lib/blackberry/platform.js b/lib/blackberry/platform.js
index 9eb9994..0e9dd79 100644
--- a/lib/blackberry/platform.js
+++ b/lib/blackberry/platform.js
@@ -37,18 +37,14 @@ module.exports = {
         }
     },
     initialize: function() {
-        var builder = require('cordova/builder'),
-            modulemapper = require('cordova/modulemapper'),
+        var modulemapper = require('cordova/modulemapper'),
             platform = require('cordova/plugin/' + this.runtime() + '/platform');
 
-        builder.buildIntoButDoNotClobber(platform.defaults, window);
-        builder.buildIntoAndClobber(platform.clobbers, window);
-        builder.buildIntoAndMerge(platform.merges, window);
-
         modulemapper.loadMatchingModules(/cordova.*\/symbols$/);
         modulemapper.loadMatchingModules(new RegExp('cordova/.*' + this.runtime() + '/.*bbsymbols$'));
-        modulemapper.mapModules(window);
+        modulemapper.mapModules(this.contextObj);
 
         platform.initialize();
-    }
+    },
+    contextObj: this // Used for testing.
 };

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/543a5783/lib/blackberry/plugin/java/app/bbsymbols.js
----------------------------------------------------------------------
diff --git a/lib/blackberry/plugin/java/app/bbsymbols.js b/lib/blackberry/plugin/java/app/bbsymbols.js
new file mode 100644
index 0000000..3ad17f7
--- /dev/null
+++ b/lib/blackberry/plugin/java/app/bbsymbols.js
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+
+var modulemapper = require('cordova/modulemapper');
+
+modulemapper.clobbers('cordova/plugin/java/app', 'navigator.app');

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/543a5783/lib/blackberry/plugin/java/platform.js
----------------------------------------------------------------------
diff --git a/lib/blackberry/plugin/java/platform.js b/lib/blackberry/plugin/java/platform.js
index 2eefada..a28ae6b 100644
--- a/lib/blackberry/plugin/java/platform.js
+++ b/lib/blackberry/plugin/java/platform.js
@@ -144,14 +144,5 @@ module.exports = {
 
         // Trap BlackBerry WebWorks exit. Allow plugins to clean up before exiting.
         blackberry.app.event.onExit(app.exitApp);
-    },
-    clobbers: {
-        navigator: {
-            children: {
-                app: {
-                    path: "cordova/plugin/java/app"
-                }
-            }
-        }
     }
 };

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/543a5783/lib/common/builder.js
----------------------------------------------------------------------
diff --git a/lib/common/builder.js b/lib/common/builder.js
index d7fc1ea..b3b4d39 100644
--- a/lib/common/builder.js
+++ b/lib/common/builder.js
@@ -30,6 +30,7 @@ function each(objects, func, context) {
 }
 
 function clobber(obj, key, value) {
+    exports.replaceHookForTesting(obj, key);
     obj[key] = value;
     // Getters can only be overridden by getters.
     if (obj[key] !== value) {
@@ -113,16 +114,15 @@ function recursiveMerge(target, src) {
     }
 }
 
-module.exports = {
-    buildIntoButDoNotClobber: function(objects, target) {
-        include(target, objects, false, false);
-    },
-    buildIntoAndClobber: function(objects, target) {
-        include(target, objects, true, false);
-    },
-    buildIntoAndMerge: function(objects, target) {
-        include(target, objects, true, true);
-    },
-    recursiveMerge: recursiveMerge,
-    assignOrWrapInDeprecateGetter: assignOrWrapInDeprecateGetter
+exports.buildIntoButDoNotClobber = function(objects, target) {
+    include(target, objects, false, false);
 };
+exports.buildIntoAndClobber = function(objects, target) {
+    include(target, objects, true, false);
+};
+exports.buildIntoAndMerge = function(objects, target) {
+    include(target, objects, true, true);
+};
+exports.recursiveMerge = recursiveMerge;
+exports.assignOrWrapInDeprecateGetter = assignOrWrapInDeprecateGetter;
+exports.replaceHookForTesting = function() {};

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/543a5783/lib/scripts/bootstrap-test.js
----------------------------------------------------------------------
diff --git a/lib/scripts/bootstrap-test.js b/lib/scripts/bootstrap-test.js
new file mode 100644
index 0000000..531ea4a
--- /dev/null
+++ b/lib/scripts/bootstrap-test.js
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+var propertyreplacer = require('cordova/propertyreplacer');
+
+require('cordova/builder').replaceHookForTesting = function(obj, key) {
+    // This doesn't clean up non-clobbering assignments, nor does it work for
+    // getters. It does work to un-clobber clobbered / merged symbols, which
+    // is generally good enough for tests.
+    if (obj[key]) {
+        propertyreplacer.stub(obj, key);
+    }
+};
+

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/543a5783/lib/test/modulereplacer.js
----------------------------------------------------------------------
diff --git a/lib/test/modulereplacer.js b/lib/test/modulereplacer.js
new file mode 100644
index 0000000..b5a2461
--- /dev/null
+++ b/lib/test/modulereplacer.js
@@ -0,0 +1,33 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+/*global spyOn:false */
+
+var propertyreplacer = require('cordova/propertyreplacer');
+
+exports.replace = function(moduleName, newValue) {
+    propertyreplacer.stub(define.moduleMap, moduleName, null);
+    define.remove(moduleName);
+    define(moduleName, function(require, exports, module) {
+        module.exports = newValue;
+    });
+};
+

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/543a5783/lib/test/propertyreplacer.js
----------------------------------------------------------------------
diff --git a/lib/test/propertyreplacer.js b/lib/test/propertyreplacer.js
new file mode 100644
index 0000000..18c5d3b
--- /dev/null
+++ b/lib/test/propertyreplacer.js
@@ -0,0 +1,48 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+
+// Use this helper module to stub out properties within Jasmine tests.
+// Original values will be restored after each test.
+
+var curStubs = null;
+
+function removeAllStubs() {
+    for (var i = curStubs.length - 1, stub; stub = curStubs[i]; --i) {
+        stub.obj[stub.key] = stub.value;
+    }
+    curStubs = null;
+}
+
+exports.stub = function(obj, key, value) {
+    if (!curStubs) {
+        curStubs = [];
+        jasmine.getEnv().currentSpec.after(removeAllStubs);
+    }
+
+    curStubs.push({
+        obj: obj,
+        key: key,
+        value: obj[key]
+    });
+    obj[key] = value;
+};
+

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/543a5783/test/blackberry/qnx/test.platform.js
----------------------------------------------------------------------
diff --git a/test/blackberry/qnx/test.platform.js b/test/blackberry/qnx/test.platform.js
index 87e18a3..231c5ca 100644
--- a/test/blackberry/qnx/test.platform.js
+++ b/test/blackberry/qnx/test.platform.js
@@ -120,11 +120,4 @@ describe("blackberry qnx platform", function () {
         });
 
     });
-
-    describe('export merges', function(){
-        it('should define the compass path', function(){
-            expect(platform.merges.navigator.children.compass.path).toEqual("cordova/plugin/qnx/compass");
-        });
-    });
-    
 });

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/543a5783/test/blackberry/test.platform.js
----------------------------------------------------------------------
diff --git a/test/blackberry/test.platform.js b/test/blackberry/test.platform.js
index 183e449..8e2a9d0 100644
--- a/test/blackberry/test.platform.js
+++ b/test/blackberry/test.platform.js
@@ -20,7 +20,18 @@
 */
 
 describe("blackberry platform", function () {
-    var platform = require('cordova/blackberryplatform');
+    var modulemapper = require('cordova/modulemapper'),
+        modulereplacer = require('cordova/modulereplacer'),
+        platform = require('cordova/blackberryplatform');
+
+    org = {};
+    org.apache = {};
+    org.apache.cordova = {};
+    org.apache.cordova.JavaPluginManager = {};
+
+    beforeEach(function () {
+        modulereplacer.replace('cordova/platform', platform);
+    });
 
     describe("when getting the runtime", function () {
         it("returns qnx for the bb10 user agent", function () {
@@ -46,11 +57,16 @@ describe("blackberry platform", function () {
     });
 
     describe("when initializing", function () {
-        var builder = require('cordova/builder');
-
         beforeEach(function () {
-            spyOn(builder, "buildIntoAndClobber");
-            spyOn(builder, "buildIntoAndMerge");
+            platform.contextObj = {};
+            var count = 0;
+            // Don't load non-blackberry symbol modules.
+            var loadMatchingModulesSpy = spyOn(modulemapper, 'loadMatchingModules');
+            loadMatchingModulesSpy.andCallFake(function(pattern) {
+                if (!pattern.exec('cordova/foo/symbols')) {
+                    return loadMatchingModulesSpy.originalValue.apply(this, arguments);
+                }
+            });
         });
 
         it("calls initialize for the platform from the runtime", function () {
@@ -58,32 +74,31 @@ describe("blackberry platform", function () {
 
             spyOn(air, "initialize");
             spyOn(platform, "runtime").andReturn("air");
-
             platform.initialize();
 
             expect(air.initialize).toHaveBeenCalled();
         });
 
-        it("builds given platforms objects into window and clobbers them", function () {
+        it("builds java platforms objects into window", function () {
             var java = require('cordova/plugin/java/platform');
 
             spyOn(java, "initialize");
             spyOn(platform, "runtime").andReturn("java");
-
             platform.initialize();
 
-            expect(builder.buildIntoAndClobber).toHaveBeenCalledWith(java.clobbers, window);
+            expect(platform.contextObj.File).not.toBeUndefined();
+            expect(platform.contextObj.navigator.app).not.toBeUndefined();
         });
 
-        it("builds given platforms merges into window and merges them", function () {
+        it("builds qnx objects into window", function () {
             var qnx = require('cordova/plugin/qnx/platform');
 
             spyOn(qnx, "initialize");
             spyOn(platform, "runtime").andReturn("qnx");
-
             platform.initialize();
 
-            expect(builder.buildIntoAndMerge).toHaveBeenCalledWith(qnx.merges, window);
+            expect(platform.contextObj.open).not.toBeUndefined();
+            expect(platform.contextObj.navigator.compass).not.toBeUndefined();
         });
     });
 });


Mime
View raw message