|
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 |
34 | | - capabilityHelper.validate(bsConfig, args).then(function (validated) { |
| 19 | + return capabilityHelper.validate(bsConfig).then(function (validated) { |
35 | 20 | logger.info(validated); |
36 | 21 |
|
37 | 22 | // accept the number of parallels |
38 | 23 | util.setParallels(bsConfig, args); |
39 | 24 |
|
40 | 25 | // Archive the spec files |
41 | | - archiver.archive(bsConfig.run_settings, config.fileName).then(function (data) { |
| 26 | + return archiver.archive(bsConfig.run_settings, config.fileName).then(function (data) { |
42 | 27 |
|
43 | 28 | // Uploaded zip file |
44 | | - zipUploader.zipUpload(bsConfig, config.fileName).then(function (zip) { |
| 29 | + return zipUploader.zipUpload(bsConfig, config.fileName).then(function (zip) { |
45 | 30 |
|
46 | 31 | // Create build |
47 | | - build.createBuild(bsConfig, zip).then(function (message) { |
| 32 | + return build.createBuild(bsConfig, zip).then(function (message) { |
48 | 33 | logger.info(message); |
49 | | - util.sendUsageReport(bsConfig, args, message, Constants.messageTypes.SUCCESS, null); |
| 34 | + utils.sendUsageReport(bsConfig, args, message, Constants.messageTypes.SUCCESS, null); |
50 | 35 | return; |
51 | 36 | }).catch(function (err) { |
52 | 37 | // Build creation failed |
53 | 38 | logger.error(err); |
54 | | - util.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'build_failed'); |
| 39 | + utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'build_failed'); |
55 | 40 | }); |
56 | 41 | }).catch(function (err) { |
57 | 42 | // Zip Upload failed |
58 | | - logger.error(err) |
59 | | - logger.error(Constants.userMessages.ZIP_UPLOAD_FAILED) |
60 | | - util.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.ZIP_UPLOAD_FAILED}`, Constants.messageTypes.ERROR, 'zip_upload_failed'); |
| 43 | + logger.error(err); |
| 44 | + logger.error(Constants.userMessages.ZIP_UPLOAD_FAILED); |
| 45 | + utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.ZIP_UPLOAD_FAILED}`, Constants.messageTypes.ERROR, 'zip_upload_failed'); |
61 | 46 | }).finally(function () { |
62 | | - deleteZip(); |
| 47 | + fileHelpers.deleteZip(); |
63 | 48 | }); |
64 | 49 | }).catch(function (err) { |
65 | 50 | // Zipping failed |
66 | 51 | logger.error(err); |
67 | 52 | logger.error(Constants.userMessages.FAILED_TO_ZIP); |
68 | | - util.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.FAILED_TO_ZIP}`, Constants.messageTypes.ERROR, 'zip_creation_failed'); |
| 53 | + utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.FAILED_TO_ZIP}`, Constants.messageTypes.ERROR, 'zip_creation_failed'); |
69 | 54 | try { |
70 | | - deleteZip(); |
| 55 | + fileHelpers.deleteZip(); |
71 | 56 | } catch (err) { |
72 | | - util.sendUsageReport(bsConfig, args, Constants.userMessages.ZIP_DELETE_FAILED, Constants.messageTypes.ERROR, 'zip_deletion_failed'); |
| 57 | + utils.sendUsageReport(bsConfig, args, Constants.userMessages.ZIP_DELETE_FAILED, Constants.messageTypes.ERROR, 'zip_deletion_failed'); |
73 | 58 | } |
74 | 59 | }); |
75 | 60 | }).catch(function (err) { |
76 | 61 | // browerstack.json is not valid |
77 | 62 | logger.error(err); |
78 | 63 | logger.error(Constants.validationMessages.NOT_VALID); |
79 | 64 |
|
80 | | - let error_code = util.getErrorCodeFromMsg(err); |
81 | | - util.sendUsageReport(bsConfig, args, `${err}\n${Constants.validationMessages.NOT_VALID}`, Constants.messageTypes.ERROR, error_code); |
| 65 | + let error_code = utils.getErrorCodeFromMsg(err); |
| 66 | + utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.validationMessages.NOT_VALID}`, Constants.messageTypes.ERROR, error_code); |
82 | 67 | }); |
83 | 68 | }).catch(function (err) { |
84 | 69 | logger.error(err); |
85 | | - util.setUsageReportingFlag(null, args.disableUsageReporting); |
86 | | - util.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, util.getErrorCodeFromErr(err)); |
87 | | - }) |
| 70 | + utils.setUsageReportingFlag(null, args.disableUsageReporting); |
| 71 | + utils.sendUsageReport(null, args, err.message, Constants.messageTypes.ERROR, utils.getErrorCodeFromErr(err)); |
| 72 | + }); |
88 | 73 | } |
0 commit comments