mirror of
https://github.com/SrIzan10/nodemon.git
synced 2026-05-01 10:55:09 +00:00
Fixed nodemon.once. Add config.run. Tests not 100% passing
Something weird is happening with required nodemon and re-running lots of times, that somehow resets the config. I know it's due to my tests, but I'm unsure which one is actually causing the damn issue. Anyway, bed for me, it's almost 2am. Sod this for a game of cricket.
This commit is contained in:
@@ -12,6 +12,5 @@ if (notifier.update) {
|
||||
}
|
||||
|
||||
var options = cli.parse(process.argv);
|
||||
options.restartable = 'rs';
|
||||
|
||||
nodemon(options);
|
||||
@@ -1,5 +1,6 @@
|
||||
// default options for config.options
|
||||
module.exports = {
|
||||
restartable: 'rs',
|
||||
execMap: {
|
||||
py: 'python',
|
||||
rb: 'ruby'
|
||||
|
||||
@@ -25,6 +25,7 @@ function reset() {
|
||||
}
|
||||
|
||||
var config = {
|
||||
run: false,
|
||||
system: {
|
||||
noWatch: false,
|
||||
watchWorks: false,
|
||||
|
||||
@@ -152,6 +152,9 @@ run.kill = noop;
|
||||
run.restart = noop;
|
||||
|
||||
bus.on('quit', function () {
|
||||
// immediately try to stop any polling
|
||||
config.run = false;
|
||||
|
||||
// remove event listener
|
||||
var exit = function () {
|
||||
exit = noop; // null out in case of race condition
|
||||
|
||||
@@ -157,11 +157,13 @@ function filterAndRestart(files) {
|
||||
}
|
||||
|
||||
if (config.system.noWatch || config.options.forceLegacyWatch) {
|
||||
setTimeout(monitor, config.timeout);
|
||||
if (config.run) {
|
||||
setTimeout(watch, config.timeout);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var monitor = module.exports = function () {
|
||||
var watch = module.exports = function () {
|
||||
// if we have noWatch or watchWorks (i.e. not using `find`)
|
||||
// then called `changeFunction` which is local to this script
|
||||
if ((config.system.noWatch || config.system.watchWorks) && !config.options.forceLegacyWatch) {
|
||||
|
||||
@@ -125,6 +125,7 @@ function nodemon(settings) {
|
||||
}
|
||||
}
|
||||
|
||||
config.run = true;
|
||||
monitor.run(config.options);
|
||||
});
|
||||
|
||||
@@ -148,7 +149,7 @@ nodemon.once = function (event, handler) {
|
||||
if (!eventHandlers[event]) { eventHandlers[event] = []; }
|
||||
eventHandlers[event].push(handler);
|
||||
bus.once(event, function () {
|
||||
eventHandlers[event].splice(eventHandlers[event].indexOf(handler), 0);
|
||||
eventHandlers[event].splice(eventHandlers[event].indexOf(handler), 1);
|
||||
handler.apply(this, arguments);
|
||||
});
|
||||
return nodemon;
|
||||
@@ -166,7 +167,7 @@ nodemon.removeAllListners = function (event) {
|
||||
}).forEach(function (event) {
|
||||
eventHandlers[event].forEach(function (handler) {
|
||||
bus.removeListener(event, handler);
|
||||
eventHandlers[event].splice(eventHandlers[event].indexOf(handler), 0);
|
||||
eventHandlers[event].splice(eventHandlers[event].indexOf(handler), 1);
|
||||
});
|
||||
// delete eventHandlers[event];
|
||||
});
|
||||
@@ -177,6 +178,7 @@ nodemon.removeAllListners = function (event) {
|
||||
nodemon.reset = function () {
|
||||
nodemon.removeAllListners();
|
||||
utils.reset();
|
||||
config.run = false;
|
||||
};
|
||||
|
||||
// expose the full config
|
||||
|
||||
@@ -51,7 +51,7 @@ Logger.prototype.required = function (val) {
|
||||
Logger.prototype.debug = false;
|
||||
Logger.prototype._log = function (type, msg) {
|
||||
if (required) {
|
||||
bus.emit('log', { type: type, message: msg, colour: msg });
|
||||
bus.emit('log', { type: type, message: msg || '', colour: msg || '' });
|
||||
} else if (type === 'error') {
|
||||
util.error(msg);
|
||||
} else {
|
||||
|
||||
@@ -18,10 +18,12 @@ describe('config load', function () {
|
||||
utils.home = oldhome;
|
||||
});
|
||||
|
||||
after(function () {
|
||||
after(function (done) {
|
||||
// clean up just in case.
|
||||
nodemon.emit('quit');
|
||||
nodemon.reset();
|
||||
nodemon.once('exit', function () {
|
||||
nodemon.reset();
|
||||
done();
|
||||
}).emit('quit');
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -54,7 +54,6 @@ describe('nodemon fork child restart', function () {
|
||||
},
|
||||
output: function (data) {
|
||||
var msg = colour.strip(data.trim());
|
||||
console.log(data.trim());
|
||||
if (utils.match(msg, 'changes after filters')) {
|
||||
var changes = msg.slice(-5).split('/');
|
||||
var restartedOn = changes.pop();
|
||||
|
||||
@@ -7,9 +7,11 @@ var nodemon = require('../../lib/'),
|
||||
appjs = path.resolve(__dirname, '..', 'fixtures', 'app.js');
|
||||
|
||||
describe('require-able', function () {
|
||||
afterEach(function (){
|
||||
nodemon.emit('quit');
|
||||
nodemon.reset()
|
||||
afterEach(function (done) {
|
||||
nodemon.once('exit', function () {
|
||||
nodemon.reset();
|
||||
done();
|
||||
}).emit('quit');
|
||||
});
|
||||
|
||||
it('should know nodemon has been required', function () {
|
||||
@@ -28,7 +30,7 @@ describe('require-able', function () {
|
||||
nodemon.emit('quit');
|
||||
}).on('quit', function () {
|
||||
assert(restarted, 'nodemon restarted and quit properly');
|
||||
nodemon.reset()
|
||||
nodemon.reset();
|
||||
done();
|
||||
}).on('log', function (event) {
|
||||
// console.log(event.message);
|
||||
@@ -47,8 +49,8 @@ describe('require-able', function () {
|
||||
nodemon.emit('quit');
|
||||
}).on('quit', function () {
|
||||
assert(restarted);
|
||||
nodemon.reset();
|
||||
// unbind events for testing again
|
||||
nodemon.reset()
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -10,11 +10,13 @@ var nodemon = require('../../lib/'),
|
||||
describe('when nodemon runs', function () {
|
||||
var tmp = path.resolve('test/fixtures/test' + crypto.randomBytes(16).toString('hex') + '.js');
|
||||
|
||||
after(function () {
|
||||
after(function (done) {
|
||||
fs.unlink(tmp);
|
||||
// clean up just in case.
|
||||
nodemon.emit('quit');
|
||||
nodemon.reset()
|
||||
nodemon.once('exit', function () {
|
||||
nodemon.reset();
|
||||
done();
|
||||
}).emit('quit');
|
||||
});
|
||||
|
||||
it('should wait when the script crashes', function (done) {
|
||||
@@ -28,9 +30,10 @@ describe('when nodemon runs', function () {
|
||||
}, 1000);
|
||||
}).on('restart', function () {
|
||||
assert(true, 'nodemon restarted');
|
||||
nodemon.emit('quit');
|
||||
nodemon.reset()
|
||||
done();
|
||||
nodemon.once('exit', function () {
|
||||
nodemon.reset();
|
||||
done();
|
||||
}).emit('quit');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -47,9 +50,10 @@ describe('when nodemon runs', function () {
|
||||
}, 500);
|
||||
}).on('restart', function () {
|
||||
assert(true, 'nodemon restarted');
|
||||
nodemon.emit('quit');
|
||||
nodemon.reset()
|
||||
done();
|
||||
nodemon.once('exit', function () {
|
||||
nodemon.reset();
|
||||
done();
|
||||
}).emit('quit');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -71,8 +75,7 @@ describe('when nodemon runs', function () {
|
||||
assert(false, 'detected crashed state');
|
||||
}).on('exit', function () {
|
||||
assert(true, 'quit correctly');
|
||||
nodemon.emit('quit');
|
||||
nodemon.reset()
|
||||
nodemon.reset();
|
||||
done();
|
||||
|
||||
setTimeout(function () {
|
||||
|
||||
@@ -25,9 +25,10 @@ describe('nodemon monitor child restart', function () {
|
||||
fs.unlink(tmpjs);
|
||||
fs.unlink(tmpmd);
|
||||
// clean up just in case.
|
||||
bus.once('exit', done);
|
||||
nodemon.emit('quit');
|
||||
nodemon.reset();
|
||||
nodemon.once('exit', function () {
|
||||
nodemon.reset();
|
||||
done();
|
||||
}).emit('quit');
|
||||
});
|
||||
|
||||
it('should happen when monitoring a single extension', function (done) {
|
||||
@@ -39,15 +40,16 @@ describe('nodemon monitor child restart', function () {
|
||||
}, 1000);
|
||||
}).on('restart', function () {
|
||||
assert(true, 'nodemon restarted');
|
||||
bus.once('exit', done);
|
||||
nodemon.emit('quit');
|
||||
nodemon.reset();
|
||||
nodemon.once('exit', function () {
|
||||
nodemon.reset();
|
||||
done();
|
||||
}).emit('quit');
|
||||
});
|
||||
});
|
||||
|
||||
it('should happen when monitoring multiple extensions', function (done) {
|
||||
write(true);
|
||||
setTimeout(function () {
|
||||
write(true);
|
||||
|
||||
nodemon({
|
||||
script: tmpjs,
|
||||
@@ -64,9 +66,10 @@ describe('nodemon monitor child restart', function () {
|
||||
var changes = msg.trim().slice(-5).split('/');
|
||||
var restartedOn = changes.pop();
|
||||
assert(restartedOn === '1', 'nodemon restarted on a single file change');
|
||||
bus.once('exit', done);
|
||||
nodemon.emit('quit');
|
||||
nodemon.reset();
|
||||
nodemon.once('exit', function () {
|
||||
nodemon.reset();
|
||||
done();
|
||||
}).emit('quit');
|
||||
}
|
||||
});
|
||||
}, 2000);
|
||||
@@ -91,9 +94,10 @@ describe('nodemon monitor child restart', function () {
|
||||
var changes = msg.trim().slice(-5).split('/');
|
||||
var restartedOn = changes.pop();
|
||||
assert(restartedOn === '1', 'nodemon restarted when watched directory');
|
||||
nodemon.once('exit', done);
|
||||
nodemon.emit('quit');
|
||||
nodemon.reset();
|
||||
nodemon.once('exit', function () {
|
||||
nodemon.reset();
|
||||
done();
|
||||
}).emit('quit');
|
||||
}
|
||||
});
|
||||
}, 2000);
|
||||
|
||||
Reference in New Issue
Block a user