Skip to content

Commit 521eb1e

Browse files
aaronjensenremy
authored andcommitted
fix: restart on change for non-default signals (#1409) (#1430)
Fixes #1409
1 parent 3afa52c commit 521eb1e

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

lib/monitor/run.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,9 @@ function run(options) {
243243
process.stdin.unpipe(child.stdin);
244244
}
245245

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

test/fixtures/app.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
// process.title = 'node (fixtures/app)';
22
// console.log('starting up @ ' + (process.env.PORT || 8000));
3-
require('http').createServer(function (req, res) { console.log('Request in'); res.end('ok'); }).listen(process.env.PORT || 8000);
3+
require('http').createServer(function (req, res) { console.log('Request in'); res.end('ok'); }).listen(process.env.PORT || 8000);
4+
5+
process.on('SIGINT', function() { process.exit(130) })

test/lib/require.test.js

+26-1
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,34 @@ describe('require-able', function () {
5454
setTimeout(function () {
5555
touch.sync(appjs);
5656
}, 1000);
57+
}).on('start', function() {
58+
if (restarted) {
59+
setTimeout(function() { nodemon.emit('quit') });
60+
}
61+
}).on('restart', function () {
62+
restarted = true;
63+
}).on('quit', function () {
64+
assert(restarted, 'nodemon restarted and quit properly');
65+
nodemon.reset(done);
66+
}).on('log', function (event) {
67+
// console.log(event.message);
68+
});
69+
});
70+
71+
it('should restart on file change with custom signal', function (done) {
72+
var restarted = false;
73+
74+
utils.port++;
75+
nodemon({ script: appjs, verbose: true, env: { PORT: utils.port }, signal: 'SIGINT' }).on('start', function () {
76+
setTimeout(function () {
77+
touch.sync(appjs);
78+
}, 1000);
79+
}).on('start', function() {
80+
if (restarted) {
81+
setTimeout(function() { nodemon.emit('quit') });
82+
}
5783
}).on('restart', function () {
5884
restarted = true;
59-
nodemon.emit('quit');
6085
}).on('quit', function () {
6186
assert(restarted, 'nodemon restarted and quit properly');
6287
nodemon.reset(done);

0 commit comments

Comments
 (0)