Skip to content

Commit

Permalink
Release 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Nov 30, 2011
1 parent 7f15256 commit 8ea4034
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 17 deletions.
8 changes: 8 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@

0.2.0 / 2011-11-30
==================

* Added `--globals <names>` to specify accepted globals. Closes #99
* Fixed funky highlighting of messages. Closes #97
* Fixed `mocha-debug(1)`. Closes #232
* Fixed growl total, use runner.total

0.1.0 / 2011-11-29
==================

Expand Down
2 changes: 1 addition & 1 deletion lib/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Library version.
*/

exports.version = '0.1.0';
exports.version = '0.2.0';

exports.interfaces = require('./interfaces');
exports.reporters = require('./reporters');
Expand Down
5 changes: 5 additions & 0 deletions mocha.css
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,13 @@ h2 {
right: 30px;
font-size: 12px;
margin: 0;
color: #888;
}


#stats em {
color: black;
}
#stats li {
list-style: none;
}
72 changes: 57 additions & 15 deletions mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,19 +321,27 @@ var Suite = require('../suite')

/**
* TDD-style interface:
*
*
* suite('Array', function(){
* suite('#indexOf()', function(){
* suiteSetup(function(){
*
* });
*
* test('should return -1 when not present', function(){
*
* });
*
* test('should return the index when present', function(){
*
* });
*
* suiteTeardown(function(){
*
* });
* });
* });
*
*
*/

module.exports = function(suite){
Expand All @@ -350,19 +358,35 @@ module.exports = function(suite){
};

/**
* Execute before each test case.
* Execute after each test case.
*/

context.teardown = function(fn){
suites[0].afterEach(fn);
};

/**
* Execute before the suite.
*/

context.suiteSetup = function(fn){
suites[0].beforeAll(fn);
};

/**
* Execute after the suite.
*/

context.suiteTeardown = function(fn){
suites[0].afterAll(fn);
};

/**
* Describe a "suite" with the given `title`
* and callback `fn` containing nested suites
* and/or tests.
*/

context.suite = function(title, fn){
var suite = Suite.create(suites[0], title);
suites.unshift(suite);
Expand Down Expand Up @@ -396,7 +420,7 @@ require.register("mocha.js", function(module, exports, require){
* Library version.
*/

exports.version = '0.0.6';
exports.version = '0.2.0';

exports.interfaces = require('./interfaces');
exports.reporters = require('./reporters');
Expand Down Expand Up @@ -524,12 +548,13 @@ exports.list = function(failures){
+ color('error stack', '\n%s\n');

// msg
var stack = test.err.stack
, index = stack.indexOf('at')
var err = test.err
, stack = err.stack
, index = stack.indexOf(err.message) + err.message.length
, msg = stack.slice(0, index);

// indent stack trace without msg
stack = stack.slice(index)
stack = stack.slice(index + 1)
.replace(/^/gm, ' ');

console.error(fmt, i, test.fullTitle(), msg, stack);
Expand All @@ -554,6 +579,7 @@ function Base(runner) {
, failures = this.failures = [];

if (!runner) return;
this.runner = runner;

runner.on('start', function(){
stats.start = new Date;
Expand Down Expand Up @@ -614,7 +640,7 @@ Base.prototype.epilogue = function(){
+ color('fail', ' %d of %d tests failed')
+ color('light', ':')

console.error(fmt, stats.failures, stats.tests);
console.error(fmt, stats.failures, this.runner.total);
Base.list(this.failures);
console.error();
process.nextTick(function(){
Expand Down Expand Up @@ -1376,7 +1402,7 @@ function Spec(runner) {
});

runner.on('test', function(test){
process.stdout.write(indent() + color('pass', test.title + ': '));
process.stdout.write(indent() + color('pass', ' ◦ ' + test.title + ': '));
});

runner.on('pending', function(test){
Expand Down Expand Up @@ -1542,7 +1568,7 @@ Runnable.prototype.fullTitle = function(){

Runnable.prototype.run = function(fn){
var self = this
, ms = this._timeout
, ms = this.timeout()
, start = new Date
, finished
, emitted
Expand All @@ -1551,7 +1577,7 @@ Runnable.prototype.run = function(fn){
// timeout
if (this.async) {
timer = setTimeout(function(){
fn(new Error('timeout of ' + ms + 'ms exceeded'));
done(new Error('timeout of ' + ms + 'ms exceeded'));
}, ms);
}

Expand Down Expand Up @@ -1630,12 +1656,13 @@ module.exports = Runner;

function Runner(suite) {
var self = this;
this._globals = [];
this.suite = suite;
this.total = suite.total();
this.globals = Object.keys(global).concat(['errno']);
this.on('test end', function(test){ self.checkGlobals(test); });
this.on('hook end', function(hook){ self.checkGlobals(hook); });
this.grep(/.*/);
this.globals(Object.keys(global).concat(['errno']));
}

/**
Expand All @@ -1659,6 +1686,21 @@ Runner.prototype.grep = function(re){
return this;
};

/**
* Allow the given `arr` of globals.
*
* @param {Array} arr
* @return {Runner} for chaining
* @api public
*/

Runner.prototype.globals = function(arr){
arr.forEach(function(arr){
this._globals.push(arr);
}, this);
return this;
};

/**
* Check for global variable leaks.
*
Expand All @@ -1667,10 +1709,10 @@ Runner.prototype.grep = function(re){

Runner.prototype.checkGlobals = function(test){
var leaks = Object.keys(global).filter(function(key){
return !~this.globals.indexOf(key);
return !~this._globals.indexOf(key);
}, this);

this.globals = this.globals.concat(leaks);
this._globals = this._globals.concat(leaks);

if (leaks.length > 1) {
this.fail(test, new Error('global leaks detected: ' + leaks.join(', ') + ''));
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mocha"
, "version": "0.1.0"
, "version": "0.2.0"
, "description": "Test framework inspired by JSpec, Expresso, & Qunit"
, "keywords": ["test", "bdd", "tdd", "tap"]
, "bin": { "mocha": "./bin/mocha" }
Expand Down

0 comments on commit 8ea4034

Please sign in to comment.