Skip to content

Commit

Permalink
Merge branch 'sknopf-fix_currentTest_name'
Browse files Browse the repository at this point in the history
  • Loading branch information
beatfactor committed Apr 16, 2015
2 parents bca890f + 5007a51 commit 06dcefc
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 23 deletions.
23 changes: 14 additions & 9 deletions lib/runner/testsuite.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ TestSuite.prototype.initHooks = function() {
hookFn.call(context, api, done);
});
};
})(item, argsCount);
})(item, argsCount);

if (index > -1) {
self.testResults.steps.splice(index, 1);
Expand Down Expand Up @@ -150,12 +150,7 @@ TestSuite.prototype.run = function() {
}
this.deferred.resolve(this.testResults);
} else {
var moduleKey = this.getReportKey();
this.client.api('currentTest', {
name : this.currentTest,
module : moduleKey.replace(path.sep , '/')
});

this.setCurrentTest();
this.globalBeforeEach()
.then(function() {
return self.runTestSuiteModule();
Expand All @@ -168,8 +163,8 @@ TestSuite.prototype.run = function() {
self.deferred.resolve(self.testResults);
})
.catch(function(e) {
this.deferred.reject(e);
}.bind(this));
self.deferred.reject(e);
});
}

return this.deferred.promise;
Expand Down Expand Up @@ -221,8 +216,18 @@ TestSuite.prototype.onTestCaseFinished = function(results, errors, time) {
this.emit('testcase:finished', results, errors, time);
};

TestSuite.prototype.setCurrentTest = function() {
var moduleKey = this.getReportKey();
this.client.api('currentTest', {
name : this.currentTest,
module : moduleKey.replace(path.sep , '/')
});
return this;
};

TestSuite.prototype.runNextTestCase = function(deffered) {
this.currentTest = this.module.getNextKey();
this.setCurrentTest();
var self = this;

deffered = deffered || Q.defer();
Expand Down
32 changes: 32 additions & 0 deletions tests/sampletests/before-after/sampleSingleTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module.exports = {
beforeEach : function(client, callback) {
var testName = client.currentTest.name;
client.globals.test.deepEqual(testName, 'demoTest');
callback();
},

before : function(client, callback) {
var testName = client.currentTest.name;
client.globals.test.deepEqual(testName, '');
callback();
},

demoTest : function (client) {
var testName = client.currentTest.name;
client.globals.test.deepEqual(testName, 'demoTest');
client.end();
},

afterEach : function(callback) {
var client = this.client;
var testName = client.currentTest.name;
client.globals.test.deepEqual(testName, 'demoTest');
callback();
},

after : function(client, callback) {
var testName = client.currentTest.name;
client.globals.test.deepEqual(testName, null);
callback();
}
};
4 changes: 4 additions & 0 deletions tests/sampletests/before-after/syncBeforeAndAfter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ module.exports = {

demoTestSyncOne : function (client) {
client.url('http://localhost');
var testName = client.currentTest.name;
client.globals.test.deepEqual(testName, 'demoTestSyncOne');
},

demoTestSyncTwo : function (client) {
var testName = client.currentTest.name;
client.globals.test.deepEqual(testName, 'demoTestSyncTwo');
client.end();
},

Expand Down
70 changes: 56 additions & 14 deletions tests/src/runner/testRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ module.exports = {
},

testRunAsyncWithBeforeAndAfter : function(test) {
test.expect(27);
test.expect(34);
var testsPath = path.join(process.cwd(), '/sampletests/before-after');
this.Runner.run([testsPath], {
seleniumPort : 10195,
Expand Down Expand Up @@ -198,7 +198,7 @@ module.exports = {
},

testRunWithGlobalBeforeAndAfter : function(test) {
test.expect(15);
test.expect(22);
var testsPath = path.join(process.cwd(), '/sampletests/before-after');
var beforeEachCount = 0;
var afterEachCount = 0;
Expand All @@ -216,14 +216,14 @@ module.exports = {
start_session : true
}, function(err, results) {
test.equals(err, null);
test.equals(beforeEachCount, 2);
test.equals(afterEachCount, 2);
test.equals(beforeEachCount, 3);
test.equals(afterEachCount, 3);
test.done();
});
},

testRunWithGlobalAsyncBeforeEachAndAfterEach : function(test) {
test.expect(15);
test.expect(22);
var testsPath = path.join(process.cwd(), '/sampletests/before-after');
var beforeEachCount = 0;
var afterEachCount = 0;
Expand All @@ -245,14 +245,14 @@ module.exports = {
start_session : true
}, function(err, results) {
test.equals(err, null);
test.equals(beforeEachCount, 2);
test.equals(afterEachCount, 2);
test.equals(beforeEachCount, 3);
test.equals(afterEachCount, 3);
test.done();
});
},

testRunWithGlobalAsyncBeforeEachAndAfterEachWithBrowser : function(test) {
test.expect(17);
test.expect(25);
var testsPath = path.join(process.cwd(), '/sampletests/before-after');
var beforeEachCount = 0;
var afterEachCount = 0;
Expand Down Expand Up @@ -281,14 +281,14 @@ module.exports = {
start_session : true
}, function(err, results) {
test.equals(err, null);
test.equals(beforeEachCount, 2);
test.equals(afterEachCount, 2);
test.equals(beforeEachCount, 3);
test.equals(afterEachCount, 3);
test.done();
});
},

testRunWithGlobalReporter : function(test) {
test.expect(15);
test.expect(22);
var testsPath = path.join(process.cwd(), '/sampletests/before-after');
var reporterCount = 0;
this.Runner.run([testsPath], {
Expand All @@ -313,7 +313,7 @@ module.exports = {
},

testRunWithGlobalAsyncReporter : function(test) {
test.expect(15);
test.expect(22);
var testsPath = path.join(process.cwd(), '/sampletests/before-after');
var reporterCount = 0;
this.Runner.run([testsPath], {
Expand Down Expand Up @@ -383,13 +383,18 @@ module.exports = {
var src_folders = [
path.join(process.cwd(), 'sampletests/withsubfolders')
];
var currentTestArray = [];

this.Runner.run(src_folders, {
seleniumPort : 10195,
silent : true,
output : false,
globals : {
test : test
test : test,
beforeEach : function(client, done) {
currentTestArray.push(client.currentTest);
done();
}
}
}, {
output_folder : 'output',
Expand All @@ -398,6 +403,11 @@ module.exports = {
reporter : 'junit'
}, function(err, results) {
test.equals(err, null);
test.deepEqual(currentTestArray, [
{ name: '', module: 'simple/sample' },
{ name: '', module: 'tags/sample' }
]);

var fs = require('fs');
fs.readdir(src_folders[0], function(err, list) {
test.deepEqual(list, ['simple', 'tags'], 'The subfolders have been created.');
Expand Down Expand Up @@ -491,6 +501,38 @@ module.exports = {

test.done();
});
}
},

testRunCurrentTestName : function(test) {
test.expect(8);
var testsPath = path.join(process.cwd(), '/sampletests/before-after/sampleSingleTest.js');
this.Runner.run([testsPath], {
seleniumPort : 10195,
silent : true,
output : false,
globals : {
test : test,
beforeEach: function(client, done) {
test.deepEqual(client.currentTest, {
name : '',
module : 'sampleSingleTest'
});
done();
},
afterEach: function(client, done) {
test.deepEqual(client.currentTest, {
name : null,
module : 'sampleSingleTest'
});
done();
}
}
}, {
output_folder : false,
start_session : true
}, function(err, results) {
test.equals(err, null);
test.done();
});
}
};

0 comments on commit 06dcefc

Please sign in to comment.