Skip to content

Commit

Permalink
fix: restart on change for non-default signals (remy#1409) (remy#1430)
Browse files Browse the repository at this point in the history
Fixes remy#1409
  • Loading branch information
aaronjensen authored and remy committed Nov 5, 2018
1 parent 3afa52c commit 521eb1e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/monitor/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ function run(options) {
process.stdin.unpipe(child.stdin);
}

if (utils.isWindows) {
// For the on('exit', ...) handler above the following looks like a
// crash, so we set the killedAfterChange flag
// For the on('exit', ...) handler above the following looks like a
// crash, so we set the killedAfterChange flag if a restart is planned
if (!noRestart) {
killedAfterChange = true;
}

Expand Down
4 changes: 3 additions & 1 deletion test/fixtures/app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// process.title = 'node (fixtures/app)';
// console.log('starting up @ ' + (process.env.PORT || 8000));
require('http').createServer(function (req, res) { console.log('Request in'); res.end('ok'); }).listen(process.env.PORT || 8000);
require('http').createServer(function (req, res) { console.log('Request in'); res.end('ok'); }).listen(process.env.PORT || 8000);

process.on('SIGINT', function() { process.exit(130) })
27 changes: 26 additions & 1 deletion test/lib/require.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,34 @@ describe('require-able', function () {
setTimeout(function () {
touch.sync(appjs);
}, 1000);
}).on('start', function() {
if (restarted) {
setTimeout(function() { nodemon.emit('quit') });
}
}).on('restart', function () {
restarted = true;
}).on('quit', function () {
assert(restarted, 'nodemon restarted and quit properly');
nodemon.reset(done);
}).on('log', function (event) {
// console.log(event.message);
});
});

it('should restart on file change with custom signal', function (done) {
var restarted = false;

utils.port++;
nodemon({ script: appjs, verbose: true, env: { PORT: utils.port }, signal: 'SIGINT' }).on('start', function () {
setTimeout(function () {
touch.sync(appjs);
}, 1000);
}).on('start', function() {
if (restarted) {
setTimeout(function() { nodemon.emit('quit') });
}
}).on('restart', function () {
restarted = true;
nodemon.emit('quit');
}).on('quit', function () {
assert(restarted, 'nodemon restarted and quit properly');
nodemon.reset(done);
Expand Down

0 comments on commit 521eb1e

Please sign in to comment.