Skip to content

Commit

Permalink
Added exclude tests option based on #110
Browse files Browse the repository at this point in the history
  • Loading branch information
beatfactor committed Apr 2, 2014
1 parent d3f9673 commit 7a5b006
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 25 deletions.
3 changes: 1 addition & 2 deletions runner/reporters/junit.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ exports.save = function(results, folder, callback) {
failures += module[x].failed;
}
}

var rendered = ejs.render(tmpl, {
locals: {
module : module,
moduleName : moduleName,
tests : tests,
testsNo : tests,
errors : errors,
failures : failures,
systemerr : results.errmessages.join('\n')
Expand Down
2 changes: 1 addition & 1 deletion runner/reporters/junit.xml.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<testsuites name="<%= moduleName %>"
errors="<%= errors %>"
failures="<%= failures %>"
tests="<%= tests %>">
tests="<%= testsNo %>">
<% for (var testsuite in module) { %>
<testsuite errors="<%= module[testsuite].errors %>" failures="<%= module[testsuite].failed %>" hostname="" id=""
name="<%= testsuite %>" package="<%= moduleName %>" skipped="<%= module[testsuite].skipped %>"
Expand Down
40 changes: 31 additions & 9 deletions runner/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ module.exports = new (function() {
testResults.errors++;
client.terminate();
error = true;
moduleCallback(err, testResults);
//moduleCallback(err, testResults);
}
} else {
moduleCallback(null, testResults);
Expand All @@ -112,7 +112,7 @@ module.exports = new (function() {

if (module.disabled === true) {
if (opts.output) {
console.log('\nSkipping module: ', Logger.colors.cyan(moduleName));
console.log(Logger.colors.cyan(moduleName), 'module is disabled, skipping...');
}
moduleCallback(null, false);
return;
Expand Down Expand Up @@ -184,7 +184,7 @@ module.exports = new (function() {
}

function processExitListener() {
process.on('exit', function(code) {
process.on('exit', function (code) {
if (globalResults.errors > 0 || globalResults.failed > 0) {
process.exit(1);
} else {
Expand Down Expand Up @@ -213,6 +213,16 @@ module.exports = new (function() {
}

paths.forEach(function(p) {
if (opts.exclude) {
opts.exclude = opts.exclude.map(function(item) {
// remove trailing slash
if (item.charAt(item.length-1) === path.sep) {
item = item.substring(0, item.length-1);
}
return path.join(p, item);
});
}

walk(p, function(err, list) {
if (err) {
return cb(err);
Expand All @@ -221,15 +231,24 @@ module.exports = new (function() {

var modules = list.filter(function (filePath) {
var filename = filePath.split(path.sep).slice(-1)[0];
return opts.filter ?
minimatch(filename, opts.filter) :
extensionPattern.exec(filePath);

if (opts.exclude) {
for (var i = 0; i < opts.exclude.length; i++) {
if (minimatch(filePath, opts.exclude[i])) {
return false;
}
}
}

if (opts.filter) {
return minimatch(filename, opts.filter);
}
return extensionPattern.exec(filePath);
});

modules = modules.map(function (filename) {
return filename.replace(extensionPattern, '');
});

cb(null, modules);
}, opts);
});
Expand All @@ -253,7 +272,10 @@ module.exports = new (function() {
fs.stat(file, function(err, stat) {
if (stat && stat.isDirectory()) {
var dirName = file.split(path.sep).slice(-1)[0];
if (opts.skipgroup && opts.skipgroup.indexOf(dirName) > -1) {
var isExcluded = opts.exclude && opts.exclude.indexOf(file) > -1;
var isSkipped = opts.skipgroup && opts.skipgroup.indexOf(dirName) > -1;

if (isExcluded || isSkipped) {
pending = pending-1;
} else {
walk(file, function(err, res) {
Expand Down Expand Up @@ -382,8 +404,8 @@ module.exports = new (function() {
console.log(Logger.colors.yellow('Warning: Failed to save report file to folder: ' + output));
console.log(err.stack);
}
finishCallback(null);
});
finishCallback(null);
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/run_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ process.chdir(__dirname);
try {
var server = require('mockserver').init();
server.on('listening', function() {
reporter.run(['src', 'src/index', 'src/assertions', 'src/protocol', 'src/commands'], options, function() {
reporter.run(['src', 'src/index', 'src/runner', 'src/assertions', 'src/protocol', 'src/commands'], options, function() {
server.close();
});
});
Expand Down
7 changes: 7 additions & 0 deletions tests/sampletests/withexclude/excluded/excluded-module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
demoTestExcluded : function (client) {
client.url('http://localhost')
.assert.elementPresent('#weblogin')
.end();
}
};
7 changes: 7 additions & 0 deletions tests/sampletests/withexclude/simple/sample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
demoTest : function (client) {
client.url('http://localhost')
.assert.elementPresent('#weblogin')
.end();
}
};
46 changes: 34 additions & 12 deletions tests/src/runner/testRunner.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
var Runner = require('../../../runner/run.js');

module.exports = {
setUp: function (callback) {
process.on('exit', function(code) {
process.exit(0);
});
callback();
},

testRunEmptyFolder : function(test) {
Runner.run([process.cwd() + '/sampletests/empty'], {
}, {
Expand Down Expand Up @@ -36,6 +29,40 @@ module.exports = {
});
},

testRunWithExcludeFolder : function(test) {
Runner.run([process.cwd() + '/sampletests/withexclude'], {
seleniumPort : 10195,
silent : true,
output : false,
globals : {
test : test
},
exclude : ['excluded']
}, {
output_folder : false
}, function(err, results) {
test.ok(!('excluded-module' in results.modules));
test.done();
});
},

testRunWithExcludePattern : function(test) {
Runner.run([process.cwd() + '/sampletests/withexclude'], {
seleniumPort : 10195,
silent : true,
output : false,
globals : {
test : test
},
exclude : ['excluded/excluded-*']
}, {
output_folder : false
}, function(err, results) {
test.ok(!('excluded-module' in results.modules));
test.done();
});
},

testRunAsync : function(test) {
test.expect(5);

Expand Down Expand Up @@ -74,10 +101,5 @@ module.exports = {
test.ok('demoTestMixed' in results.modules.sample);
test.done();
});
},

tearDown : function(callback) {
// clean up
callback();
}
};

0 comments on commit 7a5b006

Please sign in to comment.