Skip to content

Commit

Permalink
Merge pull request #102 from seebees/master
Browse files Browse the repository at this point in the history
tests hang when the topic inherits from EventEmitter
  • Loading branch information
Alexis Sellier committed Jul 25, 2011
2 parents 661b34f + 96a17a2 commit 76565ef
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/vows/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ this.Suite.prototype = new(function () {

// If the topic doesn't return an event emitter (such as a promise),
// we create it ourselves, and emit the value on the next tick.
if (! (topic && topic.constructor === events.EventEmitter)) {
if (! (topic instanceof events.EventEmitter)) {
ctx.emitter = new(events.EventEmitter);

if (! ctx._callback) {
Expand Down
133 changes: 133 additions & 0 deletions test/testInherit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
* instanceof is a more complete check then .constructor ===
*
* It works when using node's built-in util.inherits function
* and it also honors a class's entire ancestry
*
* Here I am only testing the change to vows in suite.js at line 147 to change
* the check from .constructor === to instanceof. These tests should demonstrate
* that this change should work both cases. For completness I also check
* the case when EventEmitter is an ancestor, not the parent Class.
*
*/
var EventEmitter = process.EventEmitter,
util = require('util'),
vows = require('vows'),
assert = require('assert');

vows.describe('EventEmitters as a return value from a topic').addBatch({
'returning an EventEmitter' : {
topic : function () {
//Make an event emitter
var tmp = new EventEmitter();
//set it to emit success in a bit
setTimeout(function () {
//pass a value to make sure this all works
tmp.emit('success', 'I work');
}, 10);

return tmp;
},
'will catch what I pass to success' : function (ret) {
assert.strictEqual(ret, 'I work');
}
},
'returning a class that uses util.inherit to inherit from EventEmitter' : {
topic : function () {
//Make a class that will util.inherit from EventEmitter
var Class = function () {
EventEmitter.call(this);
},
tmp;

//inherit from EventEmitter
util.inherits(Class, EventEmitter);
//Get a new one
tmp = new Class();
//set it to emit success in a bit
setTimeout(function () {
//pass a value to make sure this all works
tmp.emit('success', 'I work');
}, 10);

return tmp;
},
'will catch what I pass to success' : function (ret) {
assert.strictEqual(ret, 'I work');
}
},
'returning a class that uses Class.prototype = new EventEmitter()' : {
topic : function () {
//Make a class that will inherit from EventEmitter
var Class = function () {}, tmp;
//inherit
Class.prototype = new EventEmitter();
//Get a new one
tmp = new Class();
//set it to emit success in a bit
setTimeout(function () {
//pass a value to make sure this all works
tmp.emit('success', 'I work');
}, 10);

return tmp;
},
'will catch what I pass to success' : function (ret) {
assert.strictEqual(ret, 'I work');
}
},
'returning a class that uses util.inherit to inherit from a class that inherits from EventEmitter ' : {
topic : function () {
//Class1 inherits from EventEmitter
var Class1 = function () {
var self = this;
EventEmitter.call(self);
},
//Class2 inherits from Class1
Class2 = function () {
Class1.call(this);
}, tmp;
//Inherit
util.inherits(Class1, EventEmitter);
util.inherits(Class2, Class1);
//Get a new one
tmp = new Class2();
//set it to emit success in a bit
setTimeout(function () {
//pass a value to make sure this all works
tmp.emit('success', 'I work');
},10);

return tmp;
},
'will catch what I pass to success' : function (ret) {
assert.strictEqual(ret, 'I work');
}
},
'returning a class that uses Class2.prototype = new Class1() and Class1.prototype = new EventEmitter()' : {
topic : function () {
//Class1 will inherit from EventEmitter
var Class1 = function () {},
//Class2 will inherit from Class1
Class2 = function () {}, tmp;
//Inherit
Class1.prototype = new EventEmitter();
Class2.prototype = new Class1();
//Get a new one
tmp = new Class2();
//seit it to emit success in a bit
setTimeout(function () {
//pass a value to make sure this all works
tmp.emit('success', 'I work');
},10);

return tmp;
},
'will catch what I pass to success' : function (ret) {
assert.strictEqual(ret, 'I work');
}
}
}).export(module);



1 comment on commit 76565ef

@AndrewVos
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests don't run at all now (when working on the code). This merge made this happen:

~/Desktop/vows ± make test

node.js:134
        throw e; // process.nextTick error, or 'error' event on first tick
        ^
Error: Cannot find module 'vows'
    at Function._resolveFilename (module.js:317:11)
    at Function._load (module.js:262:25)
    at require (module.js:346:19)
    at Object.<anonymous> (/Users/andrewvos/Desktop/vows/test/testInherit.js:15:12)
    at Module._compile (module.js:402:26)
    at Object..js (module.js:408:10)
    at Module.load (module.js:334:31)
    at Function._load (module.js:293:12)
    at require (module.js:346:19)
    at /Users/andrewvos/Desktop/vows/bin/vows:382:19
make: *** [test] Error 1

Please sign in to comment.