|
1 | 1 | 'use strict';
|
2 |
| -const fs = require('fs'); |
3 |
| - |
4 | 2 | const archiver = require("../helpers/archiver"),
|
5 | 3 | zipUploader = require("../helpers/zipUpload"),
|
6 | 4 | build = require("../helpers/build"),
|
7 | 5 | logger = require("../helpers/logger").winstonLogger,
|
8 | 6 | config = require("../helpers/config"),
|
9 | 7 | capabilityHelper = require("../helpers/capabilityHelper"),
|
10 | 8 | Constants = require("../helpers/constants"),
|
11 |
| - util = require("../helpers/util"); |
| 9 | + utils = require("../helpers/utils"), |
| 10 | + fileHelpers = require("../helpers/fileHelpers"); |
12 | 11 |
|
13 | 12 | 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) { |
28 | 13 | let bsConfigPath = process.cwd() + args.cf;
|
29 | 14 |
|
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); |
32 | 17 |
|
33 | 18 | // Validate browserstack.json values
|
| 19 | +<<<<<<< HEAD |
34 | 20 | capabilityHelper.validate(bsConfig, args).then(function (validated) {
|
| 21 | +======= |
| 22 | + return capabilityHelper.validate(bsConfig).then(function (validated) { |
| 23 | +>>>>>>> f095146de37ef938646c7144ff45f904b3645b99 |
35 | 24 | logger.info(validated);
|
36 | 25 |
|
| 26 | + // accept the number of parallels |
| 27 | + util.setParallels(bsConfig, args); |
| 28 | + |
37 | 29 | // 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) { |
39 | 31 |
|
40 | 32 | // Uploaded zip file
|
41 |
| - zipUploader.zipUpload(bsConfig, config.fileName).then(function (zip) { |
| 33 | + return zipUploader.zipUpload(bsConfig, config.fileName).then(function (zip) { |
42 | 34 |
|
43 | 35 | // Create build
|
44 |
| - build.createBuild(bsConfig, zip).then(function (message) { |
| 36 | + return build.createBuild(bsConfig, zip).then(function (message) { |
45 | 37 | logger.info(message);
|
46 |
| - util.sendUsageReport(bsConfig, args, message, Constants.messageTypes.SUCCESS, null); |
| 38 | + utils.sendUsageReport(bsConfig, args, message, Constants.messageTypes.SUCCESS, null); |
47 | 39 | return;
|
48 | 40 | }).catch(function (err) {
|
49 | 41 | // Build creation failed
|
50 | 42 | 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'); |
52 | 44 | });
|
53 | 45 | }).catch(function (err) {
|
54 | 46 | // 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'); |
58 | 50 | }).finally(function () {
|
59 |
| - deleteZip(); |
| 51 | + fileHelpers.deleteZip(); |
60 | 52 | });
|
61 | 53 | }).catch(function (err) {
|
62 | 54 | // Zipping failed
|
63 | 55 | logger.error(err);
|
64 | 56 | 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'); |
66 | 58 | try {
|
67 |
| - deleteZip(); |
| 59 | + fileHelpers.deleteZip(); |
68 | 60 | } 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'); |
70 | 62 | }
|
71 | 63 | });
|
72 | 64 | }).catch(function (err) {
|
73 | 65 | // browerstack.json is not valid
|
74 | 66 | logger.error(err);
|
75 | 67 | logger.error(Constants.validationMessages.NOT_VALID);
|
76 | 68 |
|
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); |
79 | 71 | });
|
80 | 72 | }).catch(function (err) {
|
81 | 73 | 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 | + }); |
85 | 77 | }
|
0 commit comments