You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by an...@apache.org on 2013/05/07 03:20:35 UTC

[4/4] git commit: adding more specs for assets install/uninstall

adding more specs for assets install/uninstall


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

Branch: refs/heads/master
Commit: ca883de682d49b189e3c860d45f99d51c6b28207
Parents: e621a85
Author: Anis Kadri <an...@apache.org>
Authored: Mon May 6 18:20:28 2013 -0700
Committer: Anis Kadri <an...@apache.org>
Committed: Mon May 6 18:20:28 2013 -0700

----------------------------------------------------------------------
 spec/install.spec.js   |   10 +++++
 spec/uninstall.spec.js |   80 +++++++++++++++++++++++++++++++++++--------
 2 files changed, 75 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/ca883de6/spec/install.spec.js
----------------------------------------------------------------------
diff --git a/spec/install.spec.js b/spec/install.spec.js
index cf8acd4..c0c705b 100644
--- a/spec/install.spec.js
+++ b/spec/install.spec.js
@@ -47,8 +47,10 @@ describe('install', function() {
 
             expect(fs.existsSync(path.join(temp, 'assets', 'www', 'dummyplugin.js'))).toBe(true);
             expect(fs.existsSync(path.join(temp, 'assets', 'www', 'dummyplugin'))).toBe(true);
+            expect(fs.existsSync(path.join(temp, 'assets', 'www', 'dummyplugin', 'image.jpg'))).toBe(true);
             expect(fs.statSync(path.join(temp, 'assets', 'www', 'dummyplugin.js')).isFile()).toBe(true);
             expect(fs.statSync(path.join(temp, 'assets', 'www', 'dummyplugin')).isDirectory()).toBe(true);
+            expect(fs.statSync(path.join(temp, 'assets', 'www', 'dummyplugin', 'image.jpg')).isFile()).toBe(true);
         });
         it('should revert all assets on asset install error', function() {
             var sCopyFile = spyOn(common, 'copyFile').andCallThrough();
@@ -100,6 +102,14 @@ describe('install', function() {
     });
 
     describe('failure', function() {
+        it('should throw if asset target already exists', function() {
+            shell.cp('-rf', dummyplugin, plugins_dir);
+            var target = path.join(temp, 'assets', 'www', 'dummyplugin.js');
+            fs.writeFileSync(target, 'some bs', 'utf-8');
+            expect(function() {
+                install('android', temp, 'DummyPlugin', plugins_dir, {});
+            }).toThrow();
+        });
         it('should throw if platform is unrecognized', function() {
             expect(function() {
                 install('atari', temp, 'SomePlugin', plugins_dir, {});

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/ca883de6/spec/uninstall.spec.js
----------------------------------------------------------------------
diff --git a/spec/uninstall.spec.js b/spec/uninstall.spec.js
index f1c6b9c..c39812a 100644
--- a/spec/uninstall.spec.js
+++ b/spec/uninstall.spec.js
@@ -1,5 +1,6 @@
 var uninstall = require('../src/uninstall'),
     install = require('../src/install'),
+    common = require('../src/platforms/common'),
     android = require('../src/platforms/android'),
     ios     = require('../src/platforms/ios'),
     blackberry = require('../src/platforms/blackberry'),
@@ -12,12 +13,10 @@ var uninstall = require('../src/uninstall'),
     path    = require('path'),
     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'),
+    childbrowserplugin = path.join(__dirname, 'plugins', 'ChildBrowser'),
     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');
 
@@ -40,6 +39,38 @@ describe('uninstall', function() {
             install('android', temp, 'DummyPlugin', plugins_dir, {});
             android_uninstaller = spyOn(android, 'uninstall');
         });
+        it('should properly uninstall assets', function() {
+            var s = spyOn(common, 'removeFile').andCallThrough();
+            var s2 = spyOn(common, 'removeFileF').andCallThrough();
+            // making sure the right methods were called
+            uninstall('android', temp, 'DummyPlugin', plugins_dir, {});
+            expect(s).toHaveBeenCalled();
+            expect(s.calls.length).toEqual(2);
+            
+            expect(s2).toHaveBeenCalled();
+            expect(s2.calls.length).toEqual(1);
+
+            expect(fs.existsSync(path.join(temp, 'assets', 'www', 'dummyplugin.js'))).toBe(false);
+            expect(fs.existsSync(path.join(temp, 'assets', 'www', 'dummyplugin'))).toBe(false);
+        });
+        it('should properly revert all assets on asset uninstall error', function() {
+            var sRemoveFile = spyOn(common, 'removeFile').andCallThrough();
+            var sCopyFile = spyOn(common, 'copyFile').andCallThrough();
+            // making sure the right methods were called
+            
+            shell.rm('-rf', path.join(temp, 'assets', 'www', 'dummyplugin'));
+            
+            expect(function() {
+                uninstall('android', temp, 'DummyPlugin', plugins_dir, {});
+            }).toThrow();
+
+            expect(sRemoveFile).toHaveBeenCalled();
+            expect(sRemoveFile.calls.length).toEqual(2);
+            expect(sCopyFile).toHaveBeenCalled();
+            expect(sCopyFile.calls.length).toEqual(1);
+            
+            expect(fs.existsSync(path.join(temp, 'assets', 'www', 'dummyplugin.js'))).toBe(true);
+        });
         it('should generate and pass uninstall transaction log to appropriate platform handler\'s uninstall', function() {
             uninstall('android', temp, 'DummyPlugin', plugins_dir, {});
             var transactions = android_uninstaller.mostRecentCall.args[0];
@@ -66,18 +97,37 @@ describe('uninstall', function() {
                 uninstall('android', temp, 'SomePlugin', plugins_dir, {});
             }).toThrow('Plugin "SomePlugin" not found. Already uninstalled?');
         });
-        it('should handle a failed uninstall by passing completed transactions into appropriate handler\'s install method', function() {
-            shell.cp('-rf', faultyplugin, plugins_dir);
-            install('android', temp, 'DummyPlugin', plugins_dir, {});
+       // it('should handle a failed uninstall by passing completed transactions into appropriate handler\'s install method', function() {
+       //     shell.rm('-rf', path.join(temp, '*'));
+       //     shell.mkdir('-p', plugins_dir);
+       //     
+       //     shell.cp('-rf', ios_project, temp);
+       //     shell.cp('-rf', childbrowserplugin, plugins_dir);
+       //     install('ios', temp, 'ChildBrowser', plugins_dir, {});
 
-            // make uninstall fail by removing a js asset
-            shell.rm(path.join(temp, 'assets', 'www', 'dummyplugin.js'));
-            var s = spyOn(android, 'install');
-            uninstall('android', temp, 'DummyPlugin', plugins_dir, {});
-            var executed_txs = s.mostRecentCall.args[0];
-            expect(executed_txs.length).toEqual(1);
-            // It only ended up "uninstalling" one source file, so install reversion should pass in that source file to re-install
-            expect(executed_txs[0].tag).toEqual('source-file');
-        }); 
+       //     // make uninstall fail by removing a js asset
+       //     shell.rm(path.join(temp, 'SampleApp', 'Plugins', 'ChildBrowserCommand.m'));
+       //     var s = spyOn(ios, 'install');
+       //     uninstall('ios', temp, 'ChildBrowser', plugins_dir, {});
+       //     var executed_txs = s.mostRecentCall.args[0];
+       //     expect(executed_txs.length).toEqual(1);
+       //     // It only ended up "uninstalling" one source file, so install reversion should pass in that source file to re-install
+       //     expect(executed_txs[0].tag).toEqual('source-file');
+       // });
+        it('should revert assets when uninstall fails', function() {
+            install('android', temp, 'DummyPlugin', plugins_dir, {});
+            
+            var s = spyOn(common, 'copyFile').andCallThrough();
+            
+            shell.rm('-rf', path.join(temp, 'src', 'com', 'phonegap', 'plugins', 'dummyplugin'));
+            expect(function() {
+                uninstall('android', temp, 'DummyPlugin', plugins_dir, {});
+            }).toThrow();
+            expect(s).toHaveBeenCalled();
+            expect(s.calls.length).toEqual(2);
+            
+            expect(fs.existsSync(path.join(temp, 'assets', 'www', 'dummyplugin.js'))).toBe(true);
+            expect(fs.existsSync(path.join(temp, 'assets', 'www', 'dummyplugin'))).toBe(true);
+        });
     });
 });