cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bra...@apache.org
Subject git commit: Add tests for --prepare behavior
Date Tue, 16 Apr 2013 19:25:18 GMT
Updated Branches:
  refs/heads/future 7e8192511 -> 3a6777ada


Add tests for --prepare behavior

Checks for:
- cordova_plugins.json with appropriate entries
- copying the JS file into www/plugins/com.foo.id/path/to/file.js
- copying <asset> files.
- copying <asset> directories.


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

Branch: refs/heads/future
Commit: 3a6777adad8429c81bbe905b794c0296fa54e738
Parents: 7e81925
Author: Braden Shepherdson <braden.shepherdson@gmail.com>
Authored: Tue Apr 16 15:24:11 2013 -0400
Committer: Braden Shepherdson <braden.shepherdson@gmail.com>
Committed: Tue Apr 16 15:24:11 2013 -0400

----------------------------------------------------------------------
 test/android-one-install.js                        |   48 +++++++++++---
 test/android-two-install.js                        |   46 +++++++++++--
 test/plugins/ChildBrowser/plugin.xml               |    6 ++-
 .../ChildBrowser/www/childbrowser_file.html        |    1 +
 test/prepare.js                                    |   51 +++++++++++++++
 5 files changed, 134 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/3a6777ad/test/android-one-install.js
----------------------------------------------------------------------
diff --git a/test/android-one-install.js b/test/android-one-install.js
index ade18a2..e839bd6 100644
--- a/test/android-one-install.js
+++ b/test/android-one-install.js
@@ -72,19 +72,33 @@ exports['should install webless plugin'] = function (test) {
 exports['should move the js file'] = function (test) {
     var pluginsPath = path.join(test_dir, 'plugins');
     var wwwPath = path.join(test_dir, 'projects', 'android_one', 'assets', 'www');
-    var jsPath = path.join(test_dir, 'projects', 'android_one', 'assets', 'www', 'childbrowser.js');
-    
+    var jsPath = path.join(test_dir, 'projects', 'android_one', 'assets', 'www', 'plugins',
'com.phonegap.plugins.childbrowser', 'www', 'childbrowser.js');
+
     android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et, { APP_ID:
12345 });
     plugin_loader.handlePrepare(test_project_dir, pluginsPath, wwwPath, 'android');
-    
-    fs.stat(jsPath, function(err, stats) {
-        test.ok(!err);
-        test.ok(stats.isFile());
-        test.done();
-    });
+
+    var stats = fs.statSync(jsPath);
+    test.ok(stats);
+    test.ok(stats.isFile());
+    test.done();
 }
 
-exports['should move the directory'] = function (test) {
+exports['should move the asset file'] = function(test) {
+    var pluginsPath = path.join(test_dir, 'plugins');
+    var wwwPath = path.join(test_dir, 'projects', 'android_one', 'assets', 'www');
+
+    android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et, { APP_ID:
12345 });
+    plugin_loader.handlePrepare(test_project_dir, pluginsPath, wwwPath, 'android');
+
+    var assetPath = path.join(test_dir, 'projects', 'android_one', 'assets', 'www', 'childbrowser_file.html');
+    var assets = fs.statSync(assetPath);
+
+    test.ok(assets);
+    test.ok(assets.isFile());
+    test.done();
+}
+
+exports['should move the asset directory'] = function (test) {
     var pluginsPath = path.join(test_dir, 'plugins');
     var wwwPath = path.join(test_dir, 'projects', 'android_one', 'assets', 'www');
     
@@ -99,6 +113,22 @@ exports['should move the directory'] = function (test) {
     test.done();
 }
 
+exports['should add entries to the cordova_plugins.json file'] = function(test) {
+    var pluginsPath = path.join(test_dir, 'plugins');
+    var wwwPath = path.join(test_dir, 'projects', 'android_one', 'assets', 'www');
+
+    android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et, { APP_ID:
12345 });
+    plugin_loader.handlePrepare(test_project_dir, pluginsPath, wwwPath, 'android');
+
+    var jsonPath = path.join(wwwPath, 'cordova_plugins.json');
+    var content = JSON.parse(fs.readFileSync(jsonPath, 'utf-8'));
+
+    test.ok(content);
+    test.ok(content.length > 0);
+    test.ok(content[0].file);
+    test.done();
+};
+
 exports['should move the src file'] = function (test) {
     var pluginsPath = path.join(test_dir, 'plugins');
     var wwwPath = path.join(test_dir, 'projects', 'android_one', 'assets', 'www');

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/3a6777ad/test/android-two-install.js
----------------------------------------------------------------------
diff --git a/test/android-two-install.js b/test/android-two-install.js
index 8664383..a406a3b 100644
--- a/test/android-two-install.js
+++ b/test/android-two-install.js
@@ -73,23 +73,37 @@ exports['should install webless plugin'] = function (test) {
 exports['should move the js file'] = function (test) {
     var pluginsPath = path.join(test_dir, 'plugins');
     var wwwPath = path.join(test_dir, 'projects', 'android_two', 'assets', 'www');
-    var jsPath = path.join(test_dir, 'projects', 'android_two', 'assets', 'www', 'childbrowser.js');
+    var jsPath = path.join(test_dir, 'projects', 'android_two', 'assets', 'www', 'plugins',
'com.phonegap.plugins.childbrowser', 'www', 'childbrowser.js');
 
     android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et, { APP_ID:
12345 });
     plugin_loader.handlePrepare(test_project_dir, pluginsPath, wwwPath, 'android');
 
-    fs.stat(jsPath, function(err, stats) {
-        test.ok(!err);
-        test.ok(stats.isFile());
-        test.done();
-    });
+    var stats = fs.statSync(jsPath);
+    test.ok(stats);
+    test.ok(stats.isFile());
+    test.done();
 }
 
-exports['should move the directory'] = function (test) {
+exports['should move the asset file'] = function(test) {
+    var pluginsPath = path.join(test_dir, 'plugins');
+    var wwwPath = path.join(test_dir, 'projects', 'android_two', 'assets', 'www');
+
+    android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et, { APP_ID:
12345 });
+    plugin_loader.handlePrepare(test_project_dir, pluginsPath, wwwPath, 'android');
+
+    var assetPath = path.join(test_dir, 'projects', 'android_two', 'assets', 'www', 'childbrowser_file.html');
+    var assets = fs.statSync(assetPath);
+
+    test.ok(assets);
+    test.ok(assets.isFile());
+    test.done();
+}
+
+exports['should move the asset directory'] = function (test) {
     var pluginsPath = path.join(test_dir, 'plugins');
     var wwwPath = path.join(test_dir, 'projects', 'android_two', 'assets', 'www');
     
-    android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et);
+    android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et, { APP_ID:
12345 });
     plugin_loader.handlePrepare(test_project_dir, pluginsPath, wwwPath, 'android');
     
     var assetPath = path.join(test_dir, 'projects', 'android_two', 'assets', 'www', 'childbrowser');
