Skip to content

Commit

Permalink
pass the test-suite promises to tryFinish()
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudhead committed May 11, 2010
1 parent bfa2a26 commit 68e147d
Showing 1 changed file with 39 additions and 22 deletions.
61 changes: 39 additions & 22 deletions lib/vows.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function addVow(/* description & callback */) {
puts(title);
if (exception) puts(exception);
}
tryFinish(vows.remaining);
tryFinish(vows.remaining, vow.promise);
}
};

Expand Down Expand Up @@ -226,7 +226,8 @@ function addVows(tests) {
callback: ctx.tests[item],
context: ctx.name,
description: item,
binding: ctx.env
binding: ctx.env,
promise: promise
});
env = Object.create(ctx.env);

Expand All @@ -253,7 +254,7 @@ function addVows(tests) {
}
});
// Check if we're done running the tests
tryFinish(--vows.remaining);
tryFinish(--vows.remaining, promise);
// This is our initial, empty context
})(new(Context)({ callback: tests, context: null, description: null }, {}));
}
Expand All @@ -263,35 +264,51 @@ function addVows(tests) {

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

function tryFinish(remaining) {
//
// Checks if all the required tests have been run,
// and either triggers the next test suite, if any,
// or exits the process.
//
function tryFinish(remaining, promise) {
var result, style;

// Output results once all the vows have been checked
if (honored + broken + errored === total && remaining === 0) {
var result = honored + " honored, " +
broken + " broken, " +
errored + " errored",

style = honored === total ?
('green') : (errored === 0 ? 'yellow' : 'red');
result = honored + " honored, " +
broken + " broken, " +
errored + " errored",
style = honored === total ? ('green')
: (errored === 0 ? 'yellow' : 'red');

// If this isn't the last test suite in the chain,
// emit 'end', to trigger the next test suite.
if (promise.listeners('end').length > 0) {
promise.emit('end', honored, broken, errored);
} else {
if (!vows.options.brief) {
puts("\nVerified " + total + " vows in " +
(((new(Date)) - start) / 1000) + " seconds.");
puts("\n" + stylize(result, style));
}

if (!vows.options.brief) {
puts("\nVerified " + total + " vows in " +
(((new(Date)) - start) / 1000) + " seconds.");
puts("\n" + stylize(result, style));
}
// The 'finish' event is triggered once all the tests have been run.
// It's used by bin/vows
vows.promises[suites - 1].emit("finish", honored, broken, errored);

vows.promises[vows.promises.length - 1].emit("end", honored, broken, errored);
if (broken || errored) { sys.puts(buffer.join('\n') + '\n') }
if ((broken || errored) && buffer.length) { sys.puts(buffer.join('\n') + '\n') }

process.stdout.addListener('drain', function () {
process.exit(broken || errored ? 1 : 0);
});
// Don't exit until stdout is empty
process.stdout.addListener('drain', function () {
process.exit(broken || errored ? 1 : 0);
});
}
}
}

Expand Down

0 comments on commit 68e147d

Please sign in to comment.