You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ra...@apache.org on 2019/06/18 02:50:09 UTC

[cordova-common] branch master updated: Promise handling cleanup in specs (#79)

This is an automated email from the ASF dual-hosted git repository.

raphinesse pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-common.git


The following commit(s) were added to refs/heads/master by this push:
     new fe684d2  Promise handling cleanup in specs (#79)
fe684d2 is described below

commit fe684d2a0fa7eddd986add87e4a90f8c22010d69
Author: Raphael von der GrĂ¼n <ra...@gmail.com>
AuthorDate: Tue Jun 18 04:50:05 2019 +0200

    Promise handling cleanup in specs (#79)
    
    * Proper expected rejection check in ActionStack spec
    
    * Clean up Promise handling in PluginManager spec
    
    * Remove usage of jasmine's done in sync specs
    
    * Clean up Promise handling in superspawn spec
---
 spec/ActionStack.spec.js   | 15 +++++++--------
 spec/PluginManager.spec.js | 28 ++++++----------------------
 spec/plist-helpers.spec.js |  8 ++------
 spec/superspawn.spec.js    | 25 +++++++++++++------------
 4 files changed, 28 insertions(+), 48 deletions(-)

diff --git a/spec/ActionStack.spec.js b/spec/ActionStack.spec.js
index 44df820..496d73b 100644
--- a/spec/ActionStack.spec.js
+++ b/spec/ActionStack.spec.js
@@ -41,7 +41,7 @@ describe('action-stack', function () {
             expect(second_spy).toHaveBeenCalledWith(second_args[0]);
             expect(third_spy).toHaveBeenCalledWith(third_args[0]);
         });
-        it('Test 002 : should revert processed actions if an exception occurs', function (done) {
+        it('Test 002 : should revert processed actions if an exception occurs', function () {
             spyOn(console, 'log');
             var first_spy = jasmine.createSpy();
             var first_args = [1];
@@ -57,13 +57,12 @@ describe('action-stack', function () {
             stack.push(stack.createAction(first_spy, first_args, first_reverter, first_reverter_args));
             stack.push(stack.createAction(second_spy, second_args, function () {}, []));
             stack.push(stack.createAction(third_spy, third_args, function () {}, []));
+
             // process should throw
-            var error;
-            stack.process('android', android_one_project)
-                .then(function () {
-                    expect(false).toBe(true);
-                }).fail(function (err) {
-                    error = err;
+            return stack.process('android', android_one_project)
+                .then(() => {
+                    fail('Expected promise to be rejected');
+                }, error => {
                     expect(error).toEqual(process_err);
                     // first two actions should have been called, but not the third
                     expect(first_spy).toHaveBeenCalledWith(first_args[0]);
@@ -71,7 +70,7 @@ describe('action-stack', function () {
                     expect(third_spy).not.toHaveBeenCalledWith(third_args[0]);
                     // first reverter should have been called after second action exploded
                     expect(first_reverter).toHaveBeenCalledWith(first_reverter_args[0]);
-                }).fin(done);
+                });
         });
     });
 });
diff --git a/spec/PluginManager.spec.js b/spec/PluginManager.spec.js
index b54133a..9c54277 100644
--- a/spec/PluginManager.spec.js
+++ b/spec/PluginManager.spec.js
@@ -58,7 +58,6 @@ describe('PluginManager class', function () {
     describe('instance', function () {
         var actions, manager;
         var FAKE_PROJECT;
-        var fail = jasmine.createSpy('fail');
         var ActionStackOrig = PluginManager.__get__('ActionStack');
 
         beforeEach(function () {
@@ -84,8 +83,8 @@ describe('PluginManager class', function () {
                 expect(manager.addPlugin(new PluginInfo(DUMMY_PLUGIN), {})).not.toHaveBeenRejected(done);
             });
 
-            it('Test 004 : should iterate through all plugin\'s files and frameworks', function (done) {
-                manager.addPlugin(new PluginInfo(DUMMY_PLUGIN), {})
+            it('Test 004 : should iterate through all plugin\'s files and frameworks', () => {
+                return manager.addPlugin(new PluginInfo(DUMMY_PLUGIN), {})
                     .then(function () {
                         expect(FAKE_PROJECT.getInstaller.calls.count()).toBe(16);
                         expect(FAKE_PROJECT.getUninstaller.calls.count()).toBe(16);
@@ -93,43 +92,28 @@ describe('PluginManager class', function () {
                         expect(actions.push.calls.count()).toBe(16);
                         expect(actions.process).toHaveBeenCalled();
                         expect(FAKE_PROJECT.write).toHaveBeenCalled();
-                    })
-                    .fail(fail)
-                    .done(function () {
-                        expect(fail).not.toHaveBeenCalled();
-                        done();
                     });
             });
 
-            it('Test 005 : should save plugin metadata to www directory', function (done) {
+            it('Test 005 : should save plugin metadata to www directory', () => {
                 var metadataPath = path.join(manager.locations.www, 'cordova_plugins.js');
                 var platformWwwMetadataPath = path.join(manager.locations.platformWww, 'cordova_plugins.js');
 
-                manager.addPlugin(new PluginInfo(DUMMY_PLUGIN), {})
+                return manager.addPlugin(new PluginInfo(DUMMY_PLUGIN), {})
                     .then(function () {
                         expect(fs.writeFileSync).toHaveBeenCalledWith(metadataPath, jasmine.any(String), 'utf-8');
                         expect(fs.writeFileSync).not.toHaveBeenCalledWith(platformWwwMetadataPath, jasmine.any(String), 'utf-8');
-                    })
-                    .fail(fail)
-                    .done(function () {
-                        expect(fail).not.toHaveBeenCalled();
-                        done();
                     });
             });
 
-            it('Test 006 : should save plugin metadata to both www ans platform_www directories when options.usePlatformWww is specified', function (done) {
+            it('Test 006 : should save plugin metadata to both www ans platform_www directories when options.usePlatformWww is specified', () => {
                 var metadataPath = path.join(manager.locations.www, 'cordova_plugins.js');
                 var platformWwwMetadataPath = path.join(manager.locations.platformWww, 'cordova_plugins.js');
 
-                manager.addPlugin(new PluginInfo(DUMMY_PLUGIN), { usePlatformWww: true })
+                return manager.addPlugin(new PluginInfo(DUMMY_PLUGIN), { usePlatformWww: true })
                     .then(function () {
                         expect(fs.writeFileSync).toHaveBeenCalledWith(metadataPath, jasmine.any(String), 'utf-8');
                         expect(fs.writeFileSync).toHaveBeenCalledWith(platformWwwMetadataPath, jasmine.any(String), 'utf-8');
-                    })
-                    .fail(fail)
-                    .done(function () {
-                        expect(fail).not.toHaveBeenCalled();
-                        done();
                     });
             });
         });
diff --git a/spec/plist-helpers.spec.js b/spec/plist-helpers.spec.js
index fc4c923..031216f 100644
--- a/spec/plist-helpers.spec.js
+++ b/spec/plist-helpers.spec.js
@@ -43,7 +43,7 @@ describe('prunePLIST', function () {
 
     var selector = 'FirstConfigKey';
 
-    it('Test 01: should remove property from plist file using provided selector', function (done) {
+    it('Test 01: should remove property from plist file using provided selector', () => {
         var pruneStatus = plistHelpers.prunePLIST(doc, xml, selector);
 
         expect(pruneStatus).toBeTruthy();
@@ -54,8 +54,6 @@ describe('prunePLIST', function () {
                 }
             }
         );
-
-        done();
     });
 });
 
@@ -74,7 +72,7 @@ describe('plistGraft', function () {
 
     let selector = 'keychain-access-groups';
 
-    it('Test 01: should not mangle existing plist entries', function (done) {
+    it('Test 01: should not mangle existing plist entries', () => {
         var graftStatus = plistHelpers.graftPLIST(doc, xml, selector);
 
         expect(graftStatus).toBeTruthy();
@@ -86,7 +84,5 @@ describe('plistGraft', function () {
                 ]
             }
         );
-
-        done();
     });
 });
diff --git a/spec/superspawn.spec.js b/spec/superspawn.spec.js
index 9c05129..ddd3b50 100644
--- a/spec/superspawn.spec.js
+++ b/spec/superspawn.spec.js
@@ -36,25 +36,25 @@ describe('spawn method', function () {
         expect(Q.isPromise(superspawn.spawn('invalid_command'))).toBe(true);
     });
 
-    it('Test 002 : should notify about stdout "data" events', function (done) {
-        superspawn.spawn(LS, [], { stdio: 'pipe' })
+    it('Test 002 : should notify about stdout "data" events', () => {
+        return superspawn.spawn(LS, [], { stdio: 'pipe' })
             .progress(progressSpy)
-            .fin(function () {
+            .then(function () {
                 expect(progressSpy).toHaveBeenCalledWith({ 'stdout': jasmine.any(String) });
-                done();
             });
     });
 
-    it('Test 003 : should notify about stderr "data" events', function (done) {
-        superspawn.spawn(LS, ['doesnt-exist'], { stdio: 'pipe' })
+    it('Test 003 : should notify about stderr "data" events', () => {
+        return superspawn.spawn(LS, ['doesnt-exist'], { stdio: 'pipe' })
             .progress(progressSpy)
-            .fin(function () {
+            .then(() => {
+                fail('Expected promise to be rejected');
+            }, () => {
                 expect(progressSpy).toHaveBeenCalledWith({ 'stderr': jasmine.any(String) });
-                done();
             });
     });
 
-    it('Test 004 : reject handler should pass in Error object with stdout and stderr properties', function (done) {
+    it('Test 004 : reject handler should pass in Error object with stdout and stderr properties', () => {
         var cp = require('child_process');
         spyOn(cp, 'spawn').and.callFake(function (cmd, args, opts) {
             return {
@@ -80,12 +80,13 @@ describe('spawn method', function () {
                 removeListener: function () {}
             };
         });
-        superspawn.spawn('this aggression', ['will', 'not', 'stand', 'man'], {})
-            .catch(function (err) {
+        return superspawn.spawn('this aggression', ['will', 'not', 'stand', 'man'], {})
+            .then(() => {
+                fail('Expected promise to be rejected');
+            }, err => {
                 expect(err).toBeDefined();
                 expect(err.stdout).toContain('usual');
                 expect(err.stderr).toContain('mayday');
-                done();
             });
     });
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org