Skip to content

Commit 6353632

Browse files
committed
merged master
2 parents 624ef2d + f095146 commit 6353632

31 files changed

+2816
-141
lines changed

.nycrc.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
3+
# cover all files (even if a file isn't touched by any test)
4+
all: true
5+
6+
# check coverage percentage and fail test if below threshold
7+
check-coverage: true
8+
9+
# thresholds
10+
branches: 80
11+
lines: 80
12+
functions: 75
13+
statements: 80

bin/commands/info.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,28 @@ const request = require('request');
44
const config = require("../helpers/config"),
55
logger = require("../helpers/logger").winstonLogger,
66
Constants = require("../helpers/constants"),
7-
util = require("../helpers/util");
7+
utils = require("../helpers/utils");
88

99
module.exports = function info(args) {
10-
return buildInfo(args)
11-
}
12-
13-
function buildInfo(args) {
1410
let bsConfigPath = process.cwd() + args.cf;
1511

16-
util.validateBstackJson(bsConfigPath).then(function (bsConfig) {
17-
util.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
12+
return utils.validateBstackJson(bsConfigPath).then(function (bsConfig) {
13+
utils.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
1814

1915
let buildId = args._[1];
2016

2117
let options = {
2218
url: config.buildUrl + buildId,
23-
method: "GET",
2419
auth: {
2520
user: bsConfig.auth.username,
2621
password: bsConfig.auth.access_key,
2722
},
2823
headers: {
29-
"User-Agent": util.getUserAgent(),
24+
"User-Agent": utils.getUserAgent(),
3025
},
3126
};
3227

33-
request(options, function (err, resp, body) {
28+
request.get(options, function (err, resp, body) {
3429
let message = null;
3530
let messageType = null;
3631
let errorCode = null;
@@ -84,11 +79,11 @@ function buildInfo(args) {
8479
logger.info(message);
8580
}
8681
}
87-
util.sendUsageReport(bsConfig, args, message, messageType, errorCode);
82+
utils.sendUsageReport(bsConfig, args, message, messageType, errorCode);
8883
})
8984
}).catch(function (err) {
9085
logger.error(err);
91-
util.setUsageReportingFlag(null, args.disableUsageReporting);
92-
util.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, util.getErrorCodeFromErr(err));
86+
utils.setUsageReportingFlag(null, args.disableUsageReporting);
87+
utils.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err));
9388
})
9489
}

bin/commands/init.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@
22
const fileHelpers = require("../helpers/fileHelpers"),
33
Constants = require("../helpers/constants"),
44
logger = require("../helpers/logger").winstonLogger,
5-
util = require("../helpers/util");
5+
utils = require("../helpers/utils");
66

77
module.exports = function init(args) {
8-
return createBrowserStackConfig(args)
9-
}
10-
11-
function createBrowserStackConfig(args) {
12-
138
if (args.p) {
149
var path_to_bsconf = args.p + "/browserstack.json";
1510
} else {
@@ -24,16 +19,16 @@ function createBrowserStackConfig(args) {
2419
function allDone() {
2520
let message = Constants.userMessages.CONFIG_FILE_CREATED
2621
logger.info(message);
27-
util.sendUsageReport(null, args, message, Constants.messageTypes.SUCCESS, null);
22+
utils.sendUsageReport(null, args, message, Constants.messageTypes.SUCCESS, null);
2823
}
2924

3025
return fileHelpers.fileExists(config.path, function(exists){
3126
if (exists) {
3227
let message = Constants.userMessages.CONFIG_FILE_EXISTS;
3328
logger.error(message);
34-
util.sendUsageReport(null, args, message, Constants.messageTypes.ERROR, 'bstack_json_already_exists');
29+
utils.sendUsageReport(null, args, message, Constants.messageTypes.ERROR, 'bstack_json_already_exists');
3530
} else {
3631
fileHelpers.write(config, null, allDone);
3732
}
38-
})
33+
});
3934
}

