cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fil...@apache.org
Subject [30/50] [abbrv] git commit: prepare specs
Date Tue, 23 Apr 2013 23:00:58 GMT
prepare 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/63400f3b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/63400f3b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/63400f3b

Branch: refs/heads/master
Commit: 63400f3b7b5178b6f0eb0baea4467fc5cc1acc28
Parents: 9e4033c
Author: Fil Maj <maj.fil@gmail.com>
Authored: Fri Apr 19 23:57:39 2013 -0700
Committer: Fil Maj <maj.fil@gmail.com>
Committed: Fri Apr 19 23:57:39 2013 -0700

----------------------------------------------------------------------
 spec/install.spec.js                  |   37 +++++++++++----
 spec/plugins/AndroidJS/plugin.xml     |   35 +++++++++++++
 spec/plugins/AndroidJS/www/android.js |    1 +
 spec/plugins/DummyPlugin/plugin.xml   |    3 +
 spec/prepare.spec.js                  |   72 ++++++++++++++++++++++++++++
 src/platforms/android.js              |    2 +-
 src/prepare.js                        |    2 +-
 7 files changed, 141 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/63400f3b/spec/install.spec.js
----------------------------------------------------------------------
diff --git a/spec/install.spec.js b/spec/install.spec.js
index d368111..962ae96 100644
--- a/spec/install.spec.js
+++ b/spec/install.spec.js
@@ -1,5 +1,7 @@
 var install = require('../src/install'),
     android = require('../src/platforms/android'),
+    ios     = require('../src/platforms/ios'),
+    blackberry = require('../src/platforms/blackberry'),
     plugman = require('../plugman'),
     fs      = require('fs'),
     os      = require('osenv'),
@@ -7,9 +9,12 @@ var install = require('../src/install'),
     shell   = require('shelljs'),
     temp    = path.join(os.tmpdir(), 'plugman'),
     childbrowser = path.join(__dirname, 'plugins', 'ChildBrowser'),
+    dummyplugin = path.join(__dirname, 'plugins', 'DummyPlugin'),
     variableplugin = path.join(__dirname, 'plugins', 'VariablePlugin'),
     faultyplugin = path.join(__dirname, 'plugins', 'FaultyPlugin'),
     android_one_project = path.join(__dirname, 'projects', 'android_one', '*');
