Skip to content

armgit / mocha

Public Imported from GitHub
0

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

Changed: execute tests before sub-suites

Tj Holowaychuk0465790720e4
diff --git a/lib/runner.js b/lib/runner.js
index 231e9ae5..0966ea41 100644
--- a/lib/runner.js
+++ b/lib/runner.js
@@ -112,18 +112,20 @@ Runner.prototype.runSuite = function(suite, fn){
this.emit('suite', suite);
- // run sub-suites
+ // pending tests
var pending = suite.suites.length + 1;
- suite.suites.forEach(function(suite){
- self.runSuite(suite, function(){
- --pending || fn();
- });
- });
// run tests
this.runTests(suite, function(){
--pending || fn();
});
+
+ // run sub-suites
+ suite.suites.forEach(function(suite){
+ self.runSuite(suite, function(){
+ --pending || fn();
+ });
+ });
};
/**
diff --git a/test/unit/beforeEach.nested.serial.js b/test/unit/beforeEach.nested.serial.js
index 73a88eb9..f4c98cb3 100644
--- a/test/unit/beforeEach.nested.serial.js
+++ b/test/unit/beforeEach.nested.serial.js
@@ -12,27 +12,14 @@ describe('serial', function(){
});
it('foo', function(){
- calls.should.eql([
- 'before one'
- , 'after one'
- , 'before two'
- , 'after two'
- , 'before three'
- , 'after three'
- , 'parent before foo']);
+ calls.should.eql(['parent before foo']);
});
it('bar', function(){
calls.should.eql([
- 'before one'
- , 'after one'
- , 'before two'
- , 'after two'
- , 'before three'
- , 'after three'
- , 'parent before foo'
- , 'parent after foo'
- , 'parent before bar']);
+ 'parent before foo'
+ , 'parent after foo'
+ , 'parent before bar']);
});
describe('beforeEach()', function(){
@@ -41,23 +28,36 @@ describe('serial', function(){
});
it('one', function(){
- calls.should.eql(['before one']);
+ calls.should.eql([
+ 'parent before foo'
+ , 'parent after foo'
+ , 'parent before bar'
+ , 'parent after bar'
+ , 'before one']);
});
it('two', function(){
calls.should.eql([
- 'before one'
- , 'after one'
- , 'before two']);
+ 'parent before foo'
+ , 'parent after foo'
+ , 'parent before bar'
+ , 'parent after bar'
+ , 'before one'
+ , 'after one'
+ , 'before two']);
});
-
+
it('three', function(){
calls.should.eql([
- 'before one'
- , 'after one'
- , 'before two'
- , 'after two'
- , 'before three']);
+ 'parent before foo'
+ , 'parent after foo'
+ , 'parent before bar'
+ , 'parent after bar'
+ , 'before one'
+ , 'after one'
+ , 'before two'
+ , 'after two'
+ , 'before three']);
});
afterEach(function(test){