fix: use fork child node processes

* heisian-master:
  fix: get tests to pass
  fix: travis CI build before-install
  test: fork child node processes
This commit is contained in:
Remy Sharp
2017-12-12 18:00:16 +00:00
3 changed files with 35 additions and 26 deletions

View File

@@ -4,6 +4,7 @@ var bus = utils.bus;
var childProcess = require('child_process');
var spawn = childProcess.spawn;
var exec = childProcess.exec;
var fork = childProcess.fork;
var watch = require('./watch').watch;
var config = require('../config');
var child = null; // the actual child process we spawn
@@ -82,7 +83,17 @@ function run(options) {
});
}
child = spawn.apply(null, spawnArgs);
if (executable === 'node') {
var forkArgs = cmd.args.slice(1);
var env = utils.merge(options.execOptions.env, process.env);
stdio.push('ipc');
child = fork(options.execOptions.script, forkArgs, {
env: env,
stdio: stdio,
});
} else {
child = spawn.apply(null, spawnArgs);
}
if (config.required) {
var emit = {

View File

@@ -79,7 +79,8 @@ function watch() {
}
watchedFiles.push(file);
total++;
watchedFiles = Array.from(new Set(watchedFiles)); // ensure no dupes
total = watchedFiles.length;
debug('watching dir: %s', file);
});
watcher.on('ready', function () {

View File

@@ -153,32 +153,29 @@ describe('when nodemon runs (2)', function () {
}, 1500);
});
// it('should kill child on SIGINT', function (done) {
// fs.writeFileSync(tmp, 'setTimeout(function () { var n = 10; }, 10000)');
it('should kill child on SIGINT', function (done) {
fs.writeFileSync(tmp, 'setTimeout(function () { var n = 10; }, 10000)');
// nodemon({ script: tmp, verbose: true }).on('start', function () {
// assert(true, 'nodemon is waiting for a change');
nodemon({ script: tmp, verbose: true }).on('start', function () {
assert(true, 'nodemon is waiting for a change');
// setTimeout(function () {
// // process.once('SIGINT', function () {
// // // do nothing
// // console.log('not going to exit');
// // });
setTimeout(function () {
process.once('SIGINT', function () {
// do nothing
});
// process.kill(process.pid, 'SIGINT');
// }, 1000);
// }).on('crash', function () {
// assert(false, 'detected crashed state');
// }).on('exit', function () {
// assert(true, 'quit correctly');
// nodemon.reset();
// done();
process.kill(process.pid, 'SIGINT');
}, 1000);
}).on('crash', function () {
assert(false, 'detected crashed state');
}).on('exit', function () {
assert(true, 'quit correctly');
nodemon.reset();
done();
// setTimeout(function () {
// process.kill(process.pid, 'SIGINT');
// }, 1000);
// });
// });
setTimeout(function () {
process.kill(process.pid, 'SIGINT');
}, 1000);
});
});
});