Skip to content

Commit 1487a4e

Browse files
Merge pull request #43 from browserstack/CYP_161_config
Make config management developer friendly
2 parents 20c9928 + cbdde01 commit 1487a4e

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ specs
55
tests.zip
66
package-lock.json
77
.nyc_output/
8+
.env.*

bin/helpers/config.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
var config = {};
2-
config.env = "prod";
3-
var hosts = {
4-
prod: {
5-
uploadUrl: `https://api-cloud.browserstack.com/automate-frameworks/cypress/upload`,
6-
rails_host: `https://api.browserstack.com`
7-
}
8-
};
9-
config.uploadUrl = hosts[config.env].uploadUrl;
10-
config.rails_host = hosts[config.env].rails_host;
1+
var config = require('./config.json');
2+
3+
config.env = process.env.NODE_ENV || "production";
4+
5+
if(config.env !== "production") {
6+
// load config based on env
7+
require('custom-env').env(config.env);
8+
9+
config.uploadUrl = process.env.UPLOAD_URL;
10+
config.rails_host = process.env.RAILS_HOST;
11+
config.dashboardUrl = process.env.DASHBOARD_URL;
12+
config.usageReportingUrl = process.env.USAGE_REPORTING_URL;
13+
}
14+
1115
config.cypress_v1 = `${config.rails_host}/automate/cypress/v1`;
1216
config.buildUrl = `${config.cypress_v1}/builds/`;
1317
config.buildStopUrl = `${config.cypress_v1}/builds/stop/`;
14-
config.dashboardUrl = `https://automate.browserstack.com/dashboard/v2/builds/`;
15-
config.usageReportingUrl = `https://eds.browserstack.com:443/send_event_cy_internal`;
1618
config.fileName = "tests.zip";
1719

1820
module.exports = config;

bin/helpers/config.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"uploadUrl": "https://api-cloud.browserstack.com/automate-frameworks/cypress/upload",
3+
"rails_host": "https://api.browserstack.com",
4+
"dashboardUrl": "https://automate.browserstack.com/dashboard/v2/builds/",
5+
"usageReportingUrl": "https://eds.browserstack.com:443/send_event_cy_internal"
6+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"devDependencies": {
3232
"chai": "^4.2.0",
3333
"chai-as-promised": "^7.1.1",
34+
"custom-env": "^2.0.1",
3435
"mocha": "^7.1.2",
3536
"nyc": "^15.0.1",
3637
"proxyquire": "^2.1.3",

0 commit comments

Comments
 (0)