This repository was archived by the owner on May 27, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathconfig.js
More file actions
87 lines (71 loc) · 2.16 KB
/
Copy pathconfig.js
File metadata and controls
87 lines (71 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
var path = require('path'),
fs = require('fs');
var pwd = process.cwd();
config_path = process.env.BROWSERSTACK_JSON || 'browserstack.json';
config_path = path.resolve(path.relative(process.cwd(), config_path));
console.log("Using config:", config_path);
try {
var config = require(config_path);
} catch (e) {
if (e.code == 'MODULE_NOT_FOUND') {
console.log('Configuration file `browserstack.json` is missing.');
} else {
console.log('Invalid configuration in `browserstack.json` file');
console.log(e.message);
console.log(e.stack);
}
process.exit(1);
}
try {
var package_json = require(process.cwd() + '/package.json');
} catch (e) {
var package_json = {};
}
if (process.env.BROWSERSTACK_KEY) {
config.key = process.env.BROWSERSTACK_KEY;
}
if (process.env.BROWSERSTACK_USERNAME) {
config.username = process.env.BROWSERSTACK_USERNAME;
}
if (!config.project) {
var fallback_project;
if (config.username === 'OpensourceJSLib') {
fallback_project = 'Anonymous OpenSource Project';
}
config.project = process.env.TRAVIS_REPO_SLUG || package_json.name;
}
var commit_id = process.env.TRAVIS_COMMIT;
if (commit_id) {
config.build = "Commit-" + commit_id.slice(0, commit_id.length / 2);
}
['username', 'key', 'test_path', 'browsers'].forEach(function(param) {
if (typeof config[param] === 'undefined') {
console.error('Configuration parameter `%s` is required.', param);
process.exit(1);
}
});
var formatPath = function(path) {
if (path.indexOf(pwd) === 0) {
path = path.slice(pwd.length + 1);
}
if (!fs.existsSync(path)) {
console.error('Test path: ' + path + ' is invalid.');
process.exit(1);
}
return path;
};
config.tunnelIdentifier = process.env.TUNNEL_ID || process.env.TRAVIS_JOB_ID || process.env.TRAVIS_BUILD_ID;
if (Object.prototype.toString.call(config.test_path) === '[object Array]') {
config.test_path.forEach(function(path) {
path = formatPath(path);
});
} else {
//Backward Compatibility, if test_path is not array of path
config.test_path = formatPath(config.test_path);
}
config.status = 0;
for (var key in config) {
if (config.hasOwnProperty(key)) {
exports[key] = config[key];
}
}