bin/commands/runs.js

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,77 @@
11
'use strict';
2-
const fs = require('fs');
3-
42
const archiver = require("../helpers/archiver"),
53
zipUploader = require("../helpers/zipUpload"),
64
build = require("../helpers/build"),
75
logger = require("../helpers/logger").winstonLogger,
86
config = require("../helpers/config"),
97
capabilityHelper = require("../helpers/capabilityHelper"),
108
Constants = require("../helpers/constants"),
11-
util = require("../helpers/util");
9+
utils = require("../helpers/utils"),
10+
fileHelpers = require("../helpers/fileHelpers");
1211

1312
module.exports = function run(args) {
14-
return runCypress(args);
15-
}
16-
17-
function deleteZip() {
18-
fs.unlink(config.fileName, function (err) {
19-
if(err) {
20-
logger.info(Constants.userMessages.ZIP_DELETE_FAILED);
21-
} else {
22-
logger.info(Constants.userMessages.ZIP_DELETED);
23-
}
24-
});
25-
}
26-
27-
function runCypress(args) {
2813
let bsConfigPath = process.cwd() + args.cf;
2914

30-
util.validateBstackJson(bsConfigPath).then(function (bsConfig) {
31-
util.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
15+
return utils.validateBstackJson(bsConfigPath).then(function (bsConfig) {
16+
utils.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
3217

3318
// Validate browserstack.json values
19+
<<<<<<< HEAD
3420
capabilityHelper.validate(bsConfig, args).then(function (validated) {
21+
=======
22+
return capabilityHelper.validate(bsConfig).then(function (validated) {
23+
>>>>>>> f095146de37ef938646c7144ff45f904b3645b99
3524
logger.info(validated);
3625

26+
// accept the number of parallels
27+
util.setParallels(bsConfig, args);
28+
3729
// Archive the spec files
38-
archiver.archive(bsConfig.run_settings, config.fileName).then(function (data) {
30+
return archiver.archive(bsConfig.run_settings, config.fileName).then(function (data) {
3931

4032
// Uploaded zip file
41-
zipUploader.zipUpload(bsConfig, config.fileName).then(function (zip) {
33+
return zipUploader.zipUpload(bsConfig, config.fileName).then(function (zip) {
4234

4335
// Create build
44-
build.createBuild(bsConfig, zip).then(function (message) {
36+
return build.createBuild(bsConfig, zip).then(function (message) {
4537
logger.info(message);
46-
util.sendUsageReport(bsConfig, args, message, Constants.messageTypes.SUCCESS, null);
38+
utils.sendUsageReport(bsConfig, args, message, Constants.messageTypes.SUCCESS, null);
4739
return;
4840
}).catch(function (err) {
4941
// Build creation failed
5042
logger.error(err);
51-
util.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'build_failed');
43+
utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'build_failed');
5244
});
5345
}).catch(function (err) {
5446
// Zip Upload failed
55-
logger.error(err)
56-
logger.error(Constants.userMessages.ZIP_UPLOAD_FAILED)
57-
util.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.ZIP_UPLOAD_FAILED}`, Constants.messageTypes.ERROR, 'zip_upload_failed');
47+
logger.error(err);
48+
logger.error(Constants.userMessages.ZIP_UPLOAD_FAILED);
49+
utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.ZIP_UPLOAD_FAILED}`, Constants.messageTypes.ERROR, 'zip_upload_failed');
5850
}).finally(function () {
59-
deleteZip();
51+
fileHelpers.deleteZip();
6052
});
6153
}).catch(function (err) {
6254
// Zipping failed
6355
logger.error(err);
6456
logger.error(Constants.userMessages.FAILED_TO_ZIP);
65-
util.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.FAILED_TO_ZIP}`, Constants.messageTypes.ERROR, 'zip_creation_failed');
57+
utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.FAILED_TO_ZIP}`, Constants.messageTypes.ERROR, 'zip_creation_failed');
6658
try {
67-
deleteZip();
59+
fileHelpers.deleteZip();
6860
} catch (err) {
69-
util.sendUsageReport(bsConfig, args, Constants.userMessages.ZIP_DELETE_FAILED, Constants.messageTypes.ERROR, 'zip_deletion_failed');
61+
utils.sendUsageReport(bsConfig, args, Constants.userMessages.ZIP_DELETE_FAILED, Constants.messageTypes.ERROR, 'zip_deletion_failed');
7062
}
7163
});
7264
}).catch(function (err) {
7365
// browerstack.json is not valid
7466
logger.error(err);
7567
logger.error(Constants.validationMessages.NOT_VALID);
7668

77-
let error_code = util.getErrorCodeFromMsg(err);
78-
util.sendUsageReport(bsConfig, args, `${err}\n${Constants.validationMessages.NOT_VALID}`, Constants.messageTypes.ERROR, error_code);
69+
let error_code = utils.getErrorCodeFromMsg(err);
70+
utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.validationMessages.NOT_VALID}`, Constants.messageTypes.ERROR, error_code);
7971
});
8072
}).catch(function (err) {
8173
logger.error(err);
82-
util.setUsageReportingFlag(null, args.disableUsageReporting);
83-
util.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, util.getErrorCodeFromErr(err));
84-
})
74+
utils.setUsageReportingFlag(null, args.disableUsageReporting);
75+
utils.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err));
76+
});
8577
}

bin/commands/stop.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,28 @@ const request = require('request');
44
const config = require("../helpers/config"),
55
logger = require("../helpers/logger").winstonLogger,
66
Constants = require("../helpers/constants"),
7-
util = require("../helpers/util");
7+
utils = require("../helpers/utils");
88

99
module.exports = function stop(args) {
10-
return buildStop(args)
11-
}
12-
13-
function buildStop(args) {
1410
let bsConfigPath = process.cwd() + args.cf;
1511

16-
util.validateBstackJson(bsConfigPath).then(function (bsConfig) {
17-
util.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
12+
return utils.validateBstackJson(bsConfigPath).then(function (bsConfig) {
13+
utils.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
1814

1915
let buildId = args._[1];
2016

2117
let options = {
2218
url: config.buildStopUrl + buildId,
23-
method: "POST",
2419
auth: {
2520
user: bsConfig.auth.username,
2621
password: bsConfig.auth.access_key,
2722
},
2823
headers: {
29-
"User-Agent": util.getUserAgent(),
24+
"User-Agent": utils.getUserAgent(),
3025
},
3126
};
3227

33-
request(options, function (err, resp, body) {
28+
request.post(options, function (err, resp, body) {
3429
let message = null;
3530
let messageType = null;
3631
let errorCode = null;
@@ -80,11 +75,11 @@ function buildStop(args) {
8075
logger.info(message);
8176
}
8277
}
83-
util.sendUsageReport(bsConfig, args, message, messageType, errorCode);
78+
utils.sendUsageReport(bsConfig, args, message, messageType, errorCode);
8479
})
8580
}).catch(function (err) {
8681
logger.error(err);
87-
util.setUsageReportingFlag(null, args.disableUsageReporting);
88-
util.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, util.getErrorCodeFromErr(err));
82+
utils.setUsageReportingFlag(null, args.disableUsageReporting);
83+
utils.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err));
8984
})
9085
}

bin/helpers/archiver.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ const archiveSpecs = (runSettings, filePath) => {
3636

3737
archive.pipe(output);
3838

39-
40-
let allowedFileTypes = [ 'js', 'json', 'txt', 'ts' ]
39+
let allowedFileTypes = [ 'js', 'json', 'txt', 'ts' ];
4140
allowedFileTypes.forEach(fileType => {
4241
archive.glob(`**/*.${fileType}`, { cwd: cypressFolderPath, matchBase: true, ignore: ['node_modules/**', 'package-lock.json', 'package.json', 'browserstack-package.json'] });
4342
});

bin/helpers/build.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const request = require('request');
44
const config = require('./config'),
55
capabilityHelper = require("../helpers/capabilityHelper"),
66
Constants = require('../helpers/constants'),
7-
util =require('../helpers/util');
7+
utils =require('../helpers/utils');
88

99
const createBuild = (bsConfig, zip) => {
1010
return new Promise(function (resolve, reject) {
@@ -17,11 +17,11 @@ const createBuild = (bsConfig, zip) => {
1717
},
1818
headers: {
1919
'Content-Type': 'application/json',
20-
"User-Agent": util.getUserAgent(),
20+
"User-Agent": utils.getUserAgent(),
2121
},
2222
body: data
2323
}
24-
24+
2525
request.post(options, function (err, resp, body) {
2626
if (err) {
2727
reject(err);

0 commit comments

Comments
 (0)