browserstack-cypress-cli 1.9.0 → 1.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/commands/generateDownloads.js +39 -0
- package/bin/commands/generateReport.js +5 -4
- package/bin/commands/info.js +4 -3
- package/bin/commands/init.js +6 -6
- package/bin/commands/runs.js +197 -89
- package/bin/commands/stop.js +5 -65
- package/bin/helpers/buildArtifacts.js +250 -0
- package/bin/helpers/capabilityHelper.js +10 -3
- package/bin/helpers/checkUploaded.js +57 -16
- package/bin/helpers/config.js +2 -0
- package/bin/helpers/constants.js +64 -12
- package/bin/helpers/fileHelpers.js +14 -0
- package/bin/helpers/hashUtil.js +5 -1
- package/bin/helpers/packageInstaller.js +134 -0
- package/bin/helpers/reporterHTML.js +78 -22
- package/bin/helpers/sync/syncSpecsLogs.js +13 -10
- package/bin/helpers/timeComponents.js +9 -3
- package/bin/helpers/usageReporting.js +30 -2
- package/bin/helpers/utils.js +331 -12
- package/bin/helpers/zipUpload.js +104 -31
- package/bin/runner.js +109 -118
- package/package.json +6 -4
- package/.nyc_output/8250a512-572d-46ce-b8a0-1994c1cafa91.json +0 -1
- package/.nyc_output/c4d99e47-3a09-4e3a-9b8d-5fd3063b36ae.json +0 -1
- package/.nyc_output/processinfo/8250a512-572d-46ce-b8a0-1994c1cafa91.json +0 -1
- package/.nyc_output/processinfo/c4d99e47-3a09-4e3a-9b8d-5fd3063b36ae.json +0 -1
- package/.nyc_output/processinfo/index.json +0 -1
- package/log/usage.log +0 -16
package/bin/helpers/utils.js
CHANGED
|
@@ -6,13 +6,16 @@ const glob = require('glob');
|
|
|
6
6
|
const getmac = require('getmac').default;
|
|
7
7
|
const { v4: uuidv4 } = require('uuid');
|
|
8
8
|
const browserstack = require('browserstack-local');
|
|
9
|
+
const crypto = require('crypto');
|
|
9
10
|
|
|
10
11
|
const usageReporting = require("./usageReporting"),
|
|
11
12
|
logger = require("./logger").winstonLogger,
|
|
12
13
|
Constants = require("./constants"),
|
|
13
14
|
chalk = require('chalk'),
|
|
14
15
|
syncCliLogger = require("../helpers/logger").syncCliLogger,
|
|
15
|
-
|
|
16
|
+
fileHelpers = require("./fileHelpers"),
|
|
17
|
+
config = require("../helpers/config"),
|
|
18
|
+
pkg = require('../../package.json');
|
|
16
19
|
|
|
17
20
|
const request = require('request');
|
|
18
21
|
|
|
@@ -79,6 +82,9 @@ exports.getErrorCodeFromMsg = (errMsg) => {
|
|
|
79
82
|
case Constants.validationMessages.INVALID_CYPRESS_CONFIG_FILE:
|
|
80
83
|
errorCode = 'invalid_cypress_config_file';
|
|
81
84
|
break;
|
|
85
|
+
case Constants.validationMessages.INVALID_LOCAL_ASYNC_ARGS:
|
|
86
|
+
errorCode = 'invalid_local_async_args';
|
|
87
|
+
break;
|
|
82
88
|
}
|
|
83
89
|
if (
|
|
84
90
|
errMsg.includes("Please use --config-file <path to browserstack.json>.")
|
|
@@ -108,7 +114,8 @@ exports.sendUsageReport = (
|
|
|
108
114
|
message,
|
|
109
115
|
message_type,
|
|
110
116
|
error_code,
|
|
111
|
-
data
|
|
117
|
+
data,
|
|
118
|
+
rawArgs
|
|
112
119
|
) => {
|
|
113
120
|
usageReporting.send({
|
|
114
121
|
cli_args: args,
|
|
@@ -117,6 +124,7 @@ exports.sendUsageReport = (
|
|
|
117
124
|
error_code: error_code,
|
|
118
125
|
bstack_config: bsConfig,
|
|
119
126
|
data,
|
|
127
|
+
raw_args: rawArgs
|
|
120
128
|
});
|
|
121
129
|
};
|
|
122
130
|
|
|
@@ -132,6 +140,10 @@ exports.setUsageReportingFlag = (bsConfig, disableUsageReporting) => {
|
|
|
132
140
|
}
|
|
133
141
|
};
|
|
134
142
|
|
|
143
|
+
exports.getParallels = (bsConfig, args) => {
|
|
144
|
+
return args.parallels || bsConfig['run_settings']['parallels'];
|
|
145
|
+
}
|
|
146
|
+
|
|
135
147
|
exports.setParallels = (bsConfig, args, numOfSpecs) => {
|
|
136
148
|
if (!this.isUndefined(args.parallels)) {
|
|
137
149
|
bsConfig["run_settings"]["parallels"] = args.parallels;
|
|
@@ -140,6 +152,7 @@ exports.setParallels = (bsConfig, args, numOfSpecs) => {
|
|
|
140
152
|
let maxParallels = browserCombinations.length * numOfSpecs;
|
|
141
153
|
if (numOfSpecs <= 0) {
|
|
142
154
|
bsConfig['run_settings']['parallels'] = browserCombinations.length;
|
|
155
|
+
bsConfig['run_settings']['specs_count'] = numOfSpecs;
|
|
143
156
|
return;
|
|
144
157
|
}
|
|
145
158
|
if (bsConfig['run_settings']['parallels'] > maxParallels && bsConfig['run_settings']['parallels'] != -1 ) {
|
|
@@ -147,10 +160,11 @@ exports.setParallels = (bsConfig, args, numOfSpecs) => {
|
|
|
147
160
|
`Using ${maxParallels} machines instead of ${bsConfig['run_settings']['parallels']} that you configured as there are ${numOfSpecs} specs to be run on ${browserCombinations.length} browser combinations.`
|
|
148
161
|
);
|
|
149
162
|
bsConfig['run_settings']['parallels'] = maxParallels;
|
|
163
|
+
bsConfig['run_settings']['specs_count'] = numOfSpecs;
|
|
150
164
|
}
|
|
151
165
|
};
|
|
152
166
|
|
|
153
|
-
exports.warnSpecLimit = (bsConfig, args, specFiles) => {
|
|
167
|
+
exports.warnSpecLimit = (bsConfig, args, specFiles, rawArgs) => {
|
|
154
168
|
let expectedCharLength = specFiles.join("").length + Constants.METADATA_CHAR_BUFFER_PER_SPEC * specFiles.length;
|
|
155
169
|
let parallels = bsConfig.run_settings.parallels;
|
|
156
170
|
let combinations = this.getBrowserCombinations(bsConfig).length;
|
|
@@ -163,7 +177,9 @@ exports.warnSpecLimit = (bsConfig, args, specFiles) => {
|
|
|
163
177
|
args,
|
|
164
178
|
Constants.userMessages.SPEC_LIMIT_WARNING,
|
|
165
179
|
Constants.messageTypes.WARNING,
|
|
166
|
-
null
|
|
180
|
+
null,
|
|
181
|
+
null,
|
|
182
|
+
rawArgs
|
|
167
183
|
);
|
|
168
184
|
}
|
|
169
185
|
}
|
|
@@ -184,6 +200,11 @@ exports.setDefaults = (bsConfig, args) => {
|
|
|
184
200
|
bsConfig.connection_settings = {};
|
|
185
201
|
}
|
|
186
202
|
|
|
203
|
+
// setting cache_dependencies to true if not present
|
|
204
|
+
if (this.isUndefined(bsConfig.run_settings.cache_dependencies)) {
|
|
205
|
+
bsConfig.run_settings.cache_dependencies = true;
|
|
206
|
+
}
|
|
207
|
+
|
|
187
208
|
}
|
|
188
209
|
|
|
189
210
|
exports.setUsername = (bsConfig, args) => {
|
|
@@ -331,14 +352,23 @@ exports.fixCommaSeparatedString = (string) => {
|
|
|
331
352
|
|
|
332
353
|
exports.isUndefined = value => (value === undefined || value === null);
|
|
333
354
|
|
|
355
|
+
exports.isTrueString = value => (!this.isUndefined(value) && value.toString().toLowerCase() === 'true');
|
|
356
|
+
|
|
334
357
|
exports.isFloat = (value) => Number(value) && Number(value) % 1 !== 0;
|
|
335
358
|
|
|
359
|
+
exports.nonEmptyArray = (value) => {
|
|
360
|
+
if(!this.isUndefined(value) && value && value.length) {
|
|
361
|
+
return true;
|
|
362
|
+
}
|
|
363
|
+
return false;
|
|
364
|
+
}
|
|
365
|
+
|
|
336
366
|
exports.isParallelValid = (value) => {
|
|
337
367
|
return this.isUndefined(value) || !(isNaN(value) || this.isFloat(value) || parseInt(value, 10) === 0 || parseInt(value, 10) < -1) || value === Constants.cliMessages.RUN.DEFAULT_PARALLEL_MESSAGE;
|
|
338
368
|
}
|
|
339
369
|
|
|
340
370
|
exports.getUserAgent = () => {
|
|
341
|
-
return `BStack-Cypress-CLI
|
|
371
|
+
return `BStack-Cypress-CLI/${pkg.version} (${os.arch()}/${os.platform()}/${os.release()})`;
|
|
342
372
|
};
|
|
343
373
|
|
|
344
374
|
exports.isAbsolute = (configPath) => {
|
|
@@ -394,6 +424,82 @@ exports.isCypressProjDirValid = (cypressProjDir, integrationFoldDir) => {
|
|
|
394
424
|
return parentTokens.every((t, i) => childTokens[i] === t);
|
|
395
425
|
};
|
|
396
426
|
|
|
427
|
+
exports.generateUploadParams = (bsConfig, filePath, md5data, fileDetails) => {
|
|
428
|
+
let options = {
|
|
429
|
+
url: config.uploadUrl,
|
|
430
|
+
auth: {
|
|
431
|
+
user: bsConfig.auth.username,
|
|
432
|
+
password: bsConfig.auth.access_key
|
|
433
|
+
},
|
|
434
|
+
formData: {
|
|
435
|
+
file: fs.createReadStream(filePath),
|
|
436
|
+
filetype: fileDetails.filetype,
|
|
437
|
+
filename: fileDetails.filename,
|
|
438
|
+
zipMd5sum: md5data ? md5data : '',
|
|
439
|
+
},
|
|
440
|
+
headers: {
|
|
441
|
+
"User-Agent": exports.getUserAgent(),
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
return options
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
exports.sortJsonKeys = (unordered) => {
|
|
448
|
+
const ordered = Object.keys(unordered).sort().reduce(
|
|
449
|
+
(obj, key) => {
|
|
450
|
+
obj[key] = unordered[key];
|
|
451
|
+
return obj;
|
|
452
|
+
},
|
|
453
|
+
{}
|
|
454
|
+
);
|
|
455
|
+
return ordered
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
exports.generateUploadOptions = (type, md5data, packageData) => {
|
|
459
|
+
let options = {};
|
|
460
|
+
switch (type) {
|
|
461
|
+
case 'zip':
|
|
462
|
+
options = {
|
|
463
|
+
archivePresent: true,
|
|
464
|
+
md5ReturnKey: "zip_url",
|
|
465
|
+
urlPresent: md5data.zipUrlPresent,
|
|
466
|
+
md5Data: md5data.zip_md5sum,
|
|
467
|
+
url: md5data.zipUrl,
|
|
468
|
+
propogateError: true,
|
|
469
|
+
fileDetails: {
|
|
470
|
+
filetype: "zip",
|
|
471
|
+
filename: "tests"
|
|
472
|
+
},
|
|
473
|
+
messages: {
|
|
474
|
+
uploading: Constants.userMessages.UPLOADING_TESTS,
|
|
475
|
+
uploadingSuccess: Constants.userMessages.UPLOADING_TESTS_SUCCESS
|
|
476
|
+
},
|
|
477
|
+
cleanupMethod: fileHelpers.deleteZip,
|
|
478
|
+
}
|
|
479
|
+
break;
|
|
480
|
+
case 'npm':
|
|
481
|
+
options = {
|
|
482
|
+
archivePresent: packageData.packageArchieveCreated,
|
|
483
|
+
md5ReturnKey: "npm_package_url",
|
|
484
|
+
urlPresent: md5data.packageUrlPresent,
|
|
485
|
+
md5Data: md5data.npm_package_md5sum,
|
|
486
|
+
url: md5data.npmPackageUrl,
|
|
487
|
+
propogateError: false,
|
|
488
|
+
fileDetails: {
|
|
489
|
+
filetype: "tar.gz",
|
|
490
|
+
filename: "bstackPackages"
|
|
491
|
+
},
|
|
492
|
+
messages: {
|
|
493
|
+
uploading: Constants.userMessages.UPLOADING_NPM_PACKAGES,
|
|
494
|
+
uploadingSuccess: Constants.userMessages.UPLOADING_NPM_PACKAGES_SUCCESS
|
|
495
|
+
},
|
|
496
|
+
cleanupMethod: fileHelpers.deletePackageArchieve,
|
|
497
|
+
}
|
|
498
|
+
break;
|
|
499
|
+
}
|
|
500
|
+
return options;
|
|
501
|
+
};
|
|
502
|
+
|
|
397
503
|
exports.getLocalFlag = (connectionSettings) => {
|
|
398
504
|
return (
|
|
399
505
|
!this.isUndefined(connectionSettings) &&
|
|
@@ -491,7 +597,7 @@ exports.setLocalMode = (bsConfig, args) => {
|
|
|
491
597
|
}
|
|
492
598
|
};
|
|
493
599
|
|
|
494
|
-
exports.setupLocalTesting = (bsConfig, args) => {
|
|
600
|
+
exports.setupLocalTesting = (bsConfig, args, rawArgs) => {
|
|
495
601
|
return new Promise(async (resolve, reject) => {
|
|
496
602
|
if( bsConfig['connection_settings'] && bsConfig['connection_settings']['local'] && String(bsConfig['connection_settings']['local']) === "true" ){
|
|
497
603
|
let localIdentifierRunning = await this.checkLocalIdentifierRunning(
|
|
@@ -514,7 +620,9 @@ exports.setupLocalTesting = (bsConfig, args) => {
|
|
|
514
620
|
args,
|
|
515
621
|
message,
|
|
516
622
|
Constants.messageTypes.ERROR,
|
|
517
|
-
errorCode
|
|
623
|
+
errorCode,
|
|
624
|
+
null,
|
|
625
|
+
rawArgs
|
|
518
626
|
);
|
|
519
627
|
reject(Constants.userMessages.LOCAL_START_FAILED);
|
|
520
628
|
}
|
|
@@ -528,7 +636,7 @@ exports.setupLocalTesting = (bsConfig, args) => {
|
|
|
528
636
|
});
|
|
529
637
|
};
|
|
530
638
|
|
|
531
|
-
exports.stopLocalBinary = (bsConfig, bs_local, args) => {
|
|
639
|
+
exports.stopLocalBinary = (bsConfig, bs_local, args, rawArgs) => {
|
|
532
640
|
return new Promise(async (resolve, reject) => {
|
|
533
641
|
if(bsConfig['connection_settings'] && bsConfig['connection_settings']['local']){
|
|
534
642
|
let localIdentifierRunning = await this.checkLocalIdentifierRunning(bsConfig,bsConfig["connection_settings"]["local_identifier"]);
|
|
@@ -540,7 +648,9 @@ exports.stopLocalBinary = (bsConfig, bs_local, args) => {
|
|
|
540
648
|
args,
|
|
541
649
|
message,
|
|
542
650
|
Constants.messageTypes.ERROR,
|
|
543
|
-
errorCode
|
|
651
|
+
errorCode,
|
|
652
|
+
null,
|
|
653
|
+
rawArgs
|
|
544
654
|
);
|
|
545
655
|
}
|
|
546
656
|
}
|
|
@@ -557,7 +667,9 @@ exports.stopLocalBinary = (bsConfig, bs_local, args) => {
|
|
|
557
667
|
args,
|
|
558
668
|
message,
|
|
559
669
|
Constants.messageTypes.ERROR,
|
|
560
|
-
errorCode
|
|
670
|
+
errorCode,
|
|
671
|
+
null,
|
|
672
|
+
rawArgs
|
|
561
673
|
);
|
|
562
674
|
resolve(Constants.userMessages.LOCAL_STOP_FAILED);
|
|
563
675
|
}
|
|
@@ -677,6 +789,18 @@ exports.sanitizeSpecsPattern = (pattern) => {
|
|
|
677
789
|
return pattern && pattern.split(",").length > 1 ? "{" + pattern + "}" : pattern;
|
|
678
790
|
}
|
|
679
791
|
|
|
792
|
+
exports.generateUniqueHash = () => {
|
|
793
|
+
const loopback = /(?:[0]{2}[:-]){5}[0]{2}/
|
|
794
|
+
const interFaceList = os.networkInterfaces();
|
|
795
|
+
for (let inter in interFaceList){
|
|
796
|
+
for (const address of interFaceList[inter]) {
|
|
797
|
+
if (loopback.test(address.mac) === false) {
|
|
798
|
+
return crypto.createHash('md5').update(address.mac).digest('hex');
|
|
799
|
+
};
|
|
800
|
+
};
|
|
801
|
+
};
|
|
802
|
+
};
|
|
803
|
+
|
|
680
804
|
exports.getBrowserCombinations = (bsConfig) => {
|
|
681
805
|
let osBrowserArray = [];
|
|
682
806
|
let osBrowser = "";
|
|
@@ -711,18 +835,27 @@ exports.getNetworkErrorMessage = (dashboard_url) => {
|
|
|
711
835
|
return chalk.red(message)
|
|
712
836
|
}
|
|
713
837
|
|
|
714
|
-
exports.versionChangedMessage = (preferredVersion, actualVersion) => {
|
|
838
|
+
exports.versionChangedMessage = (preferredVersion, actualVersion, frameworkUpgradeMessage = '') => {
|
|
715
839
|
let message = Constants.userMessages.CYPRESS_VERSION_CHANGED.replace("<preferredVersion>", preferredVersion);
|
|
716
840
|
message = message.replace("<actualVersion>", actualVersion);
|
|
841
|
+
frameworkUpgradeMessage = frameworkUpgradeMessage.replace('.latest', "");
|
|
842
|
+
message = message.replace('<frameworkUpgradeMessage>', frameworkUpgradeMessage);
|
|
717
843
|
return message
|
|
718
844
|
}
|
|
719
845
|
|
|
720
|
-
exports.latestSyntaxToActualVersionMessage = (latestSyntaxVersion, actualVersion) => {
|
|
846
|
+
exports.latestSyntaxToActualVersionMessage = (latestSyntaxVersion, actualVersion, frameworkUpgradeMessage = '') => {
|
|
721
847
|
let message = Constants.userMessages.LATEST_SYNTAX_TO_ACTUAL_VERSION_MESSAGE.replace("<latestSyntaxVersion>", latestSyntaxVersion);
|
|
722
848
|
message = message.replace("<actualVersion>", actualVersion);
|
|
849
|
+
message = message.replace('<frameworkUpgradeMessage>', frameworkUpgradeMessage)
|
|
723
850
|
return message
|
|
724
851
|
}
|
|
725
852
|
|
|
853
|
+
exports.checkError = (data) => {
|
|
854
|
+
if (!this.isUndefined(data.error)) {
|
|
855
|
+
return data.error
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
|
|
726
859
|
exports.isJSONInvalid = (err, args) => {
|
|
727
860
|
let invalid = true
|
|
728
861
|
|
|
@@ -738,6 +871,10 @@ exports.isJSONInvalid = (err, args) => {
|
|
|
738
871
|
return false
|
|
739
872
|
}
|
|
740
873
|
|
|
874
|
+
if( err === Constants.validationMessages.INVALID_LOCAL_ASYNC_ARGS && !this.isUndefined(args.async)) {
|
|
875
|
+
return false
|
|
876
|
+
}
|
|
877
|
+
|
|
741
878
|
return invalid
|
|
742
879
|
}
|
|
743
880
|
|
|
@@ -745,3 +882,185 @@ exports.deleteBaseUrlFromError = (err) => {
|
|
|
745
882
|
return err.replace(/To test ([\s\S]*)on BrowserStack/g, 'To test on BrowserStack');
|
|
746
883
|
}
|
|
747
884
|
|
|
885
|
+
exports.setBrowsers = async (bsConfig, args) => {
|
|
886
|
+
return new Promise((resolve, reject) => {
|
|
887
|
+
if(!this.isUndefined(args.browser)){
|
|
888
|
+
try{
|
|
889
|
+
bsConfig["browsers"] = []
|
|
890
|
+
let browsersList = args.browser.split(',')
|
|
891
|
+
browsersList.forEach((browser)=>{
|
|
892
|
+
let browserHash = {}
|
|
893
|
+
let osBrowserDetails = browser.split(':')
|
|
894
|
+
if (!this.isUndefined(osBrowserDetails[1])) browserHash['os'] = osBrowserDetails[1].trim()
|
|
895
|
+
let browserDetails = osBrowserDetails[0].split('@')
|
|
896
|
+
browserHash['browser'] = browserDetails[0].trim()
|
|
897
|
+
browserHash['versions'] = []
|
|
898
|
+
browserHash['versions'].push(this.isUndefined(browserDetails[1]) ? "latest" : browserDetails[1].trim())
|
|
899
|
+
bsConfig["browsers"].push(browserHash)
|
|
900
|
+
});
|
|
901
|
+
} catch(err){
|
|
902
|
+
reject(Constants.validationMessages.INVALID_BROWSER_ARGS)
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
resolve()
|
|
906
|
+
});
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
exports.setConfig = (bsConfig, args) => {
|
|
910
|
+
if (!this.isUndefined(args.config)) {
|
|
911
|
+
bsConfig["run_settings"]["config"] = args.config
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
// blindly send other passed configs with run_settings and handle at backend
|
|
916
|
+
exports.setOtherConfigs = (bsConfig, args) => {
|
|
917
|
+
if (!this.isUndefined(args.reporter)) {
|
|
918
|
+
bsConfig["run_settings"]["reporter"] = args.reporter;
|
|
919
|
+
}
|
|
920
|
+
if (!this.isUndefined(args.reporterOptions)) {
|
|
921
|
+
bsConfig["run_settings"]["reporter_options"] = args.reporterOptions;
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
exports.readBsConfigJSON = (bsConfigPath) => {
|
|
926
|
+
try {
|
|
927
|
+
fs.accessSync(bsConfigPath, fs.constants.R_OK);
|
|
928
|
+
return fs.readFileSync(bsConfigPath, 'utf-8');
|
|
929
|
+
} catch (err) {
|
|
930
|
+
return null;
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
exports.getCypressJSON = (bsConfig) => {
|
|
935
|
+
let cypressJSON = undefined;
|
|
936
|
+
if (bsConfig.run_settings.cypress_config_file && bsConfig.run_settings.cypress_config_filename !== 'false') {
|
|
937
|
+
cypressJSON = JSON.parse(
|
|
938
|
+
fs.readFileSync(bsConfig.run_settings.cypressConfigFilePath)
|
|
939
|
+
);
|
|
940
|
+
} else if (bsConfig.run_settings.cypressProjectDir) {
|
|
941
|
+
cypressJSON = JSON.parse(
|
|
942
|
+
fs.readFileSync(path.join(bsConfig.run_settings.cypressProjectDir, 'cypress.json'))
|
|
943
|
+
);
|
|
944
|
+
}
|
|
945
|
+
return cypressJSON;
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
exports.setCLIMode = (bsConfig, args) => {
|
|
949
|
+
args.sync = true;
|
|
950
|
+
if(!this.isUndefined(args.async) && args.async){
|
|
951
|
+
args.sync = false;
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
exports.stopBrowserStackBuild = async (bsConfig, args, buildId, rawArgs) => {
|
|
956
|
+
let that = this;
|
|
957
|
+
return new Promise(function (resolve, reject) {
|
|
958
|
+
let url = config.buildStopUrl + buildId;
|
|
959
|
+
let options = {
|
|
960
|
+
url: url,
|
|
961
|
+
auth: {
|
|
962
|
+
username: bsConfig["auth"]["username"],
|
|
963
|
+
password: bsConfig["auth"]["access_key"],
|
|
964
|
+
},
|
|
965
|
+
headers: {
|
|
966
|
+
'User-Agent': that.getUserAgent(),
|
|
967
|
+
},
|
|
968
|
+
};
|
|
969
|
+
let message = null;
|
|
970
|
+
let messageType = null;
|
|
971
|
+
let errorCode = null;
|
|
972
|
+
let build = null;
|
|
973
|
+
request.post(options, function(err, resp, data) {
|
|
974
|
+
if(err) {
|
|
975
|
+
message = Constants.userMessages.BUILD_STOP_FAILED;
|
|
976
|
+
messageType = Constants.messageTypes.ERROR;
|
|
977
|
+
errorCode = 'api_failed_build_stop';
|
|
978
|
+
logger.info(message);
|
|
979
|
+
} else {
|
|
980
|
+
try {
|
|
981
|
+
build = JSON.parse(data);
|
|
982
|
+
if (resp.statusCode == 299) {
|
|
983
|
+
messageType = Constants.messageTypes.INFO;
|
|
984
|
+
errorCode = 'api_deprecated';
|
|
985
|
+
|
|
986
|
+
if (build) {
|
|
987
|
+
message = build.message;
|
|
988
|
+
logger.info(message);
|
|
989
|
+
} else {
|
|
990
|
+
message = Constants.userMessages.API_DEPRECATED;
|
|
991
|
+
logger.info(message);
|
|
992
|
+
}
|
|
993
|
+
} else if (resp.statusCode != 200) {
|
|
994
|
+
messageType = Constants.messageTypes.ERROR;
|
|
995
|
+
errorCode = 'api_failed_build_stop';
|
|
996
|
+
|
|
997
|
+
if (build) {
|
|
998
|
+
message = `${
|
|
999
|
+
Constants.userMessages.BUILD_STOP_FAILED
|
|
1000
|
+
} with error: \n${JSON.stringify(build, null, 2)}`;
|
|
1001
|
+
logger.error(message);
|
|
1002
|
+
if (build.message === 'Unauthorized') errorCode = 'api_auth_failed';
|
|
1003
|
+
} else {
|
|
1004
|
+
message = Constants.userMessages.BUILD_STOP_FAILED;
|
|
1005
|
+
logger.error(message);
|
|
1006
|
+
}
|
|
1007
|
+
} else {
|
|
1008
|
+
messageType = Constants.messageTypes.SUCCESS;
|
|
1009
|
+
message = `${JSON.stringify(build, null, 2)}`;
|
|
1010
|
+
logger.info(message);
|
|
1011
|
+
}
|
|
1012
|
+
} catch(err) {
|
|
1013
|
+
console.log(err);
|
|
1014
|
+
message = Constants.userMessages.BUILD_STOP_FAILED;
|
|
1015
|
+
messageType = Constants.messageTypes.ERROR;
|
|
1016
|
+
errorCode = 'api_failed_build_stop';
|
|
1017
|
+
logger.info(message);
|
|
1018
|
+
} finally {
|
|
1019
|
+
that.sendUsageReport(bsConfig, args, message, messageType, errorCode, null, rawArgs);
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
resolve();
|
|
1023
|
+
});
|
|
1024
|
+
});
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
exports.setProcessHooks = (buildId, bsConfig, bsLocal, args) => {
|
|
1028
|
+
let bindData = {
|
|
1029
|
+
buildId: buildId,
|
|
1030
|
+
bsConfig: bsConfig,
|
|
1031
|
+
bsLocalInstance: bsLocal,
|
|
1032
|
+
args: args
|
|
1033
|
+
}
|
|
1034
|
+
process.on('SIGINT', processExitHandler.bind(this, bindData));
|
|
1035
|
+
process.on('SIGTERM', processExitHandler.bind(this, bindData));
|
|
1036
|
+
process.on('SIGBREAK', processExitHandler.bind(this, bindData));
|
|
1037
|
+
process.on('uncaughtException', processExitHandler.bind(this, bindData));
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
async function processExitHandler(exitData){
|
|
1041
|
+
logger.warn(Constants.userMessages.PROCESS_KILL_MESSAGE);
|
|
1042
|
+
await this.stopBrowserStackBuild(exitData.bsConfig, exitData.args, exitData.buildId);
|
|
1043
|
+
await this.stopLocalBinary(exitData.bsConfig, exitData.bsLocalInstance, exitData.args);
|
|
1044
|
+
process.exit(0);
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
exports.fetchZipSize = (fileName) => {
|
|
1048
|
+
try {
|
|
1049
|
+
let stats = fs.statSync(fileName)
|
|
1050
|
+
return stats.size; // in bytes
|
|
1051
|
+
}
|
|
1052
|
+
catch(err) {
|
|
1053
|
+
return 0;
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
exports.getVideoConfig = (cypressJson) => {
|
|
1058
|
+
let conf = {
|
|
1059
|
+
video: true,
|
|
1060
|
+
videoUploadOnPasses: true
|
|
1061
|
+
}
|
|
1062
|
+
if (!this.isUndefined(cypressJson.video)) conf.video = cypressJson.video;
|
|
1063
|
+
if (!this.isUndefined(cypressJson.videoUploadOnPasses)) conf.videoUploadOnPasses = cypressJson.videoUploadOnPasses;
|
|
1064
|
+
|
|
1065
|
+
return conf;
|
|
1066
|
+
}
|
package/bin/helpers/zipUpload.js
CHANGED
|
@@ -1,65 +1,138 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
|
|
3
|
+
const request = require("request"),
|
|
4
|
+
fs = require("fs");
|
|
5
|
+
|
|
6
|
+
const cliProgress = require('cli-progress');
|
|
7
|
+
|
|
2
8
|
const config = require("./config"),
|
|
3
|
-
request = require("request"),
|
|
4
|
-
fs = require("fs"),
|
|
5
9
|
logger = require("./logger").winstonLogger,
|
|
6
10
|
Constants = require("./constants"),
|
|
7
|
-
utils = require("./utils")
|
|
8
|
-
fileHelpers = require("./fileHelpers");
|
|
11
|
+
utils = require("./utils");
|
|
9
12
|
|
|
10
|
-
const
|
|
13
|
+
const uploadSuits = (bsConfig, filePath, opts) => {
|
|
11
14
|
return new Promise(function (resolve, reject) {
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
let startTime = Date.now();
|
|
16
|
+
|
|
17
|
+
if (opts.urlPresent) {
|
|
18
|
+
return resolve({ [opts.md5ReturnKey]: opts.url });
|
|
14
19
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
url: config.uploadUrl,
|
|
18
|
-
auth: {
|
|
19
|
-
user: bsConfig.auth.username,
|
|
20
|
-
password: bsConfig.auth.access_key
|
|
21
|
-
},
|
|
22
|
-
formData: {
|
|
23
|
-
file: fs.createReadStream(filePath),
|
|
24
|
-
filetype: 'zip',
|
|
25
|
-
filename: 'tests',
|
|
26
|
-
zipMd5sum: md5data.md5sum ? md5data.md5sum : '',
|
|
27
|
-
},
|
|
28
|
-
headers: {
|
|
29
|
-
"User-Agent": utils.getUserAgent(),
|
|
30
|
-
}
|
|
20
|
+
if (!opts.archivePresent) {
|
|
21
|
+
return resolve({});
|
|
31
22
|
}
|
|
32
23
|
|
|
24
|
+
let size = fs.lstatSync(filePath).size;
|
|
25
|
+
|
|
26
|
+
// create new progress bar
|
|
27
|
+
let bar1 = new cliProgress.SingleBar({
|
|
28
|
+
format: `${filePath} [{bar}] {percentage}% | ETA: {eta}s | Speed: {speed} kbps | Duration: {duration}s [${(size / 1000000).toFixed(2)} MB]`,
|
|
29
|
+
hideCursor: true,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
bar1.start(100, 0, {
|
|
33
|
+
speed: "N/A"
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
bar1.on('start', () => {
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
bar1.on('stop', () => {
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
let options = utils.generateUploadParams(bsConfig, filePath, opts.md5Data, opts.fileDetails)
|
|
33
43
|
let responseData = null;
|
|
34
|
-
request.post(options, function (err, resp, body) {
|
|
44
|
+
var r = request.post(options, function (err, resp, body) {
|
|
45
|
+
clearInterval(q);
|
|
46
|
+
|
|
35
47
|
if (err) {
|
|
36
48
|
reject(err);
|
|
37
49
|
} else {
|
|
38
50
|
try {
|
|
39
51
|
responseData = JSON.parse(body);
|
|
40
52
|
} catch (e) {
|
|
41
|
-
responseData =
|
|
53
|
+
responseData = {};
|
|
42
54
|
}
|
|
43
55
|
if (resp.statusCode != 200) {
|
|
56
|
+
if (resp.statusCode == 401) {
|
|
57
|
+
if (responseData && responseData["error"]) {
|
|
58
|
+
responseData["time"] = Date.now() - startTime;
|
|
59
|
+
return reject(responseData["error"]);
|
|
60
|
+
} else {
|
|
61
|
+
return reject(Constants.validationMessages.INVALID_DEFAULT_AUTH_PARAMS);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (!opts.propogateError){
|
|
65
|
+
return resolve({});
|
|
66
|
+
}
|
|
44
67
|
if(responseData && responseData["error"]){
|
|
68
|
+
responseData["time"] = Date.now() - startTime;
|
|
45
69
|
reject(responseData["error"]);
|
|
46
70
|
} else {
|
|
47
|
-
if(resp.statusCode ==
|
|
48
|
-
reject(Constants.validationMessages.INVALID_DEFAULT_AUTH_PARAMS);
|
|
49
|
-
} else if (resp.statusCode == 413) {
|
|
71
|
+
if (resp.statusCode == 413) {
|
|
50
72
|
reject(Constants.userMessages.ZIP_UPLOAD_LIMIT_EXCEEDED);
|
|
51
73
|
} else {
|
|
52
74
|
reject(Constants.userMessages.ZIP_UPLOADER_NOT_REACHABLE);
|
|
53
75
|
}
|
|
54
76
|
}
|
|
55
77
|
} else {
|
|
56
|
-
|
|
57
|
-
|
|
78
|
+
bar1.update(100, {
|
|
79
|
+
speed: ((size / (Date.now() - startTime)) / 125).toFixed(2) //kbits per sec
|
|
80
|
+
});
|
|
81
|
+
bar1.stop();
|
|
82
|
+
logger.info(`${opts.messages.uploadingSuccess} (${responseData[opts.md5ReturnKey]})`);
|
|
83
|
+
opts.cleanupMethod();
|
|
84
|
+
responseData["time"] = Date.now() - startTime;
|
|
58
85
|
resolve(responseData);
|
|
59
86
|
}
|
|
60
87
|
}
|
|
61
88
|
});
|
|
89
|
+
|
|
90
|
+
var q = setInterval(function () {
|
|
91
|
+
let dispatched = r.req.connection._bytesDispatched;
|
|
92
|
+
let percent = dispatched * 100.0 / size;
|
|
93
|
+
bar1.update(percent, {
|
|
94
|
+
speed: ((dispatched / (Date.now() - startTime)) / 125).toFixed(2) //kbits per sec
|
|
95
|
+
});
|
|
96
|
+
}, 150);
|
|
97
|
+
|
|
62
98
|
});
|
|
63
99
|
}
|
|
64
100
|
|
|
65
|
-
|
|
101
|
+
|
|
102
|
+
const uploadCypressZip = (bsConfig, md5data, packageData) => {
|
|
103
|
+
return new Promise(function (resolve, reject) {
|
|
104
|
+
let obj = {}
|
|
105
|
+
const zipOptions = utils.generateUploadOptions('zip', md5data, packageData);
|
|
106
|
+
const npmOptions = utils.generateUploadOptions('npm', md5data, packageData);
|
|
107
|
+
|
|
108
|
+
if(zipOptions.urlPresent) logger.info(Constants.userMessages.SKIP_UPLOADING_TESTS);
|
|
109
|
+
if(npmOptions.urlPresent) logger.info(Constants.userMessages.SKIP_UPLOADING_NPM_PACKAGES);
|
|
110
|
+
|
|
111
|
+
if (!zipOptions.urlPresent && zipOptions.archivePresent) {
|
|
112
|
+
logger.info(zipOptions.messages.uploading);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (!npmOptions.urlPresent && npmOptions.archivePresent) {
|
|
116
|
+
logger.info(npmOptions.messages.uploading);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
let zipUpload = uploadSuits(bsConfig, config.fileName, zipOptions);
|
|
120
|
+
let npmPackageUpload = uploadSuits(bsConfig, config.packageFileName, npmOptions);
|
|
121
|
+
Promise.all([zipUpload, npmPackageUpload]).then(function (uploads) {
|
|
122
|
+
uploads.forEach(upload => {
|
|
123
|
+
if(upload.zip_url && upload.time) {
|
|
124
|
+
upload.tests_upload_time = upload.time;
|
|
125
|
+
} else if (upload.npm_package_url && upload.time) {
|
|
126
|
+
upload.npm_package_upload_time = upload.time;
|
|
127
|
+
}
|
|
128
|
+
delete upload.time;
|
|
129
|
+
Object.assign(obj, upload);
|
|
130
|
+
});
|
|
131
|
+
return resolve(obj);
|
|
132
|
+
}).catch((error) => {
|
|
133
|
+
return reject(error);
|
|
134
|
+
})
|
|
135
|
+
})
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
exports.zipUpload = uploadCypressZip;
|