Created
November 3, 2013 19:07
-
-
Save jugglinmike/7293642 to your computer and use it in GitHub Desktop.
A bad Mocha feature :/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/test/lib/mocha.js b/test/lib/mocha.js | |
index dee24d6..2b718bd 100644 | |
--- a/test/lib/mocha.js | |
+++ b/test/lib/mocha.js | |
@@ -4251,6 +4251,28 @@ Runner.prototype.fail = function(test, err){ | |
}; | |
/** | |
+ * Fail the given `suite`. | |
+ * | |
+ * @param {Suite} test | |
+ * @param {Hook} hook | |
+ * @param {Error} err | |
+ * @api private | |
+ */ | |
+ | |
+Runner.prototype.failSuite = function(suite, hook, err) { | |
+ var self = this; | |
+ hook.state = suite.state = 'failed'; | |
+ suite.eachTest(function(test) { | |
+ self.fail(test, err); | |
+ }); | |
+ | |
+ if (!suite.parent) { | |
+ this.failHook(hook, err); | |
+ } | |
+ this.fail(hook, err); | |
+}; | |
+ | |
+/** | |
* Fail the given `hook` with `err`. | |
* | |
* Hook failures (currently) hard-end due | |
@@ -4297,7 +4319,7 @@ Runner.prototype.hook = function(name, fn){ | |
hook.removeAllListeners('error'); | |
var testError = hook.error(); | |
if (testError) self.fail(self.test, testError); | |
- if (err) return self.failHook(hook, err); | |
+ if (err) self.failSuite(self.suite, hook, err); | |
self.emit('hook end', hook); | |
next(++i); | |
}); | |
@@ -4447,6 +4469,7 @@ Runner.prototype.runTests = function(suite, fn){ | |
self.emit('test', self.test = test); | |
self.hookDown('beforeEach', function(){ | |
self.currentRunnable = self.test; | |
+ if (self.suite.state === 'failed') { fn(); return; } | |
self.runTest(function(err){ | |
test = self.test; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment