Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
feat(config): add option to exclude specs based on file patterns
Browse files Browse the repository at this point in the history
The config now accepts `exclude`, an array of patterns to exclude.
  • Loading branch information
pts-michaelvera authored and juliemr committed Feb 3, 2014
1 parent 88a1e58 commit e3b1e7c
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 16 deletions.
17 changes: 12 additions & 5 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var argv = require('optimist').
describe('baseUrl', 'URL to prepend to all relative paths').
describe('rootElement', 'Element housing ng-app, if not html or body').
describe('specs', 'Comma-separated list of files to test').
describe('exclude', 'Comma-separated list of files to exclude').
describe('verbose', 'Print full spec names').
describe('stackTrace', 'Print stack trace on error').
describe('params', 'Param object to be passed to the tests').
Expand Down Expand Up @@ -66,13 +67,19 @@ if (argv.version) {
process.exit(0);
}


// Any file names should be resolved relative to the current working directory.
if (argv.specs) {
argv.specs = argv.specs.split(',');
argv.specs.forEach(function(spec, index, arr) {
arr[index] = path.resolve(process.cwd(), spec);
});
var processFilePatterns = function(patterns) {
if (patterns) {
patterns = patterns.split(',');
patterns.forEach(function(spec, index, arr) {
arr[index] = path.resolve(process.cwd(), spec);
});
}
}
processFilePatterns(argv.specs);
processFilePatterns(argv.exclude);

['seleniumServerJar', 'chromeDriver', 'onPrepare'].forEach(function(name) {
if (argv[name]) {
argv[name] = path.resolve(process.cwd(), argv[name]);
Expand Down
43 changes: 32 additions & 11 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,32 @@ var setUpSelenium = function() {
return deferred.promise;
};


/**
* Resolve a list of file patterns into a list of individual file paths.
*
* @param {array} patterns
* @param {boolean} opt_omitWarnings whether to omit did not match warnings
*
* @return {array} The resolved file paths.
*/
var resolveFilePatterns = function(patterns, opt_omitWarnings) {
var resolvedFiles = [];

if (patterns) {
for (var i = 0; i < patterns.length; ++i) {
var matches = glob.sync(patterns[i], {cwd: config.configDir});
if (!matches.length && !opt_omitWarnings) {
util.puts('Warning: pattern ' + patterns[i] + ' did not match any files.');
}
for (var j = 0; j < matches.length; ++j) {
resolvedFiles.push(path.resolve(config.configDir, matches[j]));
}
}
}
return resolvedFiles;
};

/**
* Set up webdriver and run the tests. Note that due to the current setup of
* loading Jasmine and the test specs, this should only be run once.
Expand All @@ -227,17 +253,12 @@ var runTests = function() {
throw new Error('Using config.jasmineNodeOpts.specFolders is deprecated ' +
'since Protractor 0.6.0. Please switch to config.specs.');
}
var specs = config.specs;
var resolvedSpecs = [];
for (var i = 0; i < specs.length; ++i) {
var matches = glob.sync(specs[i], {cwd: config.configDir});
if (!matches.length) {
util.puts('Warning: pattern ' + specs[i] + ' did not match any files.');
}
for (var j = 0; j < matches.length; ++j) {
resolvedSpecs.push(path.resolve(config.configDir, matches[j]));
}
}

var resolvedExcludes = resolveFilePatterns(config.exclude, true);
var resolvedSpecs = resolveFilePatterns(config.specs).filter(function (path) {
return resolvedExcludes.indexOf(path) < 0;
});

if (!resolvedSpecs.length) {
throw new Error('Spec patterns did not match any files.');
}
Expand Down
3 changes: 3 additions & 0 deletions referenceConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ exports.config = {
'spec/*_spec.js',
],

// Patterns to exclude.
exclude: [],

// ----- Capabilities to be passed to the webdriver instance ----
//
// For a full list of available capabilities, see
Expand Down
5 changes: 5 additions & 0 deletions spec/basic/excludeme_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('should be excluded', function() {
it('should fail if included', function() {
expect(true).toBe(false);
});
});
5 changes: 5 additions & 0 deletions spec/basicConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ exports.config = {
'basic/*_spec.js'
],

// Exclude patterns are relative to this directory.
exclude: [
'basic/exclude*.js'
],

capabilities: {
'browserName': 'chrome'
},
Expand Down

0 comments on commit e3b1e7c

Please sign in to comment.