cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lorinb...@apache.org
Subject [15/30] git commit: blackberry handler specs.
Date Tue, 07 May 2013 15:18:52 GMT
blackberry handler specs.


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

Branch: refs/heads/future
Commit: 09c2537d27a194720efd4154bd9c1b82da3963dd
Parents: 202d49d
Author: Fil Maj <maj.fil@gmail.com>
Authored: Tue Apr 23 17:05:53 2013 -0700
Committer: Fil Maj <maj.fil@gmail.com>
Committed: Tue Apr 23 17:05:53 2013 -0700

----------------------------------------------------------------------
 spec/platforms/android.spec.js       |    1 -
 spec/platforms/blackberry.spec.js    |  163 +++++++++++++++++++++++++----
 spec/plugins/DummyPlugin/plugin.xml  |    2 +-
 spec/plugins/FaultyPlugin/plugin.xml |   10 ++
 src/platforms/blackberry.js          |   15 +--
 5 files changed, 155 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/09c2537d/spec/platforms/android.spec.js
----------------------------------------------------------------------
diff --git a/spec/platforms/android.spec.js b/spec/platforms/android.spec.js
index a009908..277147a 100644
--- a/spec/platforms/android.spec.js
+++ b/spec/platforms/android.spec.js
@@ -23,7 +23,6 @@ var xml_path     = path.join(dummyplugin, 'plugin.xml')
 var platformTag = plugin_et.find('./platform[@name="android"]');
 var dummy_id = plugin_et._root.attrib['id'];
 var valid_source = platformTag.findall('./source-file'),
