Skip to content

Commit 17a583a

Browse files
committed
refactor into utility methods
1 parent 4c0de9d commit 17a583a

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

lib/fetchDownloadSourceUrl.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
const https = require('https'),
22
fs = require('fs'),
3-
HttpsProxyAgent = require('https-proxy-agent');
3+
HttpsProxyAgent = require('https-proxy-agent'),
4+
{ isUndefined } = require('./util');
45

56
const authToken = process.argv[2], bsHost = process.argv[3], proxyHost = process.argv[6], proxyPort = process.argv[7], useCaCertificate = process.argv[8], downloadFallback = process.argv[4], downloadErrorMessage = process.argv[5];
67

78
let body = '', data = {'auth_token': authToken};
89
const options = {
9-
hostname: bsHost && bsHost !== 'undefined' ? bsHost : 'local.browserstack.com',
10+
hostname: !isUndefined(bsHost) ? bsHost : 'local.browserstack.com',
1011
port: 443,
1112
path: '/binary/api/v1/endpoint',
1213
method: 'POST',
@@ -20,13 +21,13 @@ if (downloadFallback == 'true') {
2021
data['error_message'] = downloadErrorMessage;
2122
}
2223

23-
if(proxyHost && proxyPort && proxyHost !== 'undefined' && proxyPort !== 'undefined') {
24+
if(!isUndefined(proxyHost) && !isUndefined(proxyPort)) {
2425
options.agent = new HttpsProxyAgent({
2526
host: proxyHost,
2627
port: proxyPort
2728
});
2829
}
29-
if (useCaCertificate && useCaCertificate !== 'undefined') {
30+
if (!isUndefined(useCaCertificate)) {
3031
try {
3132
options.ca = fs.readFileSync(useCaCertificate);
3233
} catch(err) {

lib/util.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports.isUndefined = value => (value === undefined || value === null || value === 'undefined');

0 commit comments

Comments
 (0)