+    blackberry_project = path.join(__dirname, 'projects', 'blackberry', '*');
+    ios_project = path.join(__dirname, 'projects', 'ios-config-xml', '*');
     plugins_dir = path.join(temp, 'cordova', 'plugins');
 
 describe('install', function() {
@@ -25,19 +30,33 @@ describe('install', function() {
 
     describe('success', function() {
         beforeEach(function() {
-            shell.cp('-rf', android_one_project, temp);
-            shell.cp('-rf', childbrowser, plugins_dir);
+            shell.cp('-rf', dummyplugin, plugins_dir);
         });
 
         it('should call prepare after a successful install', function() {
+            shell.cp('-rf', android_one_project, temp);
             var s = spyOn(plugman, 'prepare');
-            console.log(path.resolve(path.join(plugins_dir, 'ChildBrowser', 'src', 'android')));
-            install('android', temp, 'ChildBrowser', plugins_dir, {});
-            //expect(s).toHaveBeenCalled();
+            install('android', temp, 'DummyPlugin', plugins_dir, {});
+            expect(s).toHaveBeenCalled();
+        });
+        it('on an Android project should call into Android module\'s handleInstall', function()
{
+            shell.cp('-rf', android_one_project, temp);
+            var s = spyOn(android, 'handleInstall');
+            install('android', temp, 'DummyPlugin', plugins_dir, {});
+            expect(s).toHaveBeenCalled();
+        });
+        it('on a BlackBerry project should call into BlackBerry module\'s handleInstall',
function() {
+            shell.cp('-rf', blackberry_project, temp);
+            var s = spyOn(blackberry, 'handleInstall');
+            install('blackberry', temp, 'DummyPlugin', plugins_dir, {});
+            expect(s).toHaveBeenCalled();
+        });
+        it('on an iOS project should call into iOS module\'s handleInstall', function() {
+            shell.cp('-rf', ios_project, temp);
+            var s = spyOn(ios, 'handleInstall');
+            install('ios', temp, 'DummyPlugin', plugins_dir, {});
+            expect(s).toHaveBeenCalled();
         });
-        it('on an Android project should call into Android module\'s handleInstall');
-        it('on a BlackBerry project should call into BlackBerry module\'s handleInstall');
-        it('on an iOS project should call into iOS module\'s handleInstall');
     });
 
     describe('failure', function() {
@@ -64,7 +83,7 @@ describe('install', function() {
             }
             expect(didThrow).toBe(true);
         });
-        it('should revert changes if installation failed', function() {
+        it('should call forceUninstall if installation fails to revert changes', function()
{
             shell.cp('-rf', android_one_project, temp);
             shell.cp('-rf', faultyplugin, plugins_dir);
             var s = spyOn(android, 'forceUninstall');

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/63400f3b/spec/plugins/AndroidJS/plugin.xml
----------------------------------------------------------------------
diff --git a/spec/plugins/AndroidJS/plugin.xml b/spec/plugins/AndroidJS/plugin.xml
new file mode 100644
index 0000000..4d8f648
--- /dev/null
+++ b/spec/plugins/AndroidJS/plugin.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright 2013 Anis Kadri
+
+ Licensed 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.
+
+-->
+
+<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
+    xmlns="http://www.phonegap.com/ns/plugins/1.0"
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    id="com.phonegap.androidonly"
+    version="3.0.0">
+
+    <name>JavaScript in yo droidz</name>
+
+    <!-- android -->
+    <platform name="android">
+		<js-module src="www/android.js" name="Android">
+            <clobbers target="android" />
+        </js-module>
+    </platform>
+</plugin>

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/63400f3b/spec/plugins/AndroidJS/www/android.js
----------------------------------------------------------------------
diff --git a/spec/plugins/AndroidJS/www/android.js b/spec/plugins/AndroidJS/www/android.js
new file mode 100644
index 0000000..d268b7d
--- /dev/null
+++ b/spec/plugins/AndroidJS/www/android.js
@@ -0,0 +1 @@
+{};

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/63400f3b/spec/plugins/DummyPlugin/plugin.xml
----------------------------------------------------------------------
diff --git a/spec/plugins/DummyPlugin/plugin.xml b/spec/plugins/DummyPlugin/plugin.xml
index d1bf38c..ddb1113 100644
--- a/spec/plugins/DummyPlugin/plugin.xml
+++ b/spec/plugins/DummyPlugin/plugin.xml
@@ -66,6 +66,9 @@
         <source-file src="src/blackberry/client.js" target-dir="ext-qnx/cordova.echo"
/>
         <source-file src="src/blackberry/index.js" target-dir="ext-qnx/cordova.echo" />
         <source-file src="src/blackberry/manifest.json" target-dir="ext-qnx/cordova.echo"
/>
+        <js-module src="www/dummyplugin.js" name="Dummy">
+            <clobbers target="dummy" />
+        </js-module>
     </platform>
 
         

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/63400f3b/spec/prepare.spec.js
----------------------------------------------------------------------
diff --git a/spec/prepare.spec.js b/spec/prepare.spec.js
index e69de29..494b8c5 100644
--- a/spec/prepare.spec.js
+++ b/spec/prepare.spec.js
@@ -0,0 +1,72 @@
+var prepare = require('../src/prepare'),
+    android = require('../src/platforms/android'),
+    ios     = require('../src/platforms/ios'),
+    blackberry = require('../src/platforms/blackberry'),
+    plugman = require('../plugman'),
+    fs      = require('fs'),
+    os      = require('osenv'),
+    path    = require('path'),
+    shell   = require('shelljs'),
+    temp    = path.join(os.tmpdir(), 'plugman'),
+    childbrowser = path.join(__dirname, 'plugins', 'ChildBrowser'),
+    dummyplugin = path.join(__dirname, 'plugins', 'DummyPlugin'),
+    androidplugin = path.join(__dirname, 'plugins', 'AndroidJS'),
+    faultyplugin = path.join(__dirname, 'plugins', 'FaultyPlugin'),
+    android_one_project = path.join(__dirname, 'projects', 'android_one', '*');
+    blackberry_project = path.join(__dirname, 'projects', 'blackberry', '*');
+    ios_project = path.join(__dirname, 'projects', 'ios-config-xml', '*');
+    plugins_dir = path.join(temp, 'cordova', 'plugins');
+
+describe('prepare', function() {
+    beforeEach(function() {
+        shell.mkdir('-p', temp);
+        shell.mkdir('-p', plugins_dir);
+        shell.cp('-rf', android_one_project, temp);
+        shell.cp('-rf', childbrowser, plugins_dir);
+    });
+    afterEach(function() {
+        shell.rm('-rf', temp);
+    });
+
+    var www = path.join(temp, 'assets', 'www');
+    
+    it('should create a cordova_plugins.json file', function() {
+        prepare(temp, 'android', plugins_dir);
+        expect(fs.existsSync(path.join(www, 'cordova_plugins.json'))).toBe(true);
+    });
+    it('should copy over assets defined in <asset> elements', function() {
+        prepare(temp, 'android', plugins_dir);
+        expect(fs.existsSync(path.join(www, 'childbrowser_file.html'))).toBe(true);
+        expect(fs.statSync(path.join(www, 'childbrowser')).isDirectory()).toBe(true);
+    });
+    it('should create a plugins directory in an application\'s www directory', function()
{
+        prepare(temp, 'android', plugins_dir);
+        expect(fs.existsSync(path.join(www, 'plugins'))).toBe(true);
+    });
+    it('should not add code to load platform js in a project for a different platform', function()
{
+        shell.cp('-rf', dummyplugin, plugins_dir);
+        prepare(temp, 'android', plugins_dir);
+        var plugins = JSON.parse(fs.readFileSync(path.join(www, 'cordova_plugins.json'),
'utf-8'));
+        expect(plugins.length).toEqual(1);
+        expect(plugins[0].id).not.toMatch(/dummy/);
+    });
+    it('should add code to load platform js if platform is applicable', function() {
+        shell.cp('-rf', androidplugin, plugins_dir);
+        prepare(temp, 'android', plugins_dir);
+        var plugins = JSON.parse(fs.readFileSync(path.join(www, 'cordova_plugins.json'),
'utf-8'));
+        expect(plugins.length).toEqual(2);
+        expect(plugins[0].id).toMatch(/android/);
+    });
+    it('should parse js modules for multiple plugins added to a single project', function()
{
+        shell.cp('-rf', androidplugin, plugins_dir);
+        prepare(temp, 'android', plugins_dir);
+        var plugins = JSON.parse(fs.readFileSync(path.join(www, 'cordova_plugins.json'),
'utf-8'));
+        expect(plugins.length).toEqual(2);
+    });
+    it('should write out an empty cordova_plugins.json if no plugins are applicable', function()
{
+        shell.rm('-rf', path.join(plugins_dir, '*'));
+        prepare(temp, 'android', plugins_dir);
+        var plugins = JSON.parse(fs.readFileSync(path.join(www, 'cordova_plugins.json'),
'utf-8'));
+        expect(plugins.length).toEqual(0);
+    });
+});

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/63400f3b/src/platforms/android.js
----------------------------------------------------------------------
diff --git a/src/platforms/android.js b/src/platforms/android.js
index 73b0b3a..f8dd640 100644
--- a/src/platforms/android.js
+++ b/src/platforms/android.js
@@ -203,7 +203,7 @@ function handlePlugin(action, project_dir, plugin_dir, plugin_et, variables)
{
 // TODO: resolvePath, and should be used everywhere (even across platform impls)
 function srcPath(pluginPath, filename) {
     var file = path.resolve(pluginPath, filename);
-    if (!fs.existsSync(path)) {
+    if (!fs.existsSync(file)) {
         throw new Error('Path "' + file + '" does not exist.');
     }
     return file;

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/63400f3b/src/prepare.js
----------------------------------------------------------------------
diff --git a/src/prepare.js b/src/prepare.js
index cb5474d..1d24726 100644
--- a/src/prepare.js
+++ b/src/prepare.js
@@ -37,7 +37,7 @@ module.exports = function handlePrepare(project_dir, platform, plugins_dir)
{
     // - Skip those without support for this platform. (No <platform> tags means JS-only!)
     // - Build a list of all their js-modules, including platform-specific js-modules.
     // - For each js-module (general first, then platform) build up an object storing the
path and any clobbers, merges and runs for it.
-    // - Write this object into www/plugins.json.
+    // - Write this object into www/cordova_plugins.json.
     // - Cordova.js contains code to load them at runtime from that file.
 
     var wwwDir = platform_modules[platform].www_dir(project_dir);


Mime
View raw message