8000 Fix: Change & tests for failing child processes (fixes #24) · gulpjs/async-done@0224d42 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0224d42

Browse files
tunnckoCorephated
tunnckoCore
authored andcommitted
Fix: Change & tests for failing child processes (fixes #24)
1 parent 8d4d04c commit 0224d42

File tree

3 files changed

+60
-27
lines changed

3 files changed

+60
-27
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function asyncDone(fn, cb){
4040
if(result && typeof result.on === 'function'){
4141
// assume node stream
4242
d.add(result);
43-
eos(exhaust(result), eosConfig, onSuccess);
43+
eos(exhaust(result), eosConfig, done);
4444
return;
4545
}
4646

test/child_processes.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
'use strict';
2+
3+
var lab = exports.lab = require('lab').script();
4+
var describe = lab.describe;
5+
var it = lab.it;
6+
var expect = require('code').expect;
7+
8+
var cp = require('child_process');
9+
var asyncDone = require('../');
10+
11+
12+
function execSuccess(){
13+
return cp.exec('echo hello world');
14+
}
15+
16+
function execFail(){
17+
return cp.exec('foo-bar-baz hello world');
18+
}
19+
20+
function spawnSuccess(){
21+
return cp.spawn('echo', ['hello world']);
22+
}
23+
24+
function spawnFail(){
25+
return cp.spawn('foo-bar-baz', ['hello world']);
26+
}
27+
28+
describe('child processes', function(){
29+
it('should handle successful exec', function(done){
30+
asyncDone(execSuccess, function(err){
31+
expect(err).to.not.be.instanceof(Error);
32+
done();
33+
});
34+
});
35+
36+
it('should handle failing exec', function(done){
37+
asyncDone(execFail, function(err){
38+
expect(err).to.be.an.instanceof(Error);
39+
done();
40+
});
41+
});
42+
43+
it('should handle successful spawn', function(done){
44+
asyncDone(spawnSuccess, function(err){
45+
expect(err).to.not.be.instanceof(Error);
46+
done();
47+
});
48+
});
49+
50+
it('should handle failing spawn', function(done){
51+
asyncDone(spawnFail, function(err){
52+
expect(err).to.be.an.instanceof(Error);
53+
done();
54+
});
55+
});
56+
});

test/streams.js

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,10 @@ function unpiped(){
3737
return fs.createReadStream(exists);
3838
}
3939

40-
function exec(){
41-
return cp.exec('echo hello world');
42-
}
43-
44-
function spawn(){
45-
return cp.spawn('echo', ['hello world']);
46-
}
47-
4840
describe('streams', function(){
49-
5041
it('should handle a successful stream', function(done){
5142
asyncDone(success, function(err){
52-
expect(err).to.equal(null);
43+
expect(err).to.not.be.instanceof(Error);
5344
done();
5445
});
5546
});
@@ -65,29 +56,15 @@ describe('streams', function(){
6556
asyncDone(function(cb){
6657
return success().on('end', function(){ cb(null, 3); });
6758
}, function(err, result){
68-
expect(err).to.equal(null);
59+
expect(err).to.not.be.instanceof(Error);
6960
expect(result).to.equal(3); // to know we called the callback
7061
done();
7162
});
7263
});
7364

7465
it('consumes an unpiped readable stream', function(done){
7566
asyncDone(unpiped, function(err){
76-
expect(err).to.equal(null);
77-
done();
78-
});
79-
});
80-
81-
it('should handle exec', function(done){
82-
asyncDone(exec, function(err){
83-
expect(err).to.equal(null);
84-
done();
85-
});
86-
});
87-
88-
it('should handle spawn', function(done){
89-
asyncDone(spawn, function(err){
90-
expect(err).to.equal(null);
67+
expect(err).to.not.be.instanceof(Error);
9168
done();
9269
});
9370
});

0 commit comments

Comments
 (0)
0