Skip to content

Commit

Permalink
Fixed nightwatchjs#734 - currentTest object doesnt get passed in glob…
Browse files Browse the repository at this point in the history
…al afterEach
  • Loading branch information
beatfactor committed Nov 30, 2015
1 parent 6cd1acb commit 74ada3c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/runner/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ module.exports = new (function() {
results.steps.length > 1)) {
testSuite.printResult(time);
}
testSuite.clearResult();

}).run().then(function onTestSuiteResolved(testResults) {
var testSuite = globalResults.modules[moduleKey];
testSuite.skipped = testResults.steps;
Expand Down
2 changes: 2 additions & 0 deletions lib/runner/testsuite.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ TestSuite.prototype.resetTestCases = function() {

TestSuite.prototype.setCurrentTest = function() {
var moduleKey = this.getReportKey();
this.client.clearGlobalResult();

this.client.api('currentTest', {
name : this.currentTest,
module : moduleKey.replace(path.sep , '/'),
Expand Down
8 changes: 4 additions & 4 deletions tests/run_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ try {
server.on('listening', function() {
reporter.run([
'src',
'src/commands',
'src/expect',
'src/page-object',
'src/runner',
'src/mocha',
'src/expect',
'src/protocol',
'src/http',
'src/index',
'src/assertions',
'src/commands',
'src/page-object'
'src/assertions'
], options, function(err) {
setTimeout(function() {
server.close();
Expand Down
41 changes: 41 additions & 0 deletions tests/src/runner/testRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,47 @@ module.exports = {
test.equals(err, null);
test.equals(results.modules.sampleWithChai.tests, 2);
test.equals(results.modules.sampleWithChai.failures, 0);
test.done();
});
},

'test currentTest in global beforeEach/afterEach' : function(test) {
test.expect(18);
var testsPath = path.join(process.cwd(), '/sampletests/withfailures');

this.Runner.run([testsPath], {
seleniumPort : 10195,
silent : true,
output : false,
globals : {
test : test,
beforeEach: function(client, done) {
test.deepEqual(client.currentTest.results.steps, [ 'demoTest', 'demoTest2' ]);
test.equals(client.currentTest.results.passed, 0);
test.equals(client.currentTest.results.failed, 0);
test.equals(client.currentTest.results.tests, 0);
test.deepEqual(client.currentTest.module, 'sample');
test.deepEqual(client.currentTest.name, '');
done();
},
afterEach: function(client, done) {
test.deepEqual(client.currentTest.results.steps, ['demoTest2' ]);
test.equals(client.currentTest.results.passed, 1);
test.equals(client.currentTest.results.failed, 1);
test.equals(client.currentTest.results.tests, 2);
test.ok('demoTest' in client.currentTest.results.testcases);

test.deepEqual(client.currentTest.name, 'demoTest');
test.deepEqual(client.currentTest.module, 'sample');
done();
}
}
}, {
output_folder : false,
start_session : true
}, function(err, results) {
test.equals(err, null);

test.done();
});
}
Expand Down

0 comments on commit 74ada3c

Please sign in to comment.