Skip to content

armgit / mocha

Public Imported from GitHub
0

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

Release 0.2.0

Tj Holowaychuk8ea4034781d3
diff --git a/History.md b/History.md
index 894201f5..6e2bbc22 100644
--- a/History.md
+++ b/History.md
@@ -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
==================
diff --git a/lib/mocha.js b/lib/mocha.js
index cfeca669..58c9ab7b 100644
--- a/lib/mocha.js
+++ b/lib/mocha.js
@@ -9,7 +9,7 @@
* Library version.
*/
-exports.version = '0.1.0';
+exports.version = '0.2.0';
exports.interfaces = require('./interfaces');
exports.reporters = require('./reporters');
diff --git a/mocha.css b/mocha.css
index 756d668a..256c6433 100644
--- a/mocha.css
+++ b/mocha.css
@@ -84,8 +84,13 @@ h2 {
right: 30px;
font-size: 12px;
margin: 0;
+ color: #888;
}
+
+#stats em {
+ color: black;
+}
#stats li {
list-style: none;
}
\ No newline at end of file
diff --git a/mocha.js b/mocha.js
index f9e04e49..b5236a71 100644
--- a/mocha.js
+++ b/mocha.js
@@ -321,9 +321,13 @@ var Suite = require('../suite')
/**
* TDD-style interface:
- *
+ *
* suite('Array', function(){
* suite('#indexOf()', function(){
+ * suiteSetup(function(){
+ *
+ * });
+ *
* test('should return -1 when not present', function(){
*
* });
@@ -331,9 +335,13 @@ var Suite = require('../suite')
* test('should return the index when present', function(){
*
* });
+ *
+ * suiteTeardown(function(){
+ *
+ * });
* });
* });
- *
+ *
*/
module.exports = function(suite){
@@ -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);
@@ -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');
@@ -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);
@@ -554,6 +579,7 @@ function Base(runner) {
, failures = this.failures = [];
if (!runner) return;
+ this.runner = runner;
runner.on('start', function(){
stats.start = new Date;
@@ -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(){
@@ -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){
@@ -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
@@ -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);
}
@@ -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']));
}
/**
@@ -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.
*
@@ -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(', ') + ''));
diff --git a/package.json b/package.json
index b8865257..bd85a026 100644
--- a/package.json
+++ b/package.json
@@ -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" }