summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/child-process-close/test/test-exec.js
blob: 5072d02951c5df573e6c159025fd3d7f06810525 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

require('../index');

var assert = require('assert'),
    exec = require('child_process').exec;

var cp = exec('echo hello', function(err) {
  assert(!err);
});

var stdoutData = '',
    stdoutEnd = false,
    gotExit = false,
    gotClose = false;

cp.stdout.setEncoding('ascii');

cp.stdout.on('data', function(data) {
  assert(!stdoutEnd);
  stdoutData += data;
});

cp.stdout.on('end', function() {
  assert(!stdoutEnd);
  assert(/^hello/.test(stdoutData));
  stdoutEnd = true;
});

cp.on('exit', function(code, signal) {
  assert.strictEqual(code, 0);
  assert(!signal);
  assert(!gotExit);
  assert(!gotClose);
  gotExit = true;
});

cp.on('close', function(code, signal) {
  assert.strictEqual(code, 0);
  assert(!signal);
  assert(gotExit);
  assert(stdoutEnd);
  assert(!gotClose);
  gotClose = true;
});

process.on('exit', function() {
  assert(stdoutEnd);
  assert(gotExit);
  assert(gotClose);
});