Files
node/test/parallel/test-process-wrap.js
T
Gibson Fahnestock db61c952de test: use eslint to fix var->const/let
Manually fix issues that eslint --fix couldn't do automatically.

Backport-PR-URL: https://github.com/nodejs/node/pull/11775
PR-URL: https://github.com/nodejs/node/pull/10685
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
2017-04-18 20:01:49 -04:00

65 lines
1.3 KiB
JavaScript

'use strict';
require('../common');
const assert = require('assert');
const Process = process.binding('process_wrap').Process;
const Pipe = process.binding('pipe_wrap').Pipe;
const pipe = new Pipe();
const p = new Process();
let processExited = false;
let gotPipeEOF = false;
let gotPipeData = false;
p.onexit = function(exitCode, signal) {
console.log('exit');
p.close();
pipe.readStart();
assert.equal(0, exitCode);
assert.equal(0, signal);
processExited = true;
};
pipe.onread = function(err, b, off, len) {
assert.ok(processExited);
if (b) {
gotPipeData = true;
console.log('read %d', len);
} else {
gotPipeEOF = true;
pipe.close();
}
};
p.spawn({
file: process.execPath,
args: [process.execPath, '-v'],
stdio: [
{ type: 'ignore' },
{ type: 'pipe', handle: pipe },
{ type: 'ignore' }
]
});
// 'this' safety
// https://github.com/joyent/node/issues/6690
assert.throws(function() {
const notp = { spawn: p.spawn };
notp.spawn({
file: process.execPath,
args: [process.execPath, '-v'],
stdio: [
{ type: 'ignore' },
{ type: 'pipe', handle: pipe },
{ type: 'ignore' }
]
});
}, TypeError);
process.on('exit', function() {
assert.ok(processExited);
assert.ok(gotPipeEOF);
assert.ok(gotPipeData);
});