Skip to content

Commit b926718

Browse files
santigimenobnoordhuis
authored andcommitted
test: fix test-child-process-stdout-flush-exit
Make sure all the stdout data is available before performing the assertions. Fixes: #944 PR-URL: #1868 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent d20f018 commit b926718

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

test/parallel/test-child-process-stdout-flush-exit.js

+6-13
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ if (process.argv[2] === 'child') {
1818
// spawn self as child
1919
var child = spawn(process.argv[0], [process.argv[1], 'child']);
2020

21-
var gotHello = false;
22-
var gotBye = false;
21+
var stdout = '';
2322

2423
child.stderr.setEncoding('utf8');
2524
child.stderr.on('data', function(data) {
@@ -30,17 +29,11 @@ if (process.argv[2] === 'child') {
3029
// check if we receive both 'hello' at start and 'goodbye' at end
3130
child.stdout.setEncoding('utf8');
3231
child.stdout.on('data', function(data) {
33-
if (data.slice(0, 6) == 'hello\n') {
34-
gotHello = true;
35-
} else if (data.slice(data.length - 8) == 'goodbye\n') {
36-
gotBye = true;
37-
} else {
38-
gotBye = false;
39-
}
32+
stdout += data;
4033
});
4134

42-
child.on('close', function(data) {
43-
assert(gotHello);
44-
assert(gotBye);
45-
});
35+
child.on('close', common.mustCall(function() {
36+
assert.equal(stdout.slice(0, 6), 'hello\n');
37+
assert.equal(stdout.slice(stdout.length - 8), 'goodbye\n');
38+
}));
4639
}

0 commit comments

Comments
 (0)