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

Commit

Permalink
fix(config): Make all file paths in config files relative to the conf…
Browse files Browse the repository at this point in the history
…ig file itself

Breaking Change
Previously, onPrepare and specs were relative to the location of the config,
but seleniumServerJar and chromeDriver were relative to the cwd when the
test was called. If you were calling the tests from somewhere other than
the same directory as the config location, you will need to change the paths of
seleniumServerJar and/or chromeDriver.  Closes #222.
  • Loading branch information
juliemr committed Nov 27, 2013
1 parent f3be172 commit a1c91a2
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 23 deletions.
2 changes: 1 addition & 1 deletion example/chromeOnlyConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
exports.config = {
// Do not start a Selenium Standalone sever - only run this using chrome.
chromeOnly: true,
chromeDriver: './selenium/chromedriver',
chromeDriver: '../selenium/chromedriver',

// Capabilities to be passed to the webdriver instance.
capabilities: {
Expand Down
17 changes: 10 additions & 7 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ var argv = require('optimist').
}).
argv;


var configPath;


var printVersion = function () {
util.puts('Version ' + JSON.parse(
fs.readFileSync(__dirname + '/../package.json', 'utf8')).version);
Expand All @@ -56,18 +52,25 @@ if (argv.version) {
printVersion();
}

// 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);
});
}
['seleniumServerJar', 'chromeDriver', 'onPrepare'].forEach(function(name) {
if (argv[name]) {
argv[name] = path.resolve(process.cwd(), argv[name]);
}
});

var configFilename = argv._[0];
if (configFilename) {
configPath = path.resolve(process.cwd(), configFilename);
runner.addConfig(require(configPath).config);
runner.addConfig({specFileBase: path.dirname(configPath)})
var configPath = path.resolve(process.cwd(), configFilename);
config = require(configPath).config;
config.configDir = path.dirname(configPath);
runner.addConfig(config);
}

runner.addConfig(argv);
Expand Down
17 changes: 13 additions & 4 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var sauceAccount;

// Default configuration.
var config = {
specFileBase: './',
configDir: './',
seleniumServerJar: null,
seleniumArgs: [],
seleniumPort: null,
Expand Down Expand Up @@ -60,6 +60,15 @@ var merge = function(into, from) {
* @param {Object} additionalConfig
*/
var addConfig = function(additionalConfig) {
// All filepaths should be kept relative to the current config location.
// This will not affect absolute paths.
['seleniumServerJar', 'chromeDriver', 'onPrepare'].forEach(function(name) {
if (additionalConfig[name] && additionalConfig.configDir &&
typeof additionalConfig[name] == 'string') {
additionalConfig[name] =
path.resolve(additionalConfig.configDir, additionalConfig[name]);
}
})
merge(config, additionalConfig);
};

Expand Down Expand Up @@ -183,12 +192,12 @@ var runJasmineTests = function() {
}
var resolvedSpecs = [];
for (var i = 0; i < specs.length; ++i) {
var matches = glob.sync(specs[i], {cwd: config.specFileBase});
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.specFileBase, matches[j]));
resolvedSpecs.push(path.resolve(config.configDir, matches[j]));
}
}
if (!resolvedSpecs.length) {
Expand Down Expand Up @@ -245,7 +254,7 @@ var runJasmineTests = function() {
if (typeof config.onPrepare == 'function') {
config.onPrepare();
} else if (typeof config.onPrepare == 'string') {
require(path.resolve(config.specFileBase, config.onPrepare));
require(path.resolve(config.configDir, config.onPrepare));
} else {
throw 'config.onPrepare must be a string or function';
}
Expand Down
3 changes: 2 additions & 1 deletion referenceConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ exports.config = {
// and chromeDriver will be used directly (from the location specified in
// chromeDriver)

// The location of the selenium standalone server .jar file.
// The location of the selenium standalone server .jar file, relative
// to the location of this config.
seleniumServerJar: './selenium/selenium-server-standalone-2.37.0.jar',
// The port to start the selenium server on, or null if the server should
// find its own unused port.
Expand Down
4 changes: 2 additions & 2 deletions spec/altRootConf.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Tests for an Angular app where ng-app is not on the body.
exports.config = {
seleniumServerJar: './selenium/selenium-server-standalone-2.35.0.jar',
chromeDriver: './selenium/chromedriver',
seleniumServerJar: '../selenium/selenium-server-standalone-2.37.0.jar',
chromeDriver: '../selenium/chromedriver',

seleniumAddress: 'http://localhost:4444/wd/hub',

Expand Down
4 changes: 2 additions & 2 deletions spec/basicConf.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// The main suite of Protractor tests.
exports.config = {
seleniumServerJar: './selenium/selenium-server-standalone-2.35.0.jar',
chromeDriver: './selenium/chromedriver',
seleniumServerJar: '../selenium/selenium-server-standalone-2.37.0.jar',
chromeDriver: '../selenium/chromedriver',

seleniumAddress: 'http://localhost:4444/wd/hub',

Expand Down
4 changes: 2 additions & 2 deletions spec/junitOutputConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ require('jasmine-reporters');

// The main suite of Protractor tests.
exports.config = {
seleniumServerJar: './selenium/selenium-server-standalone-2.35.0.jar',
chromeDriver: './selenium/chromedriver',
seleniumServerJar: '../selenium/selenium-server-standalone-2.35.0.jar',
chromeDriver: '../selenium/chromedriver',

seleniumAddress: 'http://localhost:4444/wd/hub',

Expand Down
4 changes: 2 additions & 2 deletions spec/onPrepareConf.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// The main suite of Protractor tests.
exports.config = {
seleniumServerJar: './selenium/selenium-server-standalone-2.35.0.jar',
chromeDriver: './selenium/chromedriver',
seleniumServerJar: '../selenium/selenium-server-standalone-2.35.0.jar',
chromeDriver: '../selenium/chromedriver',

seleniumAddress: 'http://localhost:4444/wd/hub',

Expand Down
4 changes: 2 additions & 2 deletions spec/onPrepareStringConf.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Configuration using a string in onPrepare to load a file with code to
// execute once before tests.
exports.config = {
seleniumServerJar: './selenium/selenium-server-standalone-2.35.0.jar',
chromeDriver: './selenium/chromedriver',
seleniumServerJar: '../selenium/selenium-server-standalone-2.35.0.jar',
chromeDriver: '../selenium/chromedriver',

seleniumAddress: 'http://localhost:4444/wd/hub',

Expand Down

0 comments on commit a1c91a2

Please sign in to comment.