-    libFiles = platformTag.findall('./library-file'),
     assets = plugin_et.findall('./asset'),
     configChanges = platformTag.findall('./config-file');
 

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/09c2537d/spec/platforms/blackberry.spec.js
----------------------------------------------------------------------
diff --git a/spec/platforms/blackberry.spec.js b/spec/platforms/blackberry.spec.js
index defddda..a06c2b7 100644
--- a/spec/platforms/blackberry.spec.js
+++ b/spec/platforms/blackberry.spec.js
@@ -1,4 +1,40 @@
-var blackberry = require('../../src/platforms/blackberry');
+var blackberry = require('../../src/platforms/blackberry'),
+    common  = require('../../src/platforms/common'),
+    install = require('../../src/install'),
+    path    = require('path'),
+    fs      = require('fs'),
+    shell   = require('shelljs'),
+    et      = require('elementtree'),
+    os      = require('osenv'),
+    temp    = path.join(os.tmpdir(), 'plugman'),
+    plugins_dir = path.join(temp, 'cordova', 'plugins'),
+    xml_helpers = require('../../src/util/xml-helpers'),
+    plugins_module = require('../../src/util/plugins'),
+    dummyplugin = path.join(__dirname, '..', 'plugins', 'DummyPlugin'),
+    faultyplugin = path.join(__dirname, '..', 'plugins', 'FaultyPlugin'),
+    blackberry_project = path.join(__dirname, '..', 'projects', 'blackberry', '*');
+
+var xml_path     = path.join(dummyplugin, 'plugin.xml')
+  , xml_text     = fs.readFileSync(xml_path, 'utf-8')
+  , plugin_et    = new et.ElementTree(et.XML(xml_text));
+
+var platformTag = plugin_et.find('./platform[@name="blackberry"]');
+var dummy_id = plugin_et._root.attrib['id'];
+var valid_source = platformTag.findall('./source-file'),
+    assets = plugin_et.findall('./asset'),
+    configChanges = platformTag.findall('./config-file');
+
+xml_path  = path.join(faultyplugin, 'plugin.xml')
+xml_text  = fs.readFileSync(xml_path, 'utf-8')
+plugin_et = new et.ElementTree(et.XML(xml_text));
+
+platformTag = plugin_et.find('./platform[@name="blackberry"]');
+var invalid_source = platformTag.findall('./source-file');
+var faulty_id = plugin_et._root.attrib['id'];
+
+function copyArray(arr) {
+    return Array.prototype.slice.call(arr, 0);
+}
 
 describe('blackberry project handler', function() {
     it('should have an install function', function() {
@@ -12,39 +48,122 @@ describe('blackberry project handler', function() {
     });
 
     describe('installation', function() {
-        describe('of <source-file> elements', function() {
-            it('should copy stuff from one location to another by calling common.straightCopy');
-            it('should throw if source file cannot be found');
-            it('should throw if target file already exists');
+        beforeEach(function() {
+            shell.mkdir('-p', temp);
+            shell.cp('-rf', blackberry_project, temp);
         });
-        describe('of <library-file> elements', function() {
-            it('should copy stuff from one location to another by calling common.straightCopy');
-            it('should throw if source file cannot be found');
-            it('should throw if target file already exists');
+        afterEach(function() {
+            shell.rm('-rf', temp);
+        });
+        describe('of <source-file> elements', function() {
+            it('should copy stuff from one location to another by calling common.straightCopy',
function() {
+                var source = copyArray(valid_source);
+                var s = spyOn(common, 'straightCopy');
+                blackberry.install(source, dummy_id, temp, dummyplugin, {});
+                expect(s).toHaveBeenCalledWith(dummyplugin, 'src/blackberry/client.js', temp,
'ext-qnx/cordova.echo/client.js');
+                expect(s).toHaveBeenCalledWith(dummyplugin, 'src/blackberry/index.js', temp,
'ext-qnx/cordova.echo/index.js');
+                expect(s).toHaveBeenCalledWith(dummyplugin, 'src/blackberry/manifest.json',
temp, 'ext-qnx/cordova.echo/manifest.json');
+            });
+            it('should throw if source file cannot be found', function() {
+                var source = copyArray(invalid_source);
+                expect(function() {
+                    blackberry.install(source, faulty_id, temp, faultyplugin, {});
+                }).toThrow('"' + path.resolve(faultyplugin, 'src/blackberry/device/echoJnext.so')
+ '" not found!');
+            });
+            it('should throw if target file already exists', function() {
+                // write out a file
+                var target = path.resolve(temp, 'ext-qnx/cordova.echo');
+                shell.mkdir('-p', target);
+                target = path.join(target, 'client.js');
+                fs.writeFileSync(target, 'some bs', 'utf-8');
+
+                var source = copyArray(valid_source);
+                expect(function() {
+                    blackberry.install(source, dummy_id, temp, dummyplugin, {});
+                }).toThrow('"' + target + '" already exists!');
+            });
         });
         describe('of <config-file> elements', function() {
-            it('should only target config.xml if that is applicable');
-            it('should call into xml helper\'s graftXML');
+            it('should target config.xml', function() {
+                var config = copyArray(configChanges);
+                var s = spyOn(xml_helpers, 'parseElementtreeSync').andCallThrough();
+                blackberry.install(config, dummy_id, temp, dummyplugin, {});
+                expect(s).toHaveBeenCalledWith(path.join(temp, 'www', 'config.xml'));
+            });
+            it('should call into xml helper\'s graftXML', function() {
+                shell.cp('-rf', blackberry_project, temp);
+                var config = copyArray(configChanges);
+                var s = spyOn(xml_helpers, 'graftXML').andReturn(true);
+                blackberry.install(config, dummy_id, temp, dummyplugin, {});
+                expect(s).toHaveBeenCalled();
+            });
         });
-        it('should interpolate variables properly');
     });
 
     describe('uninstallation', function() {
-        describe('of <source-file> elements', function() {
-            it('should remove stuff by calling common.deleteJava');
-            it('should remove empty dirs from java src dir heirarchy');
+        beforeEach(function() {
+            shell.mkdir('-p', temp);
+            shell.mkdir('-p', plugins_dir);
+            shell.cp('-rf', blackberry_project, temp);
+            shell.cp('-rf', dummyplugin, plugins_dir);
+        });
+        afterEach(function() {
+            shell.rm('-rf', temp);
         });
-        describe('of <library-file> elements', function() {
-            it('should remove stuff using fs.unlinkSync');
+        describe('of <source-file> elements', function() {
+            it('should remove stuff by calling common.deleteJava', function(done) {
+                var s = spyOn(common, 'deleteJava');
+                install('blackberry', temp, 'DummyPlugin', plugins_dir, {}, function() {
+                    var source = copyArray(valid_source);
+                    blackberry.uninstall(source, dummy_id, temp, path.join(plugins_dir, 'DummyPlugin'));
+                    expect(s).toHaveBeenCalledWith(temp, 'ext-qnx/cordova.echo/client.js');
+                    expect(s).toHaveBeenCalledWith(temp, 'ext-qnx/cordova.echo/index.js');
+                    expect(s).toHaveBeenCalledWith(temp, 'ext-qnx/cordova.echo/manifest.json');
+                    done();
+                });
+            });
         });
         describe('of <config-file> elements', function() {
-            it('should only target config.xml if that is applicable');
-            it('should only target plugins.xml if that is applicable');
-            it('should call into xml helper\'s pruneXML');
+            it('should target config.xml', function(done) {
+                var config = copyArray(configChanges);
+                var s = spyOn(xml_helpers, 'parseElementtreeSync').andCallThrough();
+                install('blackberry', temp, 'DummyPlugin', plugins_dir, {}, function() {
+                    var config = copyArray(configChanges);
+                    blackberry.uninstall(config, dummy_id, temp, path.join(plugins_dir, 'DummyPlugin'));
+                    expect(s).toHaveBeenCalledWith(path.join(temp, 'www', 'config.xml'));
+                    done();
+                });
+            });
+            it('should call into xml helper\'s pruneXML', function(done) {
+                var config = copyArray(configChanges);
+                install('blackberry', temp, 'DummyPlugin', plugins_dir, {}, function() {
+                    var s = spyOn(xml_helpers, 'pruneXML').andReturn(true);
+                    blackberry.uninstall(config, dummy_id, temp, path.join(plugins_dir, 'DummyPlugin'));
+                    expect(s).toHaveBeenCalled();
+                    done();
+                });
+            });
         });
         describe('of <asset> elements', function() {
-            it('should remove www\'s plugins <plugin-id> directory');
-            it('should remove stuff specified by the element');
+            it('should remove www\'s plugins/<plugin-id> directory', function(done)
{
+                var as = copyArray(assets);
+                install('blackberry', temp, 'DummyPlugin', plugins_dir, {}, function() {
+                    var s = spyOn(shell, 'rm');
+                    blackberry.uninstall(as, dummy_id, temp, path.join(plugins_dir, 'DummyPlugin'));
+                    expect(s).toHaveBeenCalledWith('-rf', path.join(temp, 'www', 'plugins',
dummy_id));
+                    done();
+                });
+            });
+            it('should remove stuff specified by the element', function(done) {
+                var as = copyArray(assets);
+                install('blackberry', temp, 'DummyPlugin', plugins_dir, {}, function() {
+                    var s = spyOn(shell, 'rm');
+                    blackberry.uninstall(as, dummy_id, temp, path.join(plugins_dir, 'DummyPlugin'));
+                    expect(s).toHaveBeenCalledWith('-rf', path.join(temp, 'www', 'dummyplugin.js'));
+                    expect(s).toHaveBeenCalledWith('-rf', path.join(temp, 'www', 'dummyplugin'));
+                    done();
+                });
+            });
         });
     });
 });

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/09c2537d/spec/plugins/DummyPlugin/plugin.xml
----------------------------------------------------------------------
diff --git a/spec/plugins/DummyPlugin/plugin.xml b/spec/plugins/DummyPlugin/plugin.xml
index ddb1113..e21ed40 100644
--- a/spec/plugins/DummyPlugin/plugin.xml
+++ b/spec/plugins/DummyPlugin/plugin.xml
@@ -59,7 +59,7 @@
 
     <!-- blackberry -->
     <platform name="blackberry">
-        <config-file target="config.xml" parent="/widget">
+        <config-file target="www/config.xml" parent="/widget">
             <feature id="dummyPlugin" required="true" version="1.0.0.0"/>
         </config-file>
 

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/09c2537d/spec/plugins/FaultyPlugin/plugin.xml
----------------------------------------------------------------------
diff --git a/spec/plugins/FaultyPlugin/plugin.xml b/spec/plugins/FaultyPlugin/plugin.xml
index d7e21e9..278c89d 100644
--- a/spec/plugins/FaultyPlugin/plugin.xml
+++ b/spec/plugins/FaultyPlugin/plugin.xml
@@ -71,4 +71,14 @@
         <source-file src="src/ios/FaultyPluginCommand.m" />
 
     </platform>
+    <platform name="blackberry">
+        <config-file target="config.xml" parent="/widget">
+            <feature id="cordova.echo" required="true" version="1.0.0.0"/>
+        </config-file>
+
+        <source-file src="src/blackberry/client.js" target-dir="ext-qnx/cordova.echo"
/>
+        <!-- these dont exist -->
+        <source-file src="src/blackberry/device/echoJnext.so" target-dir="ext-qnx/cordova.echo/device"
/>
+        <source-file src="src/blackberry/simulator/echoJnext.so" target-dir="ext-qnx/cordova.echo/simulator"
/>
+    </platform>
 </plugin>

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/09c2537d/spec/plugins/FaultyPlugin/src/blackberry/client.js
----------------------------------------------------------------------
diff --git a/spec/plugins/FaultyPlugin/src/blackberry/client.js b/spec/plugins/FaultyPlugin/src/blackberry/client.js
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/09c2537d/src/platforms/blackberry.js
----------------------------------------------------------------------
diff --git a/src/platforms/blackberry.js b/src/platforms/blackberry.js
index c558190..029378a 100644
--- a/src/platforms/blackberry.js
+++ b/src/platforms/blackberry.js
@@ -22,7 +22,7 @@ var fs = require('fs')  // use existsSync in 0.6.x
    , shell = require('shelljs')
    , et = require('elementtree')
    , getConfigChanges = require('../util/config-changes')
-   , sourceDir = 'src'
+   , common = require('./common')
    , xml_helpers = require(path.join(__dirname, '..', 'util', 'xml-helpers'));
 
 module.exports = {
@@ -52,15 +52,6 @@ function handlePlugin(action, plugin_id, txs, project_dir, plugin_dir,
variables
                         common.deleteJava(project_dir, destFile);
                     }
                     break;
-                case 'library-file':
-                    var destFile = path.join(mod.attrib['target-dir'], path.basename(mod.attrib['src']));
-
-                    if (action == 'install') {
-                        common.straightCopy(plugin_dir, mod.attrib['src'], project_dir, destFile);
-                    } else {
-                        fs.unlinkSync(path.resolve(project_dir, destFile));
-                    }
-                    break;
                 case 'config-file':
                     // Only modify config files that exist.
                     var config_file = path.resolve(project_dir, mod.attrib['target']);
@@ -86,8 +77,8 @@ function handlePlugin(action, plugin_id, txs, project_dir, plugin_dir, variables
                 case 'asset':
                     if (action == 'uninstall') {
                         var target = mod.attrib.target;
-                        shell.rm('-rf', path.resolve(module.exports.www_dir(), target));
-                        shell.rm('-rf', path.resolve(module.exports.www_dir(), 'plugins',
plugin_id));
+                        shell.rm('-rf', path.resolve(module.exports.www_dir(project_dir),
target));
+                        shell.rm('-rf', path.resolve(module.exports.www_dir(project_dir),
'plugins', plugin_id));
                     }
                     break;
                 default:


Mime
View raw message