Early testing for event tests

This commit is contained in:
Remy Sharp
2014-12-09 11:09:29 +00:00
parent 9cde007226
commit 80e8f7598f
4 changed files with 118 additions and 2 deletions

View File

@@ -10,6 +10,19 @@ util.inherits(Bus, events.EventEmitter);
var bus = new Bus();
/*
var collected = {};
bus.on('newListener', function (event) {
if (!collected[event]) {
collected[event] = true;
bus.on(event, function (e) {
console.log('>> ' + event);
});
}
});
//*/
// proxy process messages (if forked) to the bus
process.on('message', function (event) {
bus.emit(event);

View File

@@ -0,0 +1,82 @@
'use strict';
/*global describe:true, it: true, afterEach: true */
var nodemon = require('../../lib/'),
assert = require('assert'),
path = require('path'),
touch = require('touch'),
utils = require('../utils'),
appjs = path.resolve(__dirname, '..', 'fixtures', 'env.js');
describe('events should follow normal flow on user triggered change', function () {
// after(function (done) {
// nodemon.once('exit', function () {
// nodemon.reset();
// done();
// }).emit('quit');
// });
before(function (done) {
nodemon.reset(done);
});
var run = 0;
it('start', function (done) {
var plan = new utils.Plan(2, done);
nodemon.once('start', function () {
run++;
plan.assert(true, '"start" event');
});
});
it('config:update', function (done) {
nodemon.on('config:update', function () {
assert(true, '"config:update" event');
done();
});
});
it('exit', function (done) {
var plan = new utils.Plan(3, done);
nodemon.on('exit', function () {
plan.assert(true, '"exit" event');
if (run === 1) {
setTimeout(function () {
plan.assert(true, 'restarting');
touch.sync(appjs);
}, 1000);
} else if (run === 2) {
plan.assert(true, 'finished');
} else {
plan.assert(false, 'quit too many times: ' + run);
}
});
})
it('stdout', function (done) {
nodemon.on('stdout', function (data) {
assert(true, '"stdout" event with: ' + data);
done();
});
});
// }).on('stderr', function (data) {
// assert(true, '"stderr" event with: ' + data);
it('restart', function (done) {
nodemon.on('restart', function (files) {
assert(true, '"restart" event with ' + files);
assert(files[0] === appjs, 'restart due to ' + files.join(' ') + ' changing');
done();
});
});
utils.port++;
nodemon({
script: appjs,
verbose: true,
stdout: false,
noReset: true,
env: { PORT: utils.port, USER: 'nodemon' },
});
});

View File

@@ -1,4 +1,4 @@
http = require 'http'
server = http.createServer (req, res) -> res.end 'hi\n'
server.listen 8000
console.log "Listening on port 8000"
server.listen process.env.PORT
console.log "Listening..."

View File

@@ -2,6 +2,7 @@
var fork = require('child_process').fork,
path = require('path'),
appjs = path.resolve(__dirname, 'fixtures', 'app.js'),
assert = require('assert'),
port = 8000,
appcoffee = path.resolve(__dirname, 'fixtures', 'app.coffee');
@@ -79,7 +80,27 @@ function cleanup(p, done, err) {
}
}
function Plan(count, done) {
this.done = done;
this.count = count;
}
Plan.prototype.ok = function() {
assert.apply(null, arguments);
if (this.count === 0) {
assert(false, 'Too many assertions called');
} else {
this.count--;
}
if (this.count === 0) {
this.done();
}
};
module.exports = {
Plan: Plan,
asCLI: asCLI,
match: match,
run: run,