node/deps/npm/node_modules/child-process-close/test/test-fork.js

42 lines
762 B
JavaScript
Raw Normal View History

2013-05-11 08:45:37 +08:00
require('../index');
var assert = require('assert'),
fork = require('child_process').fork;
var cp = fork('worker-fork');
var gotMessage = false,
gotExit = false,
gotClose = false;
cp.on('message', function(msg) {
assert.strictEqual(msg, 'hello');
assert(!gotMessage);
assert(!gotClose);
gotMessage = 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(gotMessage);
assert(!gotClose);
gotClose = true;
});
process.on('exit', function() {
assert(gotMessage);
assert(gotExit);
assert(gotClose);
});