Files
archived-nodemon/test/lib/require.test.js
2013-12-14 20:20:27 +00:00

57 lines
1.5 KiB
JavaScript

'use strict';
/*global describe:true, it: true, afterEach: true */
var nodemon = require('../../lib/'),
assert = require('assert'),
path = require('path'),
touch = require('touch'),
appjs = path.resolve(__dirname, '..', 'fixtures', 'app.js');
describe('require-able', function () {
afterEach(function (){
nodemon.emit('quit');
nodemon.removeAllListners();
});
it('should know nodemon has been required', function () {
assert(nodemon.config.required, 'nodemon has required property');
});
it('should restart on file change', function (done) {
var restarted = false;
nodemon({ script: appjs, verbose: true }).on('start', function () {
setTimeout(function () {
touch.sync(appjs);
}, 1000);
}).on('restart', function () {
restarted = true;
nodemon.emit('quit');
}).on('quit', function () {
assert(restarted, 'nodemon restarted and quit properly');
nodemon.removeAllListners();
done();
}).on('log', function (event) {
// console.log(event.message);
});
});
it('should be restartable', function (done) {
var restarted = false;
nodemon(appjs).on('start', function () {
setTimeout(function () {
nodemon.restart();
}, 1000);
}).on('restart', function () {
restarted = true;
nodemon.emit('quit');
}).on('quit', function () {
assert(restarted);
// unbind events for testing again
nodemon.removeAllListners();
done();
});
});
});