Skip to content

Commit 9d81aca

Browse files
author
Stephanie Madison
committed
Fix nightwatchjs#574 should run afterEach with testcase cli option
1 parent 9cd4af1 commit 9d81aca

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

lib/runner/testsuite.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,22 @@ TestSuite.prototype.initAfterEachHook = function() {
107107
var key = 'afterEach';
108108
var hookFn;
109109
var index = self.testResults.steps.indexOf(key);
110-
if (index === -1) {
110+
111+
if (!module[key]) {
111112
// backwards compatibility
112113
key = 'tearDown';
113114
index = self.testResults.steps.indexOf(key);
114115
}
115116

116-
if (index === -1) {
117-
hookFn = function() {};
118-
} else {
117+
if (module[key]) {
119118
hookFn = module[key];
120-
self.testResults.steps.splice(index, 1);
121-
self.module.removeKey(key);
119+
if (index > -1) {
120+
// not running with --testcase
121+
self.testResults.steps.splice(index, 1);
122+
self.module.removeKey(key);
123+
}
124+
} else {
125+
hookFn = function() {};
122126
}
123127

124128
var expectedArgs = hookFn.length;

tests/src/runner/testRunner.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,32 @@ module.exports = {
605605
});
606606
},
607607

608+
testRunTestCaseWithBeforeAndAfter : function(test) {
609+
var testsPath = path.join(process.cwd(), '/sampletests/before-after/syncBeforeAndAfter.js');
610+
test.expect(11);
611+
this.Runner.run([testsPath], {
612+
seleniumPort : 10195,
613+
silent : true,
614+
output : false,
615+
globals : {
616+
test : test
617+
}
618+
}, {
619+
output_folder : false,
620+
start_session : true,
621+
testcase : 'demoTestSyncOne'
622+
}, function(err, results) {
623+
test.equals(err, null);
624+
var result = results.modules.syncBeforeAndAfter.completed;
625+
test.ok('demoTestSyncOne' in result);
626+
test.ok(!('beforeEach' in result));
627+
test.ok(!('before' in result));
628+
test.ok(!('afterEach' in result));
629+
test.ok(!('after' in result));
630+
test.done();
631+
});
632+
},
633+
608634
testRunTestcaseInvalid : function(test) {
609635
var testsPath = path.join(process.cwd(), '/sampletests/before-after/syncBeforeAndAfter.js');
610636

0 commit comments

Comments
 (0)