Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Extract class-level events into events.js

  • Loading branch information...
commit 6aef344f1d09a36fe85d1af5e372c0e18dfd8d50 1 parent dc9fb06
@joelplane joelplane authored
Showing with 17 additions and 24 deletions.
  1. +1 −10 context.js
  2. +12 −1 events.js
  3. +1 −1  noodleTest.js
  4. +3 −12 test.js
View
11 context.js
@@ -11,16 +11,7 @@ module.exports = (function(Test){
Context.emit('new', this);
}
sys.inherits(Context, EventEmitter);
- /* class-level event emitter for Context class */
- (function(){
- var emitter = new EventEmitter();
- Context.on = function(eventName, callback) {
- emitter.on(eventName, callback);
- };
- Context.emit = function(eventName, object) {
- emitter.emit(eventName, object);
- };
- })();
+ events.classEvents(Context);
Context.prototype.context = function(name, callback) {
var ctx = new Context(name, this);
this.subContexts.push(ctx);
View
13 events.js
@@ -7,8 +7,19 @@ module.exports = (function(){
});
});
};
+ var classEvents = function(klass) {
+ /* class-level event emitter */
+ var emitter = new EventEmitter();
+ klass.on = function(eventName, callback) {
+ emitter.on(eventName, callback);
+ };
+ klass.emit = function(eventName, object) {
+ emitter.emit(eventName, object);
+ };
+ };
return {
EventEmitter: EventEmitter,
- relayEvents: relayEvents
+ relayEvents: relayEvents,
+ classEvents: classEvents
};
})();
View
2  noodleTest.js
@@ -36,7 +36,7 @@ module.exports = (function(config){
return q;
})();
- var Test = require('./test')(Assertion, testQueue, config);
+ var Test = require('./test')(Assertion, testQueue, config.timeout);
/* Relay events emitted by Test instances to the main object */
Test.on('new', function(t){
View
15 test.js
@@ -1,4 +1,4 @@
-module.exports = (function(Assertion, testQueue, config){
+module.exports = (function(Assertion, testQueue, timeout){
var events = require('./events');
var EventEmitter = events.EventEmitter;
var sys = require('sys');
@@ -13,16 +13,7 @@ module.exports = (function(Assertion, testQueue, config){
testQueue.put(this);
};
sys.inherits(Test, EventEmitter);
- /* class-level event emitter for Test class */
- (function(){
- var emitter = new EventEmitter();
- Test.on = function(eventName, callback) {
- emitter.on(eventName, callback);
- };
- Test.emit = function(eventName, object) {
- emitter.emit(eventName, object);
- };
- })();
+ events.classEvents(Test);
Test.prototype._call = function() {
var test = this;
this.emit('testStarted', this);
@@ -32,7 +23,7 @@ module.exports = (function(Assertion, testQueue, config){
};
var timer = setTimeout(function(){
test.emit('testTimeout', test);
- }, config.timeout);
+ }, timeout);
try {
this.testFunction.call(this, done);
} catch(error) {
Please sign in to comment.
Something went wrong with that request. Please try again.