Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

Release 0.10.0

Tj Holowaychukd87988c9e1ca
diff --git a/History.md b/History.md
index bafe2f47..a32b86e9 100644
--- a/History.md
+++ b/History.md
@@ -1,4 +1,15 @@
+0.10.0 / 2012-01-13
+==================
+
+ * Added `-b, --bail` to exit on first exception [guillermo]
+ * Added support for `-gc` / `--expose-gc` [TooTallNate]
+ * Added `qunit`-inspired interface
+ * Added MIT LICENSE. Closes #194
+ * Added: `--watch` all .js in the CWD. Closes #139
+ * Fixed `self.test` reference in runner. Closes #189
+ * Fixed double reporting of uncaught exceptions after timeout. Closes #195
+
0.8.2 / 2012-01-05
==================
diff --git a/lib/mocha.js b/lib/mocha.js
index 01202bb2..dbd0425c 100644
--- a/lib/mocha.js
+++ b/lib/mocha.js
@@ -9,7 +9,7 @@
* Library version.
*/
-exports.version = '0.9.0';
+exports.version = '0.10.0';
exports.utils = require('./utils');
exports.interfaces = require('./interfaces');
diff --git a/mocha.css b/mocha.css
index 92d6d889..e7f94393 100644
--- a/mocha.css
+++ b/mocha.css
@@ -1,5 +1,6 @@
+
body {
- font: 20px/1.5 "Helvetica Neue", Helvetica, Arial, sans-serif;
+ font: 20px/1.5 "Helvetica Neue", Helvetica, Aria;, sans-serif;
padding: 60px 50px;
}
diff --git a/mocha.js b/mocha.js
index c226f415..4a58ec2a 100644
--- a/mocha.js
+++ b/mocha.js
@@ -579,9 +579,106 @@ require.register("interfaces/index.js", function(module, exports, require){
exports.bdd = require('./bdd');
exports.tdd = require('./tdd');
+exports.qunit = require('./qunit');
exports.exports = require('./exports');
+
}); // module: interfaces/index.js
+require.register("interfaces/qunit.js", function(module, exports, require){
+
+/**
+ * Module dependencies.
+ */
+
+var Suite = require('../suite')
+ , Test = require('../test');
+
+/**
+ * QUnit-style interface:
+ *
+ * suite('Array');
+ *
+ * test('#length', function(){
+ * var arr = [1,2,3];
+ * ok(arr.length == 3);
+ * });
+ *
+ * test('#indexOf()', function(){
+ * var arr = [1,2,3];
+ * ok(arr.indexOf(1) == 0);
+ * ok(arr.indexOf(2) == 1);
+ * ok(arr.indexOf(3) == 2);
+ * });
+ *
+ * suite('String');
+ *
+ * test('#length', function(){
+ * ok('foo'.length == 3);
+ * });
+ *
+ */
+
+module.exports = function(suite){
+ var suites = [suite];
+
+ suite.on('pre-require', function(context){
+
+ /**
+ * Execute before running tests.
+ */
+
+ context.before = function(fn){
+ suites[0].beforeAll(fn);
+ };
+
+ /**
+ * Execute after running tests.
+ */
+
+ context.after = function(fn){
+ suites[0].afterAll(fn);
+ };
+
+ /**
+ * Execute before each test case.
+ */
+
+ context.beforeEach = function(fn){
+ suites[0].beforeEach(fn);
+ };
+
+ /**
+ * Execute after each test case.
+ */
+
+ context.afterEach = function(fn){
+ suites[0].afterEach(fn);
+ };
+
+ /**
+ * Describe a "suite" with the given `title`.
+ */
+
+ context.suite = function(title){
+ if (suites.length > 1) suites.shift();
+ var suite = Suite.create(suites[0], title);
+ suites.unshift(suite);
+ };
+
+ /**
+ * Describe a specification or test-case
+ * with the given `title` and callback `fn`
+ * acting as a thunk.
+ */
+
+ context.test = function(title, fn){
+ suites[0].addTest(new Test(title, fn));
+ };
+ });
+};
+
+}); // module: interfaces/qunit.js
+
require.register("interfaces/tdd.js", function(module, exports, require){
/**
@@ -692,7 +789,7 @@ require.register("mocha.js", function(module, exports, require){
* Library version.
*/
-exports.version = '0.9.0';
+exports.version = '0.10.0';
exports.utils = require('./utils');
exports.interfaces = require('./interfaces');
@@ -2448,6 +2545,9 @@ Runner.prototype.runTests = function(suite, fn){
, test;
function next(err) {
+ // if we bail after first err
+ if (self.failures && suite._bail) return fn();
+
// next test
test = tests.shift();
@@ -2557,6 +2657,7 @@ Runner.prototype.run = function(fn){
function uncaught(err){
var runnable = self.currentRunnable;
debug('uncaught exception');
+ if (runnable.failed) return;
runnable.clearTimeout();
err.uncaught = true;
self.fail(runnable, err);
@@ -2633,6 +2734,7 @@ function Suite(title) {
this._afterAll = [];
this.root = !title;
this._timeout = 2000;
+ this._bail = false;
}
/**
@@ -2654,6 +2756,7 @@ Suite.prototype.clone = function(){
var suite = new Suite(this.title);
debug('clone');
suite.timeout(this.timeout());
+ suite.bail(this._bail());
return suite;
};
@@ -2673,6 +2776,21 @@ Suite.prototype.timeout = function(ms){
return this;
};
+/**
+ * Sets whether to bail after first error.
+ *
+ * @parma {Boolean} bail
+ * @return {Suite|Number} for chaining
+ * @api private
+ */
+
+Suite.prototype.bail = function(bail){
+ if (0 == arguments.length) return this._bail;
+ debug('bail %s', bail);
+ this._bail = bail;
+ return this;
+};
+
/**
* Run `fn(test[, done])` before running tests.
*
@@ -2752,6 +2870,7 @@ Suite.prototype.afterEach = function(fn){
Suite.prototype.addSuite = function(suite){
suite.parent = this;
suite.timeout(this.timeout());
+ suite.bail(this.bail());
this.suites.push(suite);
this.emit('suite', suite);
return this;
diff --git a/package.json b/package.json
index 93d37d0c..8d3b23b2 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "mocha"
- , "version": "0.9.0"
+ , "version": "0.10.0"
, "description": "simple, flexible, fun test framework"
, "keywords": ["test", "bdd", "tdd", "tap"]
, "author": "TJ Holowaychuk <[email protected]>"