cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fil...@apache.org
Subject [48/50] [abbrv] cordova-lib git commit: CB-12557: add both stdout and stderr properties to the error object passed to superspawn reject handler.
Date Thu, 09 Mar 2017 20:39:51 GMT
CB-12557: add both stdout and stderr properties to the error object passed to superspawn reject
handler.


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

Branch: refs/heads/common-2.0.x
Commit: c744fafc6ffc985cf80f0abb2fa799111331a07f
Parents: b0402b9
Author: filmaj <maj.fil@gmail.com>
Authored: Thu Mar 9 07:18:34 2017 -0800
Committer: filmaj <maj.fil@gmail.com>
Committed: Thu Mar 9 07:51:16 2017 -0800

----------------------------------------------------------------------
 cordova-common/spec/superspawn.spec.js | 35 +++++++++++++++++++++++++++++
 cordova-common/src/superspawn.js       |  6 +++++
 2 files changed, 41 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/c744fafc/cordova-common/spec/superspawn.spec.js
----------------------------------------------------------------------
diff --git a/cordova-common/spec/superspawn.spec.js b/cordova-common/spec/superspawn.spec.js
index 73a85d9..104073b 100644
--- a/cordova-common/spec/superspawn.spec.js
+++ b/cordova-common/spec/superspawn.spec.js
@@ -53,4 +53,39 @@ describe('spawn method', function() {
         });
     });
 
+    it('Test 004 : reject handler should pass in Error object with stdout and stderr properties',
function(done) {
+        var cp = require('child_process');
+        spyOn(cp, 'spawn').and.callFake(function(cmd, args, opts) {
+            return {
+                stdout:{
+                    setEncoding: function(){},
+                    on: function(evt, handler) {
+                        // some sample stdout output
+                        handler('business as usual');
+                    }
+                },
+                stderr:{
+                    setEncoding: function(){},
+                    on: function(evt, handler) {
+                        // some sample stderr output
+                        handler('mayday mayday');
+                    }
+                },
+                on: function(evt, handler) {
+                    // What's passed to handler here is the exit code, so we can control
+                    // resolve/reject flow via this argument.
+                    handler(1); // this will trigger error flow
+                },
+                removeListener: function() {}
+            };
+        });
+        superspawn.spawn('this aggression', ['will', 'not', 'stand', 'man'], {})
+        .catch(function(err) {
+            expect(err).toBeDefined();
+            expect(err.stdout).toContain('usual');
+            expect(err.stderr).toContain('mayday');
+            done();
+        });
+    });
+
 });

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/c744fafc/cordova-common/src/superspawn.js
----------------------------------------------------------------------
diff --git a/cordova-common/src/superspawn.js b/cordova-common/src/superspawn.js
index a3f1431..96ec09d 100644
--- a/cordova-common/src/superspawn.js
+++ b/cordova-common/src/superspawn.js
@@ -167,6 +167,12 @@ exports.spawn = function(cmd, args, opts) {
                 errMsg += ' Error output:\n' + capturedErr.trim();
             }
             var err = new Error(errMsg);
+            if (capturedErr) {
+                err.stderr = capturedErr;
+            }
+            if (capturedOut) {
+                err.stdout = capturedOut;
+            }
             err.code = code;
             d.reject(err);
         }


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


Mime
View raw message