Skip to content

Commit 4562270

Browse files
author
Rohan Jain
committed
Handle absolute/invalid paths in the configuration
1 parent 32c1f67 commit 4562270

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

browserstack.sample.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"username": "<username>",
33
"key": "<key>",
4-
"test_path": "path/to/test/page",
4+
"test_path": "relative/path/to/test/page",
55
"browsers": [{
66
"browser": "firefox",
77
"browser_version": "15.0",

lib/config.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
var path = require('path'),
2+
fs = require('fs');
3+
var pwd = process.cwd();
4+
15
try {
26
var config = require(process.cwd() + '/browserstack');
37
} catch (e) {
48
if (e.code == 'MODULE_NOT_FOUND') {
5-
console.log('Configuration file `browserstack.json` is missing.');
9+
console.error('Configuration file `browserstack.json` is missing.');
610
} else {
711
throw(e);
812
}
@@ -18,6 +22,23 @@ if (process.env.BROWSERSTACK_USERNAME) {
1822
config.username = process.env.BROWSERSTACK_USERNAME;
1923
}
2024

25+
['username', 'key', 'test_path', 'browsers'].forEach(function (param) {
26+
if (typeof config[param] === 'undefined') {
27+
console.error('Configuration parameter `%s` is required.', param);
28+
process.exit(1);
29+
}
30+
});
31+
32+
// Convert absoulte path into relative paths.
33+
if (config.test_path.indexOf(pwd) === 0) {
34+
config.test_path = config.test_path.slice(pwd.length + 1);
35+
}
36+
37+
if (!fs.existsSync(config.test_path)){
38+
console.error('Test path is invalid.');
39+
process.exit(1);
40+
}
41+
2142
for (key in config) {
2243
if (config.hasOwnProperty(key)) {
2344
exports[key] = config[key];

0 commit comments

Comments
 (0)