Skip to content

Commit

Permalink
Buffer test output, return EventEmitter.
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudhead committed May 2, 2010
1 parent f6d27ac commit 1d14683
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
22 changes: 20 additions & 2 deletions lib/vows.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ var total = 0, honored = 0,
// Context stack, used in addVow() to keep track
var lastContext;

// Output buffer
var buffer;

//
// Assertion Macros
//
Expand Down Expand Up @@ -123,6 +126,15 @@ function addVow(/* description & callback */) {
}
};

function puts() {
var args = Array.prototype.slice.call(arguments);
if (vows.promise.listeners('end').length > 0) {
buffer.push(args.join('\n'));
} else {
sys.puts.apply(null, args);
}
}

function tryFinish(remaining) {
// Output results once all the vows have been checked
if (honored + broken + errored === total && remaining === 0) {
Expand Down Expand Up @@ -180,7 +192,12 @@ vows.tell = function (topic, tests) {
this.tests = tests;
this.remaining = 0;

var matcher = new(RegExp)(process.argv[2] || '.*');
// Reset values
total = 0, honored = 0,
broken = 0, errored = 0;
buffer = [];

this.promise = new(events.EventEmitter);

function Context(vow, ctx) {
this.tests = vow.callback;
Expand All @@ -196,7 +213,7 @@ vows.tell = function (topic, tests) {
}

// We run the tests asynchronously, for added flexibility
return process.nextTick(function () {
process.nextTick(function () {
var setup, vow;

if (typeof topic === 'string' && tests) sys.puts('\n' + stylize(topic, 'underline') + '\n');
Expand Down Expand Up @@ -294,6 +311,7 @@ vows.tell = function (topic, tests) {
})(new(Context)(new(Vow)(vows.tests, null, null), {}));
}
});
return this.promise;
};


Expand Down
4 changes: 3 additions & 1 deletion test/vows-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ var api = vows.prepare({
var promiser = function (val) {
return function () {
var promise = new(events.EventEmitter);
setTimeout(function () {
process.nextTick(function () { promise.emit('success', val) });
}, 200);
return promise;
}
};

vows.tell("Vows", {
return vows.tell("Vows", {
"A context": {
setup: promiser("hello world"),

Expand Down

0 comments on commit 1d14683

Please sign in to comment.