From 118b94fb858afa10c5cd55fb1ea74317bb269dc9 Mon Sep 17 00:00:00 2001 From: Chris Kinsman Date: Fri, 24 Apr 2015 09:23:04 -0700 Subject: [PATCH] Added module teardown --- lib/core.js | 17 ++++++++++++++- test/test-testcase.js | 49 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/lib/core.js b/lib/core.js index 8ff031b81..c12bff6d5 100644 --- a/lib/core.js +++ b/lib/core.js @@ -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); @@ -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); + } + }); }; /** diff --git a/test/test-testcase.js b/test/test-testcase.js index 5d33b0bf0..5f9198e03 100644 --- a/test/test-testcase.js +++ b/test/test-testcase.js @@ -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 = {