browserstack-cypress-cli 1.14.0 → 1.16.0
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 +6 -3
- package/bin/commands/generateReport.js +18 -12
- package/bin/commands/info.js +73 -68
- package/bin/commands/runs.js +26 -24
- package/bin/commands/stop.js +5 -2
- package/bin/helpers/buildArtifacts.js +9 -9
- package/bin/helpers/capabilityHelper.js +3 -0
- package/bin/helpers/config.js +1 -0
- package/bin/helpers/constants.js +4 -2
- package/bin/helpers/getInitialDetails.js +41 -0
- package/bin/helpers/packageInstaller.js +19 -3
- package/bin/helpers/reporterHTML.js +58 -265
- package/bin/helpers/sync/failedSpecsDetails.js +12 -4
- package/bin/helpers/sync/specsSummary.js +10 -2
- package/bin/helpers/sync/syncSpecsLogs.js +10 -7
- package/bin/helpers/syncRunner.js +2 -2
- package/bin/helpers/usageReporting.js +1 -0
- package/bin/helpers/utils.js +64 -12
- package/bin/runner.js +6 -0
- package/log/usage.log +2 -0
- package/package.json +3 -3
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
const logger = require("../helpers/logger").winstonLogger,
|
|
4
4
|
Constants = require("../helpers/constants"),
|
|
5
5
|
utils = require("../helpers/utils"),
|
|
6
|
-
downloadBuildArtifacts = require('../helpers/buildArtifacts').downloadBuildArtifacts
|
|
6
|
+
downloadBuildArtifacts = require('../helpers/buildArtifacts').downloadBuildArtifacts,
|
|
7
|
+
getInitialDetails = require('../helpers/getInitialDetails').getInitialDetails;
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
module.exports = async function generateDownloads(args, rawArgs) {
|
|
@@ -19,6 +20,8 @@ module.exports = async function generateDownloads(args, rawArgs) {
|
|
|
19
20
|
// accept the access key from command line if provided
|
|
20
21
|
utils.setAccessKey(bsConfig, args);
|
|
21
22
|
|
|
23
|
+
let buildReportData = await getInitialDetails(bsConfig, args, rawArgs);
|
|
24
|
+
|
|
22
25
|
utils.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
|
|
23
26
|
|
|
24
27
|
// set cypress config filename
|
|
@@ -28,8 +31,8 @@ module.exports = async function generateDownloads(args, rawArgs) {
|
|
|
28
31
|
let errorCode = null;
|
|
29
32
|
let buildId = args._[1];
|
|
30
33
|
|
|
31
|
-
await downloadBuildArtifacts(bsConfig, buildId, args, rawArgs);
|
|
32
|
-
utils.sendUsageReport(bsConfig, args, Constants.usageReportingConstants.GENERATE_DOWNLOADS, messageType, errorCode,
|
|
34
|
+
await downloadBuildArtifacts(bsConfig, buildId, args, rawArgs, buildReportData);
|
|
35
|
+
utils.sendUsageReport(bsConfig, args, Constants.usageReportingConstants.GENERATE_DOWNLOADS, messageType, errorCode, buildReportData, rawArgs);
|
|
33
36
|
}).catch(function (err) {
|
|
34
37
|
logger.error(err);
|
|
35
38
|
utils.setUsageReportingFlag(null, args.disableUsageReporting);
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
const logger = require("../helpers/logger").winstonLogger,
|
|
4
4
|
Constants = require("../helpers/constants"),
|
|
5
5
|
utils = require("../helpers/utils"),
|
|
6
|
-
reporterHTML = require('../helpers/reporterHTML')
|
|
6
|
+
reporterHTML = require('../helpers/reporterHTML'),
|
|
7
|
+
getInitialDetails = require('../helpers/getInitialDetails').getInitialDetails;
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
module.exports = function generateReport(args, rawArgs) {
|
|
@@ -20,17 +21,22 @@ module.exports = function generateReport(args, rawArgs) {
|
|
|
20
21
|
// accept the access key from command line if provided
|
|
21
22
|
utils.setAccessKey(bsConfig, args);
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
24
|
+
getInitialDetails(bsConfig, args, rawArgs).then((buildReportData) => {
|
|
25
|
+
|
|
26
|
+
utils.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
|
|
27
|
+
|
|
28
|
+
// set cypress config filename
|
|
29
|
+
utils.setCypressConfigFilename(bsConfig, args);
|
|
30
|
+
|
|
31
|
+
let messageType = Constants.messageTypes.INFO;
|
|
32
|
+
let errorCode = null;
|
|
33
|
+
let buildId = args._[1];
|
|
34
|
+
|
|
35
|
+
reportGenerator(bsConfig, buildId, args, rawArgs, buildReportData);
|
|
36
|
+
utils.sendUsageReport(bsConfig, args, 'generate-report called', messageType, errorCode, buildReportData, rawArgs);
|
|
37
|
+
}).catch((err) => {
|
|
38
|
+
logger.warn(err);
|
|
39
|
+
});
|
|
34
40
|
}).catch(function (err) {
|
|
35
41
|
logger.error(err);
|
|
36
42
|
utils.setUsageReportingFlag(null, args.disableUsageReporting);
|
package/bin/commands/info.js
CHANGED
|
@@ -4,7 +4,8 @@ const request = require('request');
|
|
|
4
4
|
const config = require("../helpers/config"),
|
|
5
5
|
logger = require("../helpers/logger").winstonLogger,
|
|
6
6
|
Constants = require("../helpers/constants"),
|
|
7
|
-
utils = require("../helpers/utils")
|
|
7
|
+
utils = require("../helpers/utils"),
|
|
8
|
+
getInitialDetails = require('../helpers/getInitialDetails').getInitialDetails;
|
|
8
9
|
|
|
9
10
|
module.exports = function info(args, rawArgs) {
|
|
10
11
|
let bsConfigPath = utils.getConfigPath(args.cf);
|
|
@@ -18,82 +19,86 @@ module.exports = function info(args, rawArgs) {
|
|
|
18
19
|
// accept the access key from command line if provided
|
|
19
20
|
utils.setAccessKey(bsConfig, args);
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
getInitialDetails(bsConfig, args, rawArgs).then((buildReportData) => {
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
utils.setCypressConfigFilename(bsConfig, args);
|
|
24
|
+
utils.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
// set cypress config filename
|
|
27
|
+
utils.setCypressConfigFilename(bsConfig, args);
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
url: config.buildUrl + buildId,
|
|
30
|
-
auth: {
|
|
31
|
-
user: bsConfig.auth.username,
|
|
32
|
-
password: bsConfig.auth.access_key,
|
|
33
|
-
},
|
|
34
|
-
headers: {
|
|
35
|
-
'User-Agent': utils.getUserAgent(),
|
|
36
|
-
},
|
|
37
|
-
};
|
|
29
|
+
let buildId = args._[1];
|
|
38
30
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
let
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
build = null;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (resp.statusCode == 299) {
|
|
60
|
-
messageType = Constants.messageTypes.INFO;
|
|
61
|
-
errorCode = 'api_deprecated';
|
|
62
|
-
|
|
63
|
-
if (build) {
|
|
64
|
-
message = build.message;
|
|
65
|
-
logger.info(message);
|
|
66
|
-
} else {
|
|
67
|
-
message = Constants.userMessages.API_DEPRECATED;
|
|
68
|
-
logger.info(message);
|
|
69
|
-
}
|
|
70
|
-
logger.info(utils.formatRequest(err, resp, body));
|
|
71
|
-
} else if (resp.statusCode != 200) {
|
|
31
|
+
let options = {
|
|
32
|
+
url: config.buildUrl + buildId,
|
|
33
|
+
auth: {
|
|
34
|
+
user: bsConfig.auth.username,
|
|
35
|
+
password: bsConfig.auth.access_key,
|
|
36
|
+
},
|
|
37
|
+
headers: {
|
|
38
|
+
'User-Agent': utils.getUserAgent(),
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
request.get(options, function (err, resp, body) {
|
|
42
|
+
let message = null;
|
|
43
|
+
let messageType = null;
|
|
44
|
+
let errorCode = null;
|
|
45
|
+
|
|
46
|
+
if (err) {
|
|
47
|
+
message = Constants.userMessages.BUILD_INFO_FAILED;
|
|
72
48
|
messageType = Constants.messageTypes.ERROR;
|
|
73
49
|
errorCode = 'api_failed_build_info';
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
message = `${
|
|
77
|
-
Constants.userMessages.BUILD_INFO_FAILED
|
|
78
|
-
} with error: \n${JSON.stringify(build, null, 2)}`;
|
|
79
|
-
logger.error(message);
|
|
80
|
-
if (build.message === 'Unauthorized') errorCode = 'api_auth_failed';
|
|
81
|
-
} else {
|
|
82
|
-
message = Constants.userMessages.BUILD_INFO_FAILED;
|
|
83
|
-
logger.error(message);
|
|
84
|
-
}
|
|
50
|
+
|
|
51
|
+
logger.info(message);
|
|
85
52
|
logger.error(utils.formatRequest(err, resp, body));
|
|
86
53
|
} else {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
build
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
54
|
+
let build = null;
|
|
55
|
+
try {
|
|
56
|
+
build = JSON.parse(body);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
build = null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (resp.statusCode == 299) {
|
|
62
|
+
messageType = Constants.messageTypes.INFO;
|
|
63
|
+
errorCode = 'api_deprecated';
|
|
64
|
+
|
|
65
|
+
if (build) {
|
|
66
|
+
message = build.message;
|
|
67
|
+
logger.info(message);
|
|
68
|
+
} else {
|
|
69
|
+
message = Constants.userMessages.API_DEPRECATED;
|
|
70
|
+
logger.info(message);
|
|
71
|
+
}
|
|
72
|
+
logger.info(utils.formatRequest(err, resp, body));
|
|
73
|
+
} else if (resp.statusCode != 200) {
|
|
74
|
+
messageType = Constants.messageTypes.ERROR;
|
|
75
|
+
errorCode = 'api_failed_build_info';
|
|
76
|
+
|
|
77
|
+
if (build) {
|
|
78
|
+
message = `${
|
|
79
|
+
Constants.userMessages.BUILD_INFO_FAILED
|
|
80
|
+
} with error: \n${JSON.stringify(build, null, 2)}`;
|
|
81
|
+
logger.error(message);
|
|
82
|
+
if (build.message === 'Unauthorized') errorCode = 'api_auth_failed';
|
|
83
|
+
} else {
|
|
84
|
+
message = Constants.userMessages.BUILD_INFO_FAILED;
|
|
85
|
+
logger.error(message);
|
|
86
|
+
}
|
|
87
|
+
logger.error(utils.formatRequest(err, resp, body));
|
|
88
|
+
} else {
|
|
89
|
+
messageType = Constants.messageTypes.SUCCESS;
|
|
90
|
+
message = `Build info for build id: \n ${JSON.stringify(
|
|
91
|
+
build,
|
|
92
|
+
null,
|
|
93
|
+
2
|
|
94
|
+
)}`;
|
|
95
|
+
logger.info(message);
|
|
96
|
+
}
|
|
94
97
|
}
|
|
95
|
-
|
|
96
|
-
|
|
98
|
+
utils.sendUsageReport(bsConfig, args, message, messageType, errorCode, buildReportData, rawArgs);
|
|
99
|
+
});
|
|
100
|
+
}).catch((err) => {
|
|
101
|
+
logger.warn(err);
|
|
97
102
|
});
|
|
98
103
|
}).catch(function (err) {
|
|
99
104
|
logger.error(err);
|
package/bin/commands/runs.js
CHANGED
|
@@ -10,6 +10,7 @@ const archiver = require("../helpers/archiver"),
|
|
|
10
10
|
Constants = require("../helpers/constants"),
|
|
11
11
|
utils = require("../helpers/utils"),
|
|
12
12
|
fileHelpers = require("../helpers/fileHelpers"),
|
|
13
|
+
getInitialDetails = require('../helpers/getInitialDetails').getInitialDetails,
|
|
13
14
|
syncRunner = require("../helpers/syncRunner"),
|
|
14
15
|
checkUploaded = require("../helpers/checkUploaded"),
|
|
15
16
|
packageInstaller = require("../helpers/packageInstaller"),
|
|
@@ -52,6 +53,8 @@ module.exports = function run(args, rawArgs) {
|
|
|
52
53
|
// accept the access key from command line or env variable if provided
|
|
53
54
|
utils.setAccessKey(bsConfig, args);
|
|
54
55
|
|
|
56
|
+
let buildReportData = await getInitialDetails(bsConfig, args, rawArgs);
|
|
57
|
+
|
|
55
58
|
// accept the build name from command line if provided
|
|
56
59
|
utils.setBuildName(bsConfig, args);
|
|
57
60
|
|
|
@@ -94,6 +97,9 @@ module.exports = function run(args, rawArgs) {
|
|
|
94
97
|
// set record feature caps
|
|
95
98
|
utils.setRecordCaps(bsConfig, args);
|
|
96
99
|
|
|
100
|
+
// set node version
|
|
101
|
+
utils.setNodeVersion(bsConfig, args);
|
|
102
|
+
|
|
97
103
|
//set browsers
|
|
98
104
|
await utils.setBrowsers(bsConfig, args);
|
|
99
105
|
|
|
@@ -128,7 +134,7 @@ module.exports = function run(args, rawArgs) {
|
|
|
128
134
|
utils.setParallels(bsConfig, args, specFiles.length);
|
|
129
135
|
|
|
130
136
|
// warn if specFiles cross our limit
|
|
131
|
-
utils.warnSpecLimit(bsConfig, args, specFiles, rawArgs);
|
|
137
|
+
utils.warnSpecLimit(bsConfig, args, specFiles, rawArgs, buildReportData);
|
|
132
138
|
markBlockEnd('preArchiveSteps');
|
|
133
139
|
logger.debug("Completed pre-archive steps");
|
|
134
140
|
markBlockStart('zip');
|
|
@@ -168,7 +174,7 @@ module.exports = function run(args, rawArgs) {
|
|
|
168
174
|
//setup Local Testing
|
|
169
175
|
markBlockStart('localSetup');
|
|
170
176
|
logger.debug("Started setting up BrowserStack Local connection");
|
|
171
|
-
let bs_local = await utils.setupLocalTesting(bsConfig, args, rawArgs);
|
|
177
|
+
let bs_local = await utils.setupLocalTesting(bsConfig, args, rawArgs, buildReportData);
|
|
172
178
|
logger.debug('Completed setting up BrowserStack Local connection');
|
|
173
179
|
markBlockEnd('localSetup');
|
|
174
180
|
logger.debug("Started build creation");
|
|
@@ -177,14 +183,10 @@ module.exports = function run(args, rawArgs) {
|
|
|
177
183
|
logger.debug("Completed build creation");
|
|
178
184
|
markBlockEnd('createBuild');
|
|
179
185
|
markBlockEnd('total');
|
|
180
|
-
utils.setProcessHooks(data.build_id, bsConfig, bs_local, args);
|
|
186
|
+
utils.setProcessHooks(data.build_id, bsConfig, bs_local, args, buildReportData);
|
|
181
187
|
let message = `${data.message}! ${Constants.userMessages.BUILD_CREATED} with build id: ${data.build_id}`;
|
|
182
188
|
let dashboardLink = `${Constants.userMessages.VISIT_DASHBOARD} ${data.dashboard_url}`;
|
|
183
|
-
|
|
184
|
-
'build_id': data.build_id,
|
|
185
|
-
'user_id': data.user_id,
|
|
186
|
-
'parallels': userSpecifiedParallels
|
|
187
|
-
};
|
|
189
|
+
buildReportData = { 'build_id': data.build_id, 'parallels': userSpecifiedParallels, ...buildReportData }
|
|
188
190
|
utils.exportResults(data.build_id, `${config.dashboardUrl}${data.build_id}`);
|
|
189
191
|
if ((utils.isUndefined(bsConfig.run_settings.parallels) && utils.isUndefined(args.parallels)) || (!utils.isUndefined(bsConfig.run_settings.parallels) && bsConfig.run_settings.parallels == Constants.cliMessages.RUN.DEFAULT_PARALLEL_MESSAGE)) {
|
|
190
192
|
logger.warn(Constants.userMessages.NO_PARALLELS);
|
|
@@ -208,11 +210,11 @@ module.exports = function run(args, rawArgs) {
|
|
|
208
210
|
|
|
209
211
|
if (args.sync) {
|
|
210
212
|
logger.debug("Started polling build status from BrowserStack");
|
|
211
|
-
syncRunner.pollBuildStatus(bsConfig, data, rawArgs).then(async (exitCode) => {
|
|
213
|
+
syncRunner.pollBuildStatus(bsConfig, data, rawArgs, buildReportData).then(async (exitCode) => {
|
|
212
214
|
logger.debug("Completed polling of build status");
|
|
213
215
|
|
|
214
216
|
// stop the Local instance
|
|
215
|
-
await utils.stopLocalBinary(bsConfig, bs_local, args, rawArgs);
|
|
217
|
+
await utils.stopLocalBinary(bsConfig, bs_local, args, rawArgs, buildReportData);
|
|
216
218
|
|
|
217
219
|
// waiting for 5 secs for upload to complete (as a safety measure)
|
|
218
220
|
await new Promise(resolve => setTimeout(resolve, 5000));
|
|
@@ -221,11 +223,11 @@ module.exports = function run(args, rawArgs) {
|
|
|
221
223
|
if (exitCode != Constants.BUILD_FAILED_EXIT_CODE) {
|
|
222
224
|
if (utils.nonEmptyArray(bsConfig.run_settings.downloads)) {
|
|
223
225
|
logger.debug("Downloading build artifacts");
|
|
224
|
-
await downloadBuildArtifacts(bsConfig, data.build_id, args, rawArgs);
|
|
226
|
+
await downloadBuildArtifacts(bsConfig, data.build_id, args, rawArgs, buildReportData);
|
|
225
227
|
}
|
|
226
228
|
|
|
227
229
|
// Generate custom report!
|
|
228
|
-
reportGenerator(bsConfig, data.build_id, args, rawArgs, function(){
|
|
230
|
+
reportGenerator(bsConfig, data.build_id, args, rawArgs, buildReportData, function(){
|
|
229
231
|
utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null, buildReportData, rawArgs);
|
|
230
232
|
utils.handleSyncExit(exitCode, data.dashboard_url);
|
|
231
233
|
});
|
|
@@ -299,24 +301,24 @@ module.exports = function run(args, rawArgs) {
|
|
|
299
301
|
// Build creation failed
|
|
300
302
|
logger.error(err);
|
|
301
303
|
// stop the Local instance
|
|
302
|
-
await utils.stopLocalBinary(bsConfig, bs_local, args, rawArgs);
|
|
304
|
+
await utils.stopLocalBinary(bsConfig, bs_local, args, rawArgs, buildReportData);
|
|
303
305
|
|
|
304
|
-
utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'build_failed',
|
|
306
|
+
utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'build_failed', buildReportData, rawArgs);
|
|
305
307
|
process.exitCode = Constants.ERROR_EXIT_CODE;
|
|
306
308
|
});
|
|
307
309
|
}).catch(function (err) {
|
|
308
310
|
// Zip Upload failed | Local Start failed
|
|
309
311
|
logger.error(err);
|
|
310
312
|
if(err === Constants.userMessages.LOCAL_START_FAILED){
|
|
311
|
-
utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.LOCAL_START_FAILED}`, Constants.messageTypes.ERROR, 'local_start_failed',
|
|
313
|
+
utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.LOCAL_START_FAILED}`, Constants.messageTypes.ERROR, 'local_start_failed', buildReportData, rawArgs);
|
|
312
314
|
} else {
|
|
313
315
|
logger.error(Constants.userMessages.ZIP_UPLOAD_FAILED);
|
|
314
316
|
fileHelpers.deleteZip();
|
|
315
|
-
utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.ZIP_UPLOAD_FAILED}`, Constants.messageTypes.ERROR, 'zip_upload_failed',
|
|
317
|
+
utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.ZIP_UPLOAD_FAILED}`, Constants.messageTypes.ERROR, 'zip_upload_failed', buildReportData, rawArgs);
|
|
316
318
|
try {
|
|
317
319
|
fileHelpers.deletePackageArchieve();
|
|
318
320
|
} catch (err) {
|
|
319
|
-
utils.sendUsageReport(bsConfig, args, Constants.userMessages.NPM_DELETE_FAILED, Constants.messageTypes.ERROR, 'npm_deletion_failed',
|
|
321
|
+
utils.sendUsageReport(bsConfig, args, Constants.userMessages.NPM_DELETE_FAILED, Constants.messageTypes.ERROR, 'npm_deletion_failed', buildReportData, rawArgs);
|
|
320
322
|
}
|
|
321
323
|
}
|
|
322
324
|
process.exitCode = Constants.ERROR_EXIT_CODE;
|
|
@@ -325,16 +327,16 @@ module.exports = function run(args, rawArgs) {
|
|
|
325
327
|
// Zipping failed
|
|
326
328
|
logger.error(err);
|
|
327
329
|
logger.error(Constants.userMessages.FAILED_TO_ZIP);
|
|
328
|
-
utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.FAILED_TO_ZIP}`, Constants.messageTypes.ERROR, 'zip_creation_failed',
|
|
330
|
+
utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.FAILED_TO_ZIP}`, Constants.messageTypes.ERROR, 'zip_creation_failed', buildReportData, rawArgs);
|
|
329
331
|
try {
|
|
330
332
|
fileHelpers.deleteZip();
|
|
331
333
|
} catch (err) {
|
|
332
|
-
utils.sendUsageReport(bsConfig, args, Constants.userMessages.ZIP_DELETE_FAILED, Constants.messageTypes.ERROR, 'zip_deletion_failed',
|
|
334
|
+
utils.sendUsageReport(bsConfig, args, Constants.userMessages.ZIP_DELETE_FAILED, Constants.messageTypes.ERROR, 'zip_deletion_failed', buildReportData, rawArgs);
|
|
333
335
|
}
|
|
334
336
|
try {
|
|
335
337
|
fileHelpers.deletePackageArchieve();
|
|
336
338
|
} catch (err) {
|
|
337
|
-
utils.sendUsageReport(bsConfig, args, Constants.userMessages.NPM_DELETE_FAILED, Constants.messageTypes.ERROR, 'npm_deletion_failed',
|
|
339
|
+
utils.sendUsageReport(bsConfig, args, Constants.userMessages.NPM_DELETE_FAILED, Constants.messageTypes.ERROR, 'npm_deletion_failed', buildReportData, rawArgs);
|
|
338
340
|
}
|
|
339
341
|
process.exitCode = Constants.ERROR_EXIT_CODE;
|
|
340
342
|
});
|
|
@@ -342,11 +344,11 @@ module.exports = function run(args, rawArgs) {
|
|
|
342
344
|
// package installer failed
|
|
343
345
|
logger.error(err);
|
|
344
346
|
logger.error(Constants.userMessages.FAILED_CREATE_NPM_ARCHIVE);
|
|
345
|
-
utils.sendUsageReport(bsConfig, args, Constants.userMessages.FAILED_CREATE_NPM_ARCHIVE, Constants.messageTypes.ERROR, 'npm_package_archive_failed',
|
|
347
|
+
utils.sendUsageReport(bsConfig, args, Constants.userMessages.FAILED_CREATE_NPM_ARCHIVE, Constants.messageTypes.ERROR, 'npm_package_archive_failed', buildReportData, rawArgs);
|
|
346
348
|
try {
|
|
347
349
|
fileHelpers.deletePackageArchieve();
|
|
348
350
|
} catch (err) {
|
|
349
|
-
utils.sendUsageReport(bsConfig, args, Constants.userMessages.NPM_DELETE_FAILED, Constants.messageTypes.ERROR, 'npm_deletion_failed',
|
|
351
|
+
utils.sendUsageReport(bsConfig, args, Constants.userMessages.NPM_DELETE_FAILED, Constants.messageTypes.ERROR, 'npm_deletion_failed', buildReportData, rawArgs);
|
|
350
352
|
}
|
|
351
353
|
process.exitCode = Constants.ERROR_EXIT_CODE;
|
|
352
354
|
});
|
|
@@ -354,7 +356,7 @@ module.exports = function run(args, rawArgs) {
|
|
|
354
356
|
// md5 check failed
|
|
355
357
|
logger.error(err);
|
|
356
358
|
logger.error(Constants.userMessages.FAILED_MD5_CHECK);
|
|
357
|
-
utils.sendUsageReport(bsConfig, args, Constants.userMessages.MD5_CHECK_FAILED, Constants.messageTypes.ERROR, 'zip_already_uploaded_failed',
|
|
359
|
+
utils.sendUsageReport(bsConfig, args, Constants.userMessages.MD5_CHECK_FAILED, Constants.messageTypes.ERROR, 'zip_already_uploaded_failed', buildReportData, rawArgs);
|
|
358
360
|
process.exitCode = Constants.ERROR_EXIT_CODE;
|
|
359
361
|
});
|
|
360
362
|
}).catch(function (err) {
|
|
@@ -368,7 +370,7 @@ module.exports = function run(args, rawArgs) {
|
|
|
368
370
|
}
|
|
369
371
|
|
|
370
372
|
let error_code = utils.getErrorCodeFromMsg(err);
|
|
371
|
-
utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.validationMessages.NOT_VALID}`, Constants.messageTypes.ERROR, error_code,
|
|
373
|
+
utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.validationMessages.NOT_VALID}`, Constants.messageTypes.ERROR, error_code, buildReportData, rawArgs);
|
|
372
374
|
process.exitCode = Constants.ERROR_EXIT_CODE;
|
|
373
375
|
});
|
|
374
376
|
}).catch(function (err) {
|
package/bin/commands/stop.js
CHANGED
|
@@ -4,7 +4,8 @@ const request = require('request');
|
|
|
4
4
|
const config = require("../helpers/config"),
|
|
5
5
|
logger = require("../helpers/logger").winstonLogger,
|
|
6
6
|
Constants = require("../helpers/constants"),
|
|
7
|
-
utils = require("../helpers/utils")
|
|
7
|
+
utils = require("../helpers/utils"),
|
|
8
|
+
getInitialDetails = require('../helpers/getInitialDetails').getInitialDetails;
|
|
8
9
|
|
|
9
10
|
module.exports = function stop(args, rawArgs) {
|
|
10
11
|
let bsConfigPath = utils.getConfigPath(args.cf);
|
|
@@ -18,6 +19,8 @@ module.exports = function stop(args, rawArgs) {
|
|
|
18
19
|
// accept the access key from command line if provided
|
|
19
20
|
utils.setAccessKey(bsConfig, args);
|
|
20
21
|
|
|
22
|
+
let buildReportData = await getInitialDetails(bsConfig, args, rawArgs);
|
|
23
|
+
|
|
21
24
|
utils.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
|
|
22
25
|
|
|
23
26
|
// set cypress config filename
|
|
@@ -25,7 +28,7 @@ module.exports = function stop(args, rawArgs) {
|
|
|
25
28
|
|
|
26
29
|
let buildId = args._[1];
|
|
27
30
|
|
|
28
|
-
await utils.stopBrowserStackBuild(bsConfig, args, buildId, rawArgs);
|
|
31
|
+
await utils.stopBrowserStackBuild(bsConfig, args, buildId, rawArgs, buildReportData);
|
|
29
32
|
|
|
30
33
|
}).catch(function (err) {
|
|
31
34
|
logger.error(err);
|
|
@@ -134,7 +134,7 @@ const unzipFile = async (filePath, fileName) => {
|
|
|
134
134
|
});
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
const sendUpdatesToBstack = async (bsConfig, buildId, args, options, rawArgs) => {
|
|
137
|
+
const sendUpdatesToBstack = async (bsConfig, buildId, args, options, rawArgs, buildReportData) => {
|
|
138
138
|
options.url = `${config.buildUrl}${buildId}/build_artifacts/status`;
|
|
139
139
|
|
|
140
140
|
let cypressJSON = utils.getCypressJSON(bsConfig);
|
|
@@ -161,7 +161,7 @@ const sendUpdatesToBstack = async (bsConfig, buildId, args, options, rawArgs) =>
|
|
|
161
161
|
return new Promise (async (resolve, reject) => {
|
|
162
162
|
request.post(options, function (err, resp, data) {
|
|
163
163
|
if(err) {
|
|
164
|
-
utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'api_failed_build_artifacts_status_update',
|
|
164
|
+
utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'api_failed_build_artifacts_status_update', buildReportData, rawArgs);
|
|
165
165
|
logger.error(utils.formatRequest(err, resp, data));
|
|
166
166
|
reject(err);
|
|
167
167
|
} else {
|
|
@@ -172,7 +172,7 @@ const sendUpdatesToBstack = async (bsConfig, buildId, args, options, rawArgs) =>
|
|
|
172
172
|
}
|
|
173
173
|
if (resp.statusCode != 200) {
|
|
174
174
|
if (responseData && responseData["error"]) {
|
|
175
|
-
utils.sendUsageReport(bsConfig, args, responseData["error"], Constants.messageTypes.ERROR, 'api_failed_build_artifacts_status_update',
|
|
175
|
+
utils.sendUsageReport(bsConfig, args, responseData["error"], Constants.messageTypes.ERROR, 'api_failed_build_artifacts_status_update', buildReportData, rawArgs);
|
|
176
176
|
reject(responseData["error"])
|
|
177
177
|
}
|
|
178
178
|
}
|
|
@@ -182,7 +182,7 @@ const sendUpdatesToBstack = async (bsConfig, buildId, args, options, rawArgs) =>
|
|
|
182
182
|
});
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
-
exports.downloadBuildArtifacts = async (bsConfig, buildId, args, rawArgs) => {
|
|
185
|
+
exports.downloadBuildArtifacts = async (bsConfig, buildId, args, rawArgs, buildReportData = null) => {
|
|
186
186
|
return new Promise ( async (resolve, reject) => {
|
|
187
187
|
BUILD_ARTIFACTS_FAIL_COUNT = 0;
|
|
188
188
|
BUILD_ARTIFACTS_TOTAL_COUNT = 0;
|
|
@@ -205,7 +205,7 @@ exports.downloadBuildArtifacts = async (bsConfig, buildId, args, rawArgs) => {
|
|
|
205
205
|
request.get(options, async function (err, resp, body) {
|
|
206
206
|
if(err) {
|
|
207
207
|
logger.error(utils.formatRequest(err, resp, body));
|
|
208
|
-
utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'api_failed_build_artifacts',
|
|
208
|
+
utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'api_failed_build_artifacts', buildReportData, rawArgs);
|
|
209
209
|
process.exitCode = Constants.ERROR_EXIT_CODE;
|
|
210
210
|
} else {
|
|
211
211
|
try {
|
|
@@ -214,7 +214,7 @@ exports.downloadBuildArtifacts = async (bsConfig, buildId, args, rawArgs) => {
|
|
|
214
214
|
logger.error('Downloading the build artifacts failed.');
|
|
215
215
|
logger.error(`Error: Request failed with status code ${resp.statusCode}`)
|
|
216
216
|
logger.error(utils.formatRequest(err, resp, body));
|
|
217
|
-
utils.sendUsageReport(bsConfig, args, buildDetails, Constants.messageTypes.ERROR, 'api_failed_build_artifacts',
|
|
217
|
+
utils.sendUsageReport(bsConfig, args, buildDetails, Constants.messageTypes.ERROR, 'api_failed_build_artifacts', buildReportData, rawArgs);
|
|
218
218
|
process.exitCode = Constants.ERROR_EXIT_CODE;
|
|
219
219
|
} else {
|
|
220
220
|
await createDirectories(buildId, buildDetails);
|
|
@@ -229,8 +229,8 @@ exports.downloadBuildArtifacts = async (bsConfig, buildId, args, rawArgs) => {
|
|
|
229
229
|
message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_SUCCESS.replace('<build-id>', buildId).replace('<user-path>', process.cwd());
|
|
230
230
|
logger.info(message);
|
|
231
231
|
}
|
|
232
|
-
await sendUpdatesToBstack(bsConfig, buildId, args, options, rawArgs)
|
|
233
|
-
utils.sendUsageReport(bsConfig, args, message, messageType, null,
|
|
232
|
+
await sendUpdatesToBstack(bsConfig, buildId, args, options, rawArgs, buildReportData)
|
|
233
|
+
utils.sendUsageReport(bsConfig, args, message, messageType, null, buildReportData, rawArgs);
|
|
234
234
|
}
|
|
235
235
|
} catch (err) {
|
|
236
236
|
messageType = Constants.messageTypes.ERROR;
|
|
@@ -242,7 +242,7 @@ exports.downloadBuildArtifacts = async (bsConfig, buildId, args, rawArgs) => {
|
|
|
242
242
|
} else {
|
|
243
243
|
logger.error('Downloading the build artifacts failed.');
|
|
244
244
|
}
|
|
245
|
-
utils.sendUsageReport(bsConfig, args, err, messageType, errorCode,
|
|
245
|
+
utils.sendUsageReport(bsConfig, args, err, messageType, errorCode, buildReportData, rawArgs);
|
|
246
246
|
logger.error(`Error: Request failed with status code ${resp.statusCode}`)
|
|
247
247
|
logger.error(utils.formatRequest(err, resp, body));
|
|
248
248
|
process.exitCode = Constants.ERROR_EXIT_CODE;
|
|
@@ -254,6 +254,9 @@ const validate = (bsConfig, args) => {
|
|
|
254
254
|
}
|
|
255
255
|
}
|
|
256
256
|
|
|
257
|
+
if (!Utils.isUndefined(bsConfig.run_settings.nodeVersion) && typeof(bsConfig.run_settings.nodeVersion) === 'string' && !bsConfig.run_settings.nodeVersion.match(/^(\d+\.)?(\d+\.)?(\*|\d+)$/))
|
|
258
|
+
logger.warn(Constants.validationMessages.NODE_VERSION_PARSING_ERROR);
|
|
259
|
+
|
|
257
260
|
resolve(cypressJson);
|
|
258
261
|
});
|
|
259
262
|
}
|
package/bin/helpers/config.js
CHANGED
|
@@ -16,6 +16,7 @@ config.cypress_v1 = `${config.rails_host}/automate/cypress/v1`;
|
|
|
16
16
|
config.buildUrl = `${config.cypress_v1}/builds/`;
|
|
17
17
|
config.buildStopUrl = `${config.cypress_v1}/builds/stop/`;
|
|
18
18
|
config.checkMd5sum = `${config.cypress_v1}/md5sumcheck/`;
|
|
19
|
+
config.getInitialDetails = `${config.cypress_v1}/get_initial_details/`;
|
|
19
20
|
config.fileName = "tests.zip";
|
|
20
21
|
config.packageFileName = "bstackPackages.tar.gz";
|
|
21
22
|
config.packageDirName = "tmpBstackPackages";
|
package/bin/helpers/constants.js
CHANGED
|
@@ -104,7 +104,8 @@ const validationMessages = {
|
|
|
104
104
|
SPEC_TIMEOUT_LIMIT_ERROR: "The maximum allowed value of 'spec_timeout' is 120. Read more on https://browserstack.com/docs/automate/cypress/spec-timeout ",
|
|
105
105
|
SPEC_TIMEOUT_NOT_PASSED_ERROR: "'spec_timeout' key not specified. Going ahead with 30 mins as the default spec timeout. Read more about how to specify the option in https://browserstack.com/docs/automate/cypress/spec-timeout ",
|
|
106
106
|
PROJECT_ID_MISSING: "You have specified '--record' flag but you've not provided the 'projectId' in cypress.json or in browserstack.json. Your record functionality on cypress.io dashboard might not work as it needs both the key and the projectId",
|
|
107
|
-
RECORD_KEY_MISSING: "You have specified '--record' flag but you've not provided the '--record-key' and we could not find any value in 'CYPRESS_RECORD_KEY' environment variable. Your record functionality on cypress.io dashboard might not work as it needs the key and projectId"
|
|
107
|
+
RECORD_KEY_MISSING: "You have specified '--record' flag but you've not provided the '--record-key' and we could not find any value in 'CYPRESS_RECORD_KEY' environment variable. Your record functionality on cypress.io dashboard might not work as it needs the key and projectId",
|
|
108
|
+
NODE_VERSION_PARSING_ERROR: "We weren't able to successfully parse the specified nodeVersion. We will be using the default nodeVersion to run your tests."
|
|
108
109
|
};
|
|
109
110
|
|
|
110
111
|
const cliMessages = {
|
|
@@ -151,7 +152,8 @@ const cliMessages = {
|
|
|
151
152
|
SPEC_TIMEOUT: "Specify a value for a hard timeout for each spec execution in the 1-120 mins range. Read https://browserstack.com/docs/automate/cypress/spec-timeout for more details.",
|
|
152
153
|
RECORD: "Pass the --record flag to record your Cypress runs on Cypress.io dashboard. Note: You also need to specify '--record-key' and '--projectId' arguments either in CLI or in browserstack.json.",
|
|
153
154
|
RECORD_KEY: "You can specify the 'key' that is needed to record your runs on Cypress.io dashboard using the '--record-key' argument. Alternatively, you can also pass it on browserstack.json",
|
|
154
|
-
PROJECT_ID: "You can pass the 'projectId' of your Cypress.io project where you want to record your runs if specifying the '--record' key. You can also specify this in your cypress.json or in your browserstack.json."
|
|
155
|
+
PROJECT_ID: "You can pass the 'projectId' of your Cypress.io project where you want to record your runs if specifying the '--record' key. You can also specify this in your cypress.json or in your browserstack.json.",
|
|
156
|
+
NODE_VERSION: "Pass the node version that you want BrowserStack to use to run your Cypress tests on."
|
|
155
157
|
},
|
|
156
158
|
COMMON: {
|
|
157
159
|
DISABLE_USAGE_REPORTING: "Disable usage reporting",
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const request = require('request'),
|
|
2
|
+
logger = require('./logger').winstonLogger,
|
|
3
|
+
utils = require('./utils'),
|
|
4
|
+
config = require("./config"),
|
|
5
|
+
Constants = require('./constants');
|
|
6
|
+
|
|
7
|
+
exports.getInitialDetails = (bsConfig, args, rawArgs) => {
|
|
8
|
+
return new Promise((resolve, reject) => {
|
|
9
|
+
let options = {
|
|
10
|
+
url: config.getInitialDetails,
|
|
11
|
+
auth: {
|
|
12
|
+
username: bsConfig.auth.username,
|
|
13
|
+
password: bsConfig.auth.access_key,
|
|
14
|
+
},
|
|
15
|
+
headers: {
|
|
16
|
+
'User-Agent': utils.getUserAgent(),
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
let responseData = {};
|
|
20
|
+
request.get(options, function (err, resp, data) {
|
|
21
|
+
if(err) {
|
|
22
|
+
logger.warn(utils.formatRequest(err, resp, data));
|
|
23
|
+
utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'get_initial_details_failed', null, rawArgs);
|
|
24
|
+
resolve({});
|
|
25
|
+
} else {
|
|
26
|
+
try {
|
|
27
|
+
responseData = JSON.parse(data);
|
|
28
|
+
} catch (e) {
|
|
29
|
+
responseData = {};
|
|
30
|
+
}
|
|
31
|
+
if(resp.statusCode != 200) {
|
|
32
|
+
logger.warn(`Warn: Get Initial Details Request failed with status code ${resp.statusCode}`);
|
|
33
|
+
utils.sendUsageReport(bsConfig, args, responseData["error"], Constants.messageTypes.ERROR, 'get_initial_details_failed', null, rawArgs);
|
|
34
|
+
resolve({});
|
|
35
|
+
} else {
|
|
36
|
+
resolve(responseData);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
};
|
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
fileHelpers = require('./fileHelpers'),
|
|
6
6
|
logger = require("./logger").winstonLogger,
|
|
7
7
|
Constants = require('./constants'),
|
|
8
|
-
process = require('process'),
|
|
9
8
|
utils = require('./utils'),
|
|
9
|
+
{ get_version } = require('./usageReporting'),
|
|
10
|
+
process = require('process'),
|
|
10
11
|
{ spawn } = require('child_process'),
|
|
11
12
|
util = require('util');
|
|
12
13
|
|
|
@@ -64,7 +65,7 @@ const packageInstall = (packageDir) => {
|
|
|
64
65
|
logger.info(`Packages were installed locally successfully.`);
|
|
65
66
|
resolve('Packages were installed successfully.');
|
|
66
67
|
} else {
|
|
67
|
-
logger.error(`Some error occurred while installing packages. Error code ${code}
|
|
68
|
+
logger.error(`Some error occurred while installing packages. Error code ${code}. Please read npm_install_debug.log for more info.`);
|
|
68
69
|
reject(`Packages were not installed successfully. Error code ${code}`);
|
|
69
70
|
}
|
|
70
71
|
};
|
|
@@ -72,7 +73,22 @@ const packageInstall = (packageDir) => {
|
|
|
72
73
|
logger.error(`Some error occurred while installing packages: %j`, error);
|
|
73
74
|
reject(`Packages were not installed successfully. Error Description ${util.format('%j', error)}`);
|
|
74
75
|
};
|
|
75
|
-
|
|
76
|
+
|
|
77
|
+
let nodeProcess;
|
|
78
|
+
logger.debug(`Fetching npm version and its major version`);
|
|
79
|
+
const npm_version = get_version('npm')
|
|
80
|
+
const npm_major_version = utils.getMajorVersion(npm_version);
|
|
81
|
+
logger.debug(`Fetched npm version: ${npm_version} and its major version: ${npm_major_version}`);
|
|
82
|
+
|
|
83
|
+
// add --legacy-peer-deps flag while installing dependencies for npm v7+
|
|
84
|
+
// For more info please read "Peer Dependencies" section here -> https://github.blog/2021-02-02-npm-7-is-now-generally-available/
|
|
85
|
+
if (parseInt(npm_major_version) >= 7) {
|
|
86
|
+
logger.debug(`Running NPM install command: npm install --legacy-peer-deps --loglevel verbose > ../npm_install_debug.log`);
|
|
87
|
+
nodeProcess = spawn(/^win/.test(process.platform) ? 'npm.cmd' : 'npm', ['install', '--legacy-peer-deps', '--loglevel', 'verbose', '>', '../npm_install_debug.log', '2>&1'], {cwd: packageDir, shell: true});
|
|
88
|
+
} else {
|
|
89
|
+
logger.debug(`Running NPM install command: 'npm install --loglevel verbose > ../npm_install_debug.log'`);
|
|
90
|
+
nodeProcess = spawn(/^win/.test(process.platform) ? 'npm.cmd' : 'npm', ['install', '--loglevel', 'verbose', '>', '../npm_install_debug.log', '2>&1'], {cwd: packageDir, shell: true});
|
|
91
|
+
}
|
|
76
92
|
nodeProcess.on('close', nodeProcessCloseCallback);
|
|
77
93
|
nodeProcess.on('error', nodeProcessErrorCallback);
|
|
78
94
|
});
|