2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2016-07-15 15:43:24 -04:00
|
|
|
const common = require('../common');
|
2016-12-30 18:38:06 -05:00
|
|
|
const assert = require('assert');
|
|
|
|
const fork = require('child_process').fork;
|
2017-01-08 13:19:00 +00:00
|
|
|
const args = ['foo', 'bar'];
|
2011-05-11 00:41:16 -07:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const n = fork(common.fixturesDir + '/child-process-spawn-node.js', args);
|
2016-10-27 14:36:49 -04:00
|
|
|
|
|
|
|
assert.strictEqual(n.channel, n._channel);
|
2016-04-19 15:37:45 -07:00
|
|
|
assert.deepStrictEqual(args, ['foo', 'bar']);
|
2011-05-11 00:41:16 -07:00
|
|
|
|
|
|
|
n.on('message', function(m) {
|
|
|
|
console.log('PARENT got message:', m);
|
|
|
|
assert.ok(m.foo);
|
|
|
|
});
|
|
|
|
|
2011-12-18 01:26:00 +01:00
|
|
|
// https://github.com/joyent/node/issues/2355 - JSON.stringify(undefined)
|
|
|
|
// returns "undefined" but JSON.parse() cannot parse that...
|
|
|
|
assert.throws(function() { n.send(undefined); }, TypeError);
|
|
|
|
assert.throws(function() { n.send(); }, TypeError);
|
|
|
|
|
2011-05-11 00:41:16 -07:00
|
|
|
n.send({ hello: 'world' });
|
|
|
|
|
2016-07-15 15:43:24 -04:00
|
|
|
n.on('exit', common.mustCall(function(c) {
|
|
|
|
assert.strictEqual(c, 0);
|
|
|
|
}));
|