does not create a directory for files
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugman/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugman/commit/c2c528e1 Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/c2c528e1 Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/c2c528e1 Branch: refs/heads/future Commit: c2c528e17a6b22f98dfc8257c13e2e3796c5d802 Parents: 9b83bc3 Author: Anis Kadri <[email protected]> Authored: Tue Apr 2 20:03:07 2013 -0700 Committer: Anis Kadri <[email protected]> Committed: Tue Apr 2 20:03:07 2013 -0700 ---------------------------------------------------------------------- platforms/ios.js | 17 +++-- test/plugman.js | 150 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 160 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/c2c528e1/platforms/ios.js ---------------------------------------------------------------------- diff --git a/platforms/ios.js b/platforms/ios.js index edddbeb..6473936 100644 --- a/platforms/ios.js +++ b/platforms/ios.js @@ -96,13 +96,16 @@ exports.handlePlugin = function (action, project_dir, plugin_dir, plugin_et, var var targetPath = path.resolve( project_dir, assetsDir, asset.attrib['target']); - var stat = fs.statSync(srcPath); - if(stat.isDirectory()) { - shell.mkdir('-p', targetPath); - checkLastCommand(); - } if (action == 'install') { - shell.cp('-r', srcPath, targetPath); + var stat = fs.statSync(srcPath); + if(stat.isDirectory()) { + shell.mkdir('-p', targetPath); + checkLastCommand(); + shell.cp('-r', srcPath, targetPath); + checkLastCommand(); + } else { + shell.cp(srcPath, targetPath); + } checkLastCommand(); } else { shell.rm('-rf', targetPath); @@ -364,7 +367,7 @@ function updateConfig(action, config_path, plugin_et) { updatePlistFile(action, config_path, plugin_et); } } - +// throws error if last command returns code != 0 function checkLastCommand() { if(shell.error() != null) throw {name: "ShellError", message: shell.error()}; } http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/c2c528e1/test/plugman.js ---------------------------------------------------------------------- diff --git a/test/plugman.js b/test/plugman.js new file mode 100644 index 0000000..0222085 --- /dev/null +++ b/test/plugman.js @@ -0,0 +1,150 @@ +/* + * + * 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. + * +*/ + +var fs = require('fs') + , path = require('path') + , osenv = require('osenv') + , shell = require('shelljs') + , util = require('util') + , plugman_exe = path.join(__dirname, '..', 'plugman.js') + , test_dir = path.join(osenv.tmpdir(), 'test_plugman'); + +exports.setUp = function(callback) { + shell.mkdir('-p', test_dir); + callback(); +} + +exports.tearDown = function(callback) { + // remove the temp files (projects and plugins) + shell.rm('-rf', test_dir); + callback(); +} + +exports['should list all plugins'] = function (test) { + + var command = util.format('%s %s --list', shell.which('node'), plugman_exe), + options = {silent: true}, + ret = shell.exec(command, options); + test.equal(0, ret.code); + test.ok(ret.output); + test.done(); + +} + +exports['should install and uninstall ios plugin'] = function (test) { + var test_project_dir = path.join(test_dir, 'ios-config-xml'), + test_plugin_dir = path.join(test_dir, 'WebNotifications'), + srcDir = path.resolve(test_project_dir, 'SampleApp/Plugins'), + options = {silent: true}, + command; + + // copy the ios test project to a temp directory + shell.cp('-r', path.join(__dirname, 'projects', 'ios-config-xml'), test_dir); + + // copy the ios test plugin to a temp directory + shell.cp('-r', path.join(__dirname, 'plugins', 'WebNotifications'), test_dir); + + command = util.format('%s %s --platform ios --project %s --plugin %s', shell.which('node'), + plugman_exe, + test_project_dir, + test_plugin_dir + ); + var ret = shell.exec(command, options); + test.equal(0, ret.code); + test.equal("plugin installed\n", ret.output); + + test.ok(fs.existsSync(srcDir + '/WebNotifications.m')) + test.ok(fs.existsSync(srcDir + '/WebNotifications.h')); + + command = util.format('%s %s --remove --platform ios --project %s --plugin %s', shell.which('node'), + plugman_exe, + test_project_dir, + test_plugin_dir + ); + var ret = shell.exec(command, options); + test.equal(0, ret.code); + test.equal("plugin uninstalled\n", ret.output); + + test.ok(!fs.existsSync(srcDir + '/WebNotifications.m')) + test.ok(!fs.existsSync(srcDir + '/WebNotifications.h')); + + test.done(); +} + +exports['should revert ios install on failures'] = function (test) { + var test_project_dir = path.join(test_dir, 'ios-config-xml'), + test_plugin_dir = path.join(test_dir, 'FaultyPlugin'), + srcDir = path.resolve(test_project_dir, 'SampleApp/Plugins'), + options = {silent: false}, + command; + + // copy the ios test project to a temp directory + shell.cp('-r', path.join(__dirname, 'projects', 'ios-config-xml'), test_dir); + + // copy the ios test plugin to a temp directory + shell.cp('-r', path.join(__dirname, 'plugins', 'FaultyPlugin'), test_dir); + + command = util.format('%s %s --platform ios --project %s --plugin %s', shell.which('node'), + plugman_exe, + test_project_dir, + test_plugin_dir + ); + var ret = shell.exec(command, options); + test.equal(0, ret.code); + //console.log(ret.output); + test.notEqual("plugin installed\n", ret.output); + + test.ok(!fs.existsSync(srcDir + '/FaultyPlugin.m')) + test.ok(!fs.existsSync(srcDir + '/FaultyPlugin.h')); + + test.done(); +} + +exports['should install and uninstall android plugin'] = function (test) { + var test_project_dir = path.join(test_dir, 'android_two'), + test_plugin_dir = path.join(test_dir, 'ChildBrowser'), + options = {silent: true}, + command; + + // copy the ios test project to a temp directory + shell.cp('-r', path.join(__dirname, 'projects', 'android_two'), test_dir); + + // copy the ios test plugin to a temp directory + shell.cp('-r', path.join(__dirname, 'plugins', 'ChildBrowser'), test_dir); + + command = util.format('%s %s --platform android --project %s --plugin %s', shell.which('node'), + plugman_exe, + test_project_dir, + test_plugin_dir + ); + var ret = shell.exec(command, options); + test.equal(0, ret.code); + test.equal("plugin installed\n", ret.output); + + command = util.format('%s %s --remove --platform android --project %s --plugin %s', shell.which('node'), + plugman_exe, + test_project_dir, + test_plugin_dir + ); + var ret = shell.exec(command, options); + test.equal(0, ret.code); + test.equal("plugin uninstalled\n", ret.output); + + test.done(); +}
