Skip to content

Commit

Permalink
no more global module state
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudhead committed Jun 5, 2010
1 parent f825f7f commit aae87c2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 38 deletions.
4 changes: 1 addition & 3 deletions bin/vows
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ if (args.length === 0) {
options.reporter = reporter = require('vows/reporters/watch');
}

vows.config(options);

msg('bin', 'argv', args);
msg('bin', 'options', { reporter: options.reporter.name, matcher: options.matcher });

Expand Down Expand Up @@ -263,7 +261,7 @@ function runSuites(suites, callback) {
var suite = suites.shift();
if (suite) {
msg('runner', "running", suite.subject);
suite.run(function (result) {
suite.run(options, function (result) {
Object.keys(result).forEach(function (k) {
results[k] += result[k];
});
Expand Down
31 changes: 3 additions & 28 deletions lib/vows.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,14 @@ vows.inspect = function inspect(val) {
};

vows.prepare = require('vows/extras').prepare;
vows.tryEnd = require('vows/suite').tryEnd;

//
// Assertion Macros & Extensions
//
require('./assert/error');
require('./assert/macros');

//
// Checks if all the tests in the batch have been run,
// and triggers the next batch (if any), by emitting the 'end' event.
//
vows.tryEnd = function (batch) {
var result, style, time;

if (batch.honored + batch.broken + batch.errored === batch.total &&
batch.remaining === 0) {

Object.keys(batch).forEach(function (k) {
(k in batch.suite.results) && (batch.suite.results[k] += batch[k]);
});

vows.reporter.report(['end']);
batch.promise.emit('end', batch.honored, batch.broken, batch.errored);
}
}

//
// Suite constructor
//
Expand Down Expand Up @@ -131,9 +113,9 @@ function addVow(vow) {
if (exception || !vows.options.brief) {
if (vow.context && batch.lastContext !== vow.context) {
batch.lastContext = vow.context;
vows.reporter.report(['context', vow.context]);
batch.suite.report(['context', vow.context]);
}
vows.reporter.report(['vow', {
batch.suite.report(['vow', {
title: vow.description,
status: status,
exception: exception || null
Expand Down Expand Up @@ -165,10 +147,3 @@ vows.describe = function (subject) {

return suite;
};

// Return the `vows` object after setting some options
vows.config = function (opts) {
for (var k in opts) { this.options[k] = opts[k] }
return this;
};

38 changes: 31 additions & 7 deletions lib/vows/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ require.paths.unshift(path.join(__dirname, '..'));

var vows = require('vows');
var Context = require('vows/context').Context;
var tryEnd = vows.tryEnd;

this.Suite = function (subject) {
this.subject = subject;
Expand Down Expand Up @@ -110,8 +109,8 @@ 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 instanceof vows.options.Emitter)) {
ctx.emitter = new(vows.options.Emitter);
if (! (topic instanceof events.EventEmitter)) {
ctx.emitter = new(events.EventEmitter);

if (! ctx._callback) {
process.nextTick(function (val) {
Expand Down Expand Up @@ -174,20 +173,26 @@ this.Suite.prototype = new(function () {
});
// Check if we're done running the tests
batch.remaining --;
tryEnd(batch);
exports.tryEnd(batch);
// This is our initial, empty context
})(new(Context)({ callback: tests, context: null, description: null }, {}));
}
return promise;
};

this.run = function (callback) {
this.report = function () {
return this.reporter.report.apply(this.reporter, arguments);
};

this.run = function (options, callback) {
var that = this;
var start = new(Date);

this.matcher = options.matcher || vows.options.matcher;
this.reporter = options.reporter || vows.options.reporter;
this.reset();

vows.reporter.report(['subject', this.subject]);
this.report(['subject', this.subject]);

(function run(batches) {
var batch;
Expand All @@ -199,7 +204,7 @@ this.Suite.prototype = new(function () {
} else {
that.results.time = (new(Date) - start) / 1000;

vows.reporter.report(['finish', that.results]);
that.report(['finish', that.results]);

if (callback) { callback(that.results) }

Expand All @@ -221,3 +226,22 @@ this.Suite.prototype = new(function () {
}
};
});

//
// Checks if all the tests in the batch have been run,
// and triggers the next batch (if any), by emitting the 'end' event.
//
this.tryEnd = function (batch) {
var result, style, time;

if (batch.honored + batch.broken + batch.errored === batch.total &&
batch.remaining === 0) {

Object.keys(batch).forEach(function (k) {
(k in batch.suite.results) && (batch.suite.results[k] += batch[k]);
});

batch.suite.report(['end']);
batch.promise.emit('end', batch.honored, batch.broken, batch.errored);
}
};

0 comments on commit aae87c2

Please sign in to comment.