Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added module teardown #295

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ exports.runTest = function (name, fn, opt, callback) {
*/

exports.runSuite = function (name, suite, opt, callback) {
var moduleTearDown;
if(suite.moduleTearDown) {
moduleTearDown = suite.moduleTearDown;
delete suite.moduleTearDown;
}

suite = wrapGroup(suite);
var keys = _keys(suite);

Expand Down Expand Up @@ -124,7 +130,16 @@ exports.runSuite = function (name, suite, opt, callback) {
else {
exports.runSuite(_name, suite[k], opt, cb);
}
}, callback);
}, function(err, results) {
if(!err && moduleTearDown) {
moduleTearDown(function() {
return callback(null, results);
})
}
else {
return callback(err, results);
}
});
};

/**
Expand Down
49 changes: 49 additions & 0 deletions test/test-testcase.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,55 @@ exports.testCaseGroups = function (test) {
});
};


exports.testCaseGroupsWithModuleTeardown = function (test) {
var call_order = [];
var s = {
setUp: function (callback) {
call_order.push('setUp');
callback();
},
tearDown: function (callback) {
call_order.push('tearDown');
callback();
},
moduleTearDown: function(callback) {
call_order.push('moduleTearDown');
callback();
},
test1: function (test) {
call_order.push('test1');
test.done();
},
group1: {
test2: function (test) {
call_order.push('group1.test2');
test.done();
},
test3: function (test) {
call_order.push('group1.test3');
test.done();
}
}
};
nodeunit.runSuite(null, s, {}, function (err, assertions) {
test.same(call_order, [
'setUp',
'test1',
'tearDown',
'setUp',
'group1.test2',
'tearDown',
'setUp',
'group1.test3',
'tearDown',
'moduleTearDown'
]);
test.done();
});
};


exports.nestedTestCases = function (test) {
var call_order = [];
var s = {
Expand Down