@@ -100,6 +114,22 @@ exports['should move the directory'] = function (test) {
     test.done();
 }
 
+exports['should add entries to the cordova_plugins.json file'] = function(test) {
+    var pluginsPath = path.join(test_dir, 'plugins');
+    var wwwPath = path.join(test_dir, 'projects', 'android_two', 'assets', 'www');
+
+    android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et, { APP_ID:
12345 });
+    plugin_loader.handlePrepare(test_project_dir, pluginsPath, wwwPath, 'android');
+
+    var jsonPath = path.join(wwwPath, 'cordova_plugins.json');
+    var content = JSON.parse(fs.readFileSync(jsonPath, 'utf-8'));
+
+    test.ok(content);
+    test.ok(content.length > 0);
+    test.ok(content[0].file);
+    test.done();
+};
+
 exports['should move the src file'] = function (test) {
     var pluginsPath = path.join(test_dir, 'plugins');
     var wwwPath = path.join(test_dir, 'projects', 'android_two', 'assets', 'www');

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/3a6777ad/test/plugins/ChildBrowser/plugin.xml
----------------------------------------------------------------------
diff --git a/test/plugins/ChildBrowser/plugin.xml b/test/plugins/ChildBrowser/plugin.xml
index caff701..9c87b06 100644
--- a/test/plugins/ChildBrowser/plugin.xml
+++ b/test/plugins/ChildBrowser/plugin.xml
@@ -25,8 +25,12 @@
 
     <name>Child Browser</name>
 
-    <asset src="www/childbrowser.js" target="childbrowser.js" />
     <asset src="www/childbrowser" target="childbrowser" />
+    <asset src="www/childbrowser_file.html" target="childbrowser_file.html" />
+
+    <js-module src="www/childbrowser.js" name="ChildBrowser">
+        <clobbers target="childbrowser" />
+    </js-module>
 
     <access origin="build.phonegap.com" />
     <access origin="$APP_ID.s3.amazonaws.com" />

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/3a6777ad/test/plugins/ChildBrowser/www/childbrowser_file.html
----------------------------------------------------------------------
diff --git a/test/plugins/ChildBrowser/www/childbrowser_file.html b/test/plugins/ChildBrowser/www/childbrowser_file.html
new file mode 100644
index 0000000..6de7b8c
--- /dev/null
+++ b/test/plugins/ChildBrowser/www/childbrowser_file.html
@@ -0,0 +1 @@
+This is a test file.

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/3a6777ad/test/prepare.js
----------------------------------------------------------------------
diff --git a/test/prepare.js b/test/prepare.js
new file mode 100644
index 0000000..30e0ec8
--- /dev/null
+++ b/test/prepare.js
@@ -0,0 +1,51 @@
+/*
+ *
+ * Copyright 2013 Braden Shepherdson
+ *
+ * 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.
+ *
+*/
+
+var path = require('path'),
+    shell = require('shelljs'),
+    osenv = require('osenv'),
+    et = require('elementtree'),
+    test_dir = path.join(osenv.tmpdir(), 'test_plugman'),
+    test_project_dir = path.join(test_dir, 'projects', 'android_one'),
+    test_plugin_dir = path.join(test_dir, 'plugins', 'ChildBrowser'),
+    xml_path = path.join(test_plugin_dir, 'plugin.xml'),
+    plugin_loader = require(path.join(__dirname, '..', 'util', 'plugin_loader'));
+
+exports.setUp = function(callback) {
+    shell.mkdir('-p', test_dir);
+    
+    // copy the ios test project to a temp directory
+    shell.cp('-r', path.join(__dirname, 'projects'), test_dir);
+
+    // copy the ios test plugin to a temp directory
+    shell.cp('-r', path.join(__dirname, 'plugins'), test_dir);
+
+    // parse the plugin.xml into an elementtree object
+    xml_text   = fs.readFileSync(xml_path, 'utf-8')
+    plugin_et  = new et.ElementTree(et.XML(xml_text));
+
+    callback();
+}
+
+exports.tearDown = function(callback) {
+    // remove the temp files (projects and plugins)
+    shell.rm('-rf', test_dir);
+    callback();
+}
+


Mime
View raw message