Skip to content

armgit / mocha

Public Imported from GitHub
0

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

use test.state to ensure fail or pass not both ;)

TJ Holowaychuk199112f944b1
diff --git a/lib/reporters/html.js b/lib/reporters/html.js
index 169bbbd7..a8461c24 100644
--- a/lib/reporters/html.js
+++ b/lib/reporters/html.js
@@ -92,7 +92,7 @@ function HTML(runner) {
stat.find('.duration em').text((ms / 1000).toFixed(2));
// test
- if (test.passed) {
+ if ('passed' == test.state) {
var el = $('<div class="test pass"><h2>' + escape(test.title) + '</h2></div>')
} else if (test.pending) {
var el = $('<div class="test pass pending"><h2>' + escape(test.title) + '</h2></div>')
diff --git a/lib/reporters/landing.js b/lib/reporters/landing.js
index ceab6d8d..8d59e505 100644
--- a/lib/reporters/landing.js
+++ b/lib/reporters/landing.js
@@ -67,7 +67,7 @@ function Landing(runner) {
: crashed;
// show the crash
- if (test.failed) {
+ if ('failed' == test.state) {
plane = color('plane crash', '✈');
crashed = col;
}
diff --git a/lib/reporters/xunit.js b/lib/reporters/xunit.js
index 8ee59931..63bcbd4d 100644
--- a/lib/reporters/xunit.js
+++ b/lib/reporters/xunit.js
@@ -63,7 +63,7 @@ function test(test) {
, time: test.duration / 1000
};
- if (test.failed) {
+ if ('failed' == test.state) {
var err = test.err;
attrs.message = escape(err.message);
console.log(tag('testcase', attrs, false, tag('failure', attrs, false, cdata(err.stack))));
diff --git a/lib/runner.js b/lib/runner.js
index 1c04de94..e65cffdd 100644
--- a/lib/runner.js
+++ b/lib/runner.js
@@ -115,7 +115,7 @@ Runner.prototype.checkGlobals = function(test){
Runner.prototype.fail = function(test, err){
++this.failures;
- test.failed = true;
+ test.state = 'failed';
this.emit('fail', test, err);
};
@@ -322,7 +322,7 @@ Runner.prototype.runTests = function(suite, fn){
return self.hookUp('afterEach', next);
}
- test.passed = true;
+ test.state = 'passed';
self.emit('pass', test);
self.emit('test end', test);
self.hookUp('afterEach', next);
@@ -379,7 +379,7 @@ Runner.prototype.runSuite = function(suite, fn){
Runner.prototype.uncaught = function(err){
debug('uncaught exception');
var runnable = this.currentRunnable;
- if (runnable.failed) return;
+ if ('failed' == runnable.state) return;
runnable.clearTimeout();
err.uncaught = true;
this.fail(runnable, err);
diff --git a/mocha.css b/mocha.css
index bd811eb6..163cd13f 100644
--- a/mocha.css
+++ b/mocha.css
@@ -37,11 +37,13 @@ body {
right: -10px;
content: '(view source)';
font-size: 12px;
+ font-family: arial;
color: #888;
}
#mocha .test.pending:hover h2::after {
content: '(pending)';
+ font-family: arial;
}
#mocha .test.pass::before {
@@ -130,4 +132,4 @@ code .comment { color: #ddd }
code .init { color: #2F6FAD }
code .string { color: #5890AD }
code .keyword { color: #8A6343 }
-code .number { color: #2F6FAD }
\ No newline at end of file
+code .number { color: #2F6FAD }
diff --git a/mocha.js b/mocha.js
index abdc28cb..dcdd00e1 100644
--- a/mocha.js
+++ b/mocha.js
@@ -513,6 +513,11 @@ module.exports = function(suite){
suite.on('pre-require', function(context){
+ // noop variants
+
+ context.xdescribe = function(){};
+ context.xit = function(){};
+
/**
* Execute before running tests.
*/
@@ -1342,7 +1347,7 @@ function HTML(runner) {
stat.find('.duration em').text((ms / 1000).toFixed(2));
// test
- if (test.passed) {
+ if ('passed' == test.state) {
var el = $('<div class="test pass"><h2>' + escape(test.title) + '</h2></div>')
} else if (test.pending) {
var el = $('<div class="test pass pending"><h2>' + escape(test.title) + '</h2></div>')
@@ -1629,7 +1634,7 @@ function Landing(runner) {
: crashed;
// show the crash
- if (test.failed) {
+ if ('failed' == test.state) {
plane = color('plane crash', '✈');
crashed = col;
}
@@ -2109,7 +2114,7 @@ function test(test) {
, time: test.duration / 1000
};
- if (test.failed) {
+ if ('failed' == test.state) {
var err = test.err;
attrs.message = escape(err.message);
console.log(tag('testcase', attrs, false, tag('failure', attrs, false, cdata(err.stack))));
@@ -2436,7 +2441,7 @@ Runner.prototype.checkGlobals = function(test){
Runner.prototype.fail = function(test, err){
++this.failures;
- test.failed = true;
+ test.state = 'failed';
this.emit('fail', test, err);
};
@@ -2643,7 +2648,7 @@ Runner.prototype.runTests = function(suite, fn){
return self.hookUp('afterEach', next);
}
- test.passed = true;
+ test.state = 'passed';
self.emit('pass', test);
self.emit('test end', test);
self.hookUp('afterEach', next);
@@ -2700,7 +2705,7 @@ Runner.prototype.runSuite = function(suite, fn){
Runner.prototype.uncaught = function(err){
debug('uncaught exception');
var runnable = this.currentRunnable;
- if (runnable.failed) return;
+ if ('failed' == runnable.state) return;
runnable.clearTimeout();
err.uncaught = true;
this.fail(runnable, err);
@@ -3179,9 +3184,9 @@ exports.keys = Object.keys || function(obj) {
var keys = []
, has = Object.prototype.hasOwnProperty // for `window` on <=IE8
- for (var i in obj) {
- if (has.call(obj, i)) {
- keys.push(i);
+ for (var key in obj) {
+ if (has.call(obj, key)) {
+ keys.push(key);
}
}
diff --git a/test/runner.js b/test/runner.js
index 8fa6a2e2..20a0afb8 100644
--- a/test/runner.js
+++ b/test/runner.js
@@ -60,10 +60,10 @@ describe('Runner', function(){
runner.failures.should.equal(2);
})
- it('should set test.failed to true', function(){
+ it('should set test.state to "failed"', function(){
var test = {};
runner.fail(test, 'some error');
- test.failed.should.be.true;
+ test.state.should.equal('failed');
})
it('should emit "fail"', function(done){