Skip to content

Commit

Permalink
added filter option on the test_settings object
Browse files Browse the repository at this point in the history
  • Loading branch information
beatfactor committed May 8, 2014
1 parent 6b05358 commit d0788e3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
29 changes: 25 additions & 4 deletions bin/_clirunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ CliRunner.prototype = {
this.replaceEnvVariables();
this.manageSelenium = !this.isParallelMode() && this.settings.selenium &&
this.settings.selenium.start_process;

if (typeof this.settings.src_folders == 'string') {
this.settings.src_folders = [this.settings.src_folders];
}
Expand Down Expand Up @@ -330,12 +329,13 @@ CliRunner.prototype = {
}

if (this.argv.f) {
this.test_settings.filter = this.argv.f;
this.test_settings.filename_filter = this.argv.f;
}

if (this.test_settings.disable_colors) {
Logger.disableColors();
}

return this;
},

Expand Down Expand Up @@ -423,6 +423,27 @@ CliRunner.prototype = {
var mainModule = process.mainModule.filename;
finishCallback = finishCallback || function() {};

var availColors = [
['red', 'light_gray'], ['green', 'black'], ['blue', 'light_gray'], ['magenta', 'light_gray']];
var currentIndex = availColors.length, temporaryValue, randomIndex;

// While there remain elements to shuffle...
while (0 !== currentIndex) {
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;

// And swap it with the current element.
temporaryValue = availColors[currentIndex];
availColors[currentIndex] = availColors[randomIndex];
availColors[randomIndex] = temporaryValue;
}

var writeToSdtout = function(data, item, index) {
data = data.replace(/^\s+|\s+$/g, "");
var color_pair = availColors[index%4];
process.stdout.write(Logger.colors[color_pair[1]]('[' + item + ']', Logger.colors.background[color_pair[0]]) + '\t' + data + '\n');
};

envs.forEach(function(item, index) {
var cliArgs = self.getChildProcessArgs();
cliArgs.push('-e', item, '__parallel-mode');
Expand All @@ -440,11 +461,11 @@ CliRunner.prototype = {
});

child.stdout.on('data', function (data) {
process.stdout.write(Logger.colors.light_gray('[' + item + ']', Logger.colors.background.red) + '\n ' + data);
writeToSdtout(data, item, index);
});

child.stderr.on('data', function (data) {
process.stdout.write(Logger.colors.light_gray('[' + item + ']', Logger.colors.background.magenta) + '\n ' + data);
writeToSdtout(data, item, index);
});

child.on('close', function (code) {
Expand Down
15 changes: 14 additions & 1 deletion lib/runner/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,13 @@ module.exports = new (function() {
});
}

if (opts.filter) {
if (opts.filter.charAt(opts.filter.length-1) === path.sep) {
opts.filter = opts.filter.substring(0, opts.filter.length-1);
}
opts.filter = path.join(p, opts.filter);
}

walk(p, function(err, list) {
if (err) {
return cb(err);
Expand All @@ -273,8 +280,14 @@ module.exports = new (function() {
}

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

if (opts.filename_filter) {
console.log('filter', filename, opts.filename_filter);
return minimatch(filename, opts.filename_filter);
}

return extensionPattern.exec(filePath);
});

Expand Down

0 comments on commit d0788e3

Please sign in to comment.