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
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('fs'),
|
|
4
|
+
path = require('path');
|
|
5
|
+
|
|
6
|
+
const unzipper = require('unzipper');
|
|
7
|
+
|
|
8
|
+
const logger = require('./logger').winstonLogger,
|
|
9
|
+
utils = require("./utils"),
|
|
10
|
+
Constants = require("./constants"),
|
|
11
|
+
config = require("./config");
|
|
12
|
+
|
|
13
|
+
const request = require('request');
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
let BUILD_ARTIFACTS_TOTAL_COUNT = 0;
|
|
17
|
+
let BUILD_ARTIFACTS_FAIL_COUNT = 0;
|
|
18
|
+
|
|
19
|
+
const parseAndDownloadArtifacts = async (buildId, data) => {
|
|
20
|
+
return new Promise(async (resolve, reject) => {
|
|
21
|
+
let all_promises = [];
|
|
22
|
+
let combs = Object.keys(data);
|
|
23
|
+
for(let i = 0; i < combs.length; i++) {
|
|
24
|
+
let comb = combs[i];
|
|
25
|
+
let sessions = Object.keys(data[comb]);
|
|
26
|
+
for(let j = 0; j < sessions.length; j++) {
|
|
27
|
+
let sessionId = sessions[j];
|
|
28
|
+
let filePath = path.join('./', 'build_artifacts', buildId, comb, sessionId);
|
|
29
|
+
let fileName = 'build_artifacts.zip';
|
|
30
|
+
BUILD_ARTIFACTS_TOTAL_COUNT += 1;
|
|
31
|
+
all_promises.push(downloadAndUnzip(filePath, fileName, data[comb][sessionId]).catch((error) => {
|
|
32
|
+
BUILD_ARTIFACTS_FAIL_COUNT += 1;
|
|
33
|
+
// delete malformed zip if present
|
|
34
|
+
let tmpFilePath = path.join(filePath, fileName);
|
|
35
|
+
if(fs.existsSync(tmpFilePath)){
|
|
36
|
+
fs.unlinkSync(tmpFilePath);
|
|
37
|
+
}
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
await Promise.all(all_promises);
|
|
42
|
+
resolve();
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const createDirIfNotPresent = async (dir) => {
|
|
47
|
+
return new Promise((resolve) => {
|
|
48
|
+
if (!fs.existsSync(dir)){
|
|
49
|
+
fs.mkdirSync(dir);
|
|
50
|
+
}
|
|
51
|
+
resolve();
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const createDirectories = async (buildId, data) => {
|
|
56
|
+
// create dir for build_artifacts if not already present
|
|
57
|
+
let artifactsDir = path.join('./', 'build_artifacts');
|
|
58
|
+
if (!fs.existsSync(artifactsDir)){
|
|
59
|
+
fs.mkdirSync(artifactsDir);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// create dir for buildId if not already present
|
|
63
|
+
let buildDir = path.join('./', 'build_artifacts', buildId);
|
|
64
|
+
if (fs.existsSync(buildDir)){
|
|
65
|
+
// remove dir in case already exists
|
|
66
|
+
fs.rmdirSync(buildDir, { recursive: true, force: true });
|
|
67
|
+
}
|
|
68
|
+
fs.mkdirSync(buildDir);
|
|
69
|
+
|
|
70
|
+
let combDirs = [];
|
|
71
|
+
let sessionDirs = [];
|
|
72
|
+
let combs = Object.keys(data);
|
|
73
|
+
|
|
74
|
+
for(let i = 0; i < combs.length; i++) {
|
|
75
|
+
let comb = combs[i];
|
|
76
|
+
let combDir = path.join('./', 'build_artifacts', buildId, comb);
|
|
77
|
+
combDirs.push(createDirIfNotPresent(combDir));
|
|
78
|
+
let sessions = Object.keys(data[comb]);
|
|
79
|
+
for(let j = 0; j < sessions.length; j++) {
|
|
80
|
+
let sessionId = sessions[j];
|
|
81
|
+
let sessionDir = path.join('./', 'build_artifacts', buildId, comb, sessionId);
|
|
82
|
+
sessionDirs.push(createDirIfNotPresent(sessionDir));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return new Promise(async (resolve) => {
|
|
87
|
+
// create sub dirs for each combination in build
|
|
88
|
+
await Promise.all(combDirs);
|
|
89
|
+
// create sub dirs for each machine id in combination
|
|
90
|
+
await Promise.all(sessionDirs);
|
|
91
|
+
resolve();
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const downloadAndUnzip = async (filePath, fileName, url) => {
|
|
96
|
+
let tmpFilePath = path.join(filePath, fileName);
|
|
97
|
+
const writer = fs.createWriteStream(tmpFilePath);
|
|
98
|
+
|
|
99
|
+
return new Promise(async (resolve, reject) => {
|
|
100
|
+
request.get(url).on('response', function(response) {
|
|
101
|
+
|
|
102
|
+
if(response.statusCode != 200) {
|
|
103
|
+
reject();
|
|
104
|
+
} else {
|
|
105
|
+
//ensure that the user can call `then()` only when the file has
|
|
106
|
+
//been downloaded entirely.
|
|
107
|
+
response.pipe(writer);
|
|
108
|
+
let error = null;
|
|
109
|
+
writer.on('error', err => {
|
|
110
|
+
error = err;
|
|
111
|
+
writer.close();
|
|
112
|
+
reject(err);
|
|
113
|
+
});
|
|
114
|
+
writer.on('close', async () => {
|
|
115
|
+
if (!error) {
|
|
116
|
+
await unzipFile(filePath, fileName);
|
|
117
|
+
fs.unlinkSync(tmpFilePath);
|
|
118
|
+
resolve(true);
|
|
119
|
+
}
|
|
120
|
+
//no need to call the reject here, as it will have been called in the
|
|
121
|
+
//'error' stream;
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const unzipFile = async (filePath, fileName) => {
|
|
129
|
+
return new Promise( async (resolve, reject) => {
|
|
130
|
+
await unzipper.Open.file(path.join(filePath, fileName))
|
|
131
|
+
.then(d => d.extract({path: filePath, concurrency: 5}))
|
|
132
|
+
.catch((err) => reject(err));
|
|
133
|
+
resolve();
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const sendUpdatesToBstack = async (bsConfig, buildId, args, options, rawArgs) => {
|
|
138
|
+
options.url = `${config.buildUrl}${buildId}/build_artifacts/status`;
|
|
139
|
+
|
|
140
|
+
let cypressJSON = utils.getCypressJSON(bsConfig);
|
|
141
|
+
|
|
142
|
+
let reporter = null;
|
|
143
|
+
if(!utils.isUndefined(args.reporter)) {
|
|
144
|
+
reporter = args.reporter;
|
|
145
|
+
} else if(cypressJSON !== undefined){
|
|
146
|
+
reporter = cypressJSON.reporter;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
let data = {
|
|
150
|
+
feature_usage: {
|
|
151
|
+
downloads: {
|
|
152
|
+
eligible_download_folders: BUILD_ARTIFACTS_TOTAL_COUNT,
|
|
153
|
+
successfully_downloaded_folders: BUILD_ARTIFACTS_TOTAL_COUNT - BUILD_ARTIFACTS_FAIL_COUNT
|
|
154
|
+
},
|
|
155
|
+
reporter: reporter
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
options.formData = data.toString();
|
|
160
|
+
let responseData = null;
|
|
161
|
+
return new Promise (async (resolve, reject) => {
|
|
162
|
+
request.post(options, function (err, resp, data) {
|
|
163
|
+
if(err) {
|
|
164
|
+
utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'api_failed_build_artifacts_status_update', null, rawArgs);
|
|
165
|
+
reject(err);
|
|
166
|
+
} else {
|
|
167
|
+
try {
|
|
168
|
+
responseData = JSON.parse(data);
|
|
169
|
+
} catch(e) {
|
|
170
|
+
responseData = {};
|
|
171
|
+
}
|
|
172
|
+
if (resp.statusCode != 200) {
|
|
173
|
+
if (responseData && responseData["error"]) {
|
|
174
|
+
utils.sendUsageReport(bsConfig, args, responseData["error"], Constants.messageTypes.ERROR, 'api_failed_build_artifacts_status_update', null, rawArgs);
|
|
175
|
+
reject(responseData["error"])
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
resolve()
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
exports.downloadBuildArtifacts = async (bsConfig, buildId, args, rawArgs) => {
|
|
185
|
+
return new Promise ( async (resolve, reject) => {
|
|
186
|
+
BUILD_ARTIFACTS_FAIL_COUNT = 0;
|
|
187
|
+
BUILD_ARTIFACTS_TOTAL_COUNT = 0;
|
|
188
|
+
|
|
189
|
+
let options = {
|
|
190
|
+
url: `${config.buildUrl}${buildId}/build_artifacts`,
|
|
191
|
+
auth: {
|
|
192
|
+
username: bsConfig.auth.username,
|
|
193
|
+
password: bsConfig.auth.access_key,
|
|
194
|
+
},
|
|
195
|
+
headers: {
|
|
196
|
+
'User-Agent': utils.getUserAgent(),
|
|
197
|
+
},
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
let message = null;
|
|
201
|
+
let messageType = null;
|
|
202
|
+
let errorCode = null;
|
|
203
|
+
let buildDetails = null;
|
|
204
|
+
request.get(options, async function (err, resp, body) {
|
|
205
|
+
if(err) {
|
|
206
|
+
utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'api_failed_build_artifacts', null, rawArgs);
|
|
207
|
+
process.exitCode = Constants.ERROR_EXIT_CODE;
|
|
208
|
+
} else {
|
|
209
|
+
try {
|
|
210
|
+
buildDetails = JSON.parse(body);
|
|
211
|
+
if(resp.statusCode != 200) {
|
|
212
|
+
logger.error('Downloading the build artifacts failed.');
|
|
213
|
+
logger.error(`Error: Request failed with status code ${resp.statusCode}`)
|
|
214
|
+
utils.sendUsageReport(bsConfig, args, buildDetails, Constants.messageTypes.ERROR, 'api_failed_build_artifacts', null, rawArgs);
|
|
215
|
+
process.exitCode = Constants.ERROR_EXIT_CODE;
|
|
216
|
+
} else {
|
|
217
|
+
await createDirectories(buildId, buildDetails);
|
|
218
|
+
await parseAndDownloadArtifacts(buildId, buildDetails);
|
|
219
|
+
if (BUILD_ARTIFACTS_FAIL_COUNT > 0) {
|
|
220
|
+
messageType = Constants.messageTypes.ERROR;
|
|
221
|
+
message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_FAILED.replace('<build-id>', buildId).replace('<machine-count>', BUILD_ARTIFACTS_FAIL_COUNT);
|
|
222
|
+
logger.error(message);
|
|
223
|
+
process.exitCode = Constants.ERROR_EXIT_CODE;
|
|
224
|
+
} else {
|
|
225
|
+
messageType = Constants.messageTypes.SUCCESS;
|
|
226
|
+
message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_SUCCESS.replace('<build-id>', buildId).replace('<user-path>', process.cwd());
|
|
227
|
+
logger.info(message);
|
|
228
|
+
}
|
|
229
|
+
await sendUpdatesToBstack(bsConfig, buildId, args, options, rawArgs)
|
|
230
|
+
utils.sendUsageReport(bsConfig, args, message, messageType, null, null, rawArgs);
|
|
231
|
+
}
|
|
232
|
+
} catch (err) {
|
|
233
|
+
messageType = Constants.messageTypes.ERROR;
|
|
234
|
+
errorCode = 'api_failed_build_artifacts';
|
|
235
|
+
if (BUILD_ARTIFACTS_FAIL_COUNT > 0) {
|
|
236
|
+
messageType = Constants.messageTypes.ERROR;
|
|
237
|
+
message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_FAILED.replace('<build-id>', buildId).replace('<machine-count>', BUILD_ARTIFACTS_FAIL_COUNT);
|
|
238
|
+
logger.error(message);
|
|
239
|
+
} else {
|
|
240
|
+
logger.error('Downloading the build artifacts failed.');
|
|
241
|
+
}
|
|
242
|
+
utils.sendUsageReport(bsConfig, args, err, messageType, errorCode, null, rawArgs);
|
|
243
|
+
logger.error(`Error: Request failed with status code ${resp.statusCode}`)
|
|
244
|
+
process.exitCode = Constants.ERROR_EXIT_CODE;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
resolve();
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
const logger = require("./logger").winstonLogger,
|
|
2
2
|
Constants = require("./constants"),
|
|
3
3
|
Utils = require("./utils"),
|
|
4
|
-
fs = require('fs')
|
|
5
|
-
path = require('path');
|
|
4
|
+
fs = require('fs');
|
|
6
5
|
|
|
7
6
|
const caps = (bsConfig, zip) => {
|
|
8
7
|
return new Promise(function (resolve, reject) {
|
|
@@ -24,7 +23,7 @@ const caps = (bsConfig, zip) => {
|
|
|
24
23
|
if (bsConfig.browsers) {
|
|
25
24
|
bsConfig.browsers.forEach((element) => {
|
|
26
25
|
osBrowser = element.os + "-" + element.browser;
|
|
27
|
-
osAndBrowser = element.os + " / " + Utils.capitalizeFirstLetter(element.browser);
|
|
26
|
+
osAndBrowser = (element.os) ? element.os : "Any OS" + " / " + Utils.capitalizeFirstLetter(element.browser);
|
|
28
27
|
element.versions.forEach((version) => {
|
|
29
28
|
osBrowserArray.push(osBrowser + version);
|
|
30
29
|
browsersList.push(`${osAndBrowser} (${version})`);
|
|
@@ -42,6 +41,12 @@ const caps = (bsConfig, zip) => {
|
|
|
42
41
|
reject("Test suite is empty");
|
|
43
42
|
}
|
|
44
43
|
|
|
44
|
+
// Npm package
|
|
45
|
+
if (zip.npm_package_url && zip.npm_package_url.split("://")[1].length !== 0) {
|
|
46
|
+
obj.npm_package_suite = zip.npm_package_url.split("://")[1];
|
|
47
|
+
}
|
|
48
|
+
obj.cache_dependencies = bsConfig.run_settings.cache_dependencies;
|
|
49
|
+
|
|
45
50
|
// Inferred settings
|
|
46
51
|
if(bsConfig.connection_settings){
|
|
47
52
|
if (bsConfig.connection_settings.local_mode_inferred) {
|
|
@@ -157,6 +162,8 @@ const validate = (bsConfig, args) => {
|
|
|
157
162
|
|
|
158
163
|
if( Utils.searchForOption('--local-config-file') && ( Utils.isUndefined(args.localConfigFile) || (!Utils.isUndefined(args.localConfigFile) && !fs.existsSync(args.localConfigFile)))) reject(Constants.validationMessages.INVALID_LOCAL_CONFIG_FILE);
|
|
159
164
|
|
|
165
|
+
if( Utils.searchForOption('--async') && ( !Utils.isUndefined(args.async) && bsConfig["connection_settings"]["local"])) reject(Constants.validationMessages.INVALID_LOCAL_ASYNC_ARGS);
|
|
166
|
+
|
|
160
167
|
// validate if config file provided exists or not when cypress_config_file provided
|
|
161
168
|
// validate the cypressProjectDir key otherwise.
|
|
162
169
|
let cypressConfigFilePath = bsConfig.run_settings.cypressConfigFilePath;
|
|
@@ -10,16 +10,19 @@ const crypto = require('crypto'),
|
|
|
10
10
|
utils = require('./utils');
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
const checkSpecsMd5 = (runSettings,
|
|
13
|
+
const checkSpecsMd5 = (runSettings, args, instrumentBlocks) => {
|
|
14
14
|
return new Promise(function (resolve, reject) {
|
|
15
|
+
if (args["force-upload"]) {
|
|
16
|
+
return resolve("force-upload");
|
|
17
|
+
}
|
|
15
18
|
let cypressFolderPath = path.dirname(runSettings.cypressConfigFilePath);
|
|
16
|
-
let ignoreFiles = utils.getFilesToIgnore(runSettings,
|
|
19
|
+
let ignoreFiles = utils.getFilesToIgnore(runSettings, args.exclude, false);
|
|
17
20
|
let options = {
|
|
18
21
|
cwd: cypressFolderPath,
|
|
19
22
|
ignore: ignoreFiles,
|
|
20
23
|
pattern: `**/*.+(${Constants.allowedFileTypes.join("|")})`
|
|
21
24
|
};
|
|
22
|
-
hashHelper.hashWrapper(options).then(function (data) {
|
|
25
|
+
hashHelper.hashWrapper(options, instrumentBlocks).then(function (data) {
|
|
23
26
|
const outputHash = crypto.createHash(Constants.hashingOptions.algo);
|
|
24
27
|
outputHash.update(data);
|
|
25
28
|
outputHash.update(checkPackageMd5(runSettings));
|
|
@@ -45,12 +48,12 @@ const checkPackageMd5 = (runSettings) => {
|
|
|
45
48
|
const outputHash = crypto.createHash(Constants.hashingOptions.algo);
|
|
46
49
|
let packageJSON = {};
|
|
47
50
|
if (typeof runSettings.package_config_options === 'object') {
|
|
48
|
-
Object.assign(packageJSON, runSettings.package_config_options);
|
|
51
|
+
Object.assign(packageJSON, utils.sortJsonKeys(runSettings.package_config_options));
|
|
49
52
|
}
|
|
50
53
|
|
|
51
54
|
if (typeof runSettings.npm_dependencies === 'object') {
|
|
52
55
|
Object.assign(packageJSON, {
|
|
53
|
-
devDependencies: runSettings.npm_dependencies,
|
|
56
|
+
devDependencies: utils.sortJsonKeys(runSettings.npm_dependencies),
|
|
54
57
|
});
|
|
55
58
|
}
|
|
56
59
|
|
|
@@ -58,22 +61,41 @@ const checkPackageMd5 = (runSettings) => {
|
|
|
58
61
|
let packageJSONString = JSON.stringify(packageJSON);
|
|
59
62
|
outputHash.update(packageJSONString);
|
|
60
63
|
}
|
|
64
|
+
let cypressFolderPath = path.dirname(runSettings.cypressConfigFilePath);
|
|
65
|
+
let sourceNpmrc = path.join(cypressFolderPath, ".npmrc");
|
|
66
|
+
if (fs.existsSync(sourceNpmrc)) {
|
|
67
|
+
const npmrc = fs.readFileSync(sourceNpmrc, {encoding:'utf8', flag:'r'});
|
|
68
|
+
outputHash.update(npmrc);
|
|
69
|
+
}
|
|
61
70
|
|
|
62
71
|
return outputHash.digest(Constants.hashingOptions.encoding)
|
|
63
72
|
};
|
|
64
73
|
|
|
65
|
-
const checkUploadedMd5 = (bsConfig, args) => {
|
|
74
|
+
const checkUploadedMd5 = (bsConfig, args, instrumentBlocks) => {
|
|
66
75
|
return new Promise(function (resolve) {
|
|
67
76
|
let obj = {
|
|
68
77
|
zipUrlPresent: false,
|
|
78
|
+
packageUrlPresent: false,
|
|
69
79
|
};
|
|
70
|
-
if (args["force-upload"]) {
|
|
80
|
+
if (args["force-upload"] && !utils.isTrueString(bsConfig.run_settings.cache_dependencies)) {
|
|
71
81
|
return resolve(obj);
|
|
72
82
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
83
|
+
|
|
84
|
+
instrumentBlocks.markBlockStart("checkAlreadyUploaded.md5Total");
|
|
85
|
+
checkSpecsMd5(bsConfig.run_settings, args, instrumentBlocks).then(function (zip_md5sum) {
|
|
86
|
+
instrumentBlocks.markBlockStart("checkAlreadyUploaded.md5Package");
|
|
87
|
+
let npm_package_md5sum = checkPackageMd5(bsConfig.run_settings);
|
|
88
|
+
instrumentBlocks.markBlockEnd("checkAlreadyUploaded.md5Package");
|
|
89
|
+
instrumentBlocks.markBlockEnd("checkAlreadyUploaded.md5Total");
|
|
90
|
+
let data = {};
|
|
91
|
+
if (!args["force-upload"]) {
|
|
92
|
+
Object.assign(data, { zip_md5sum });
|
|
93
|
+
Object.assign(obj, { zip_md5sum });
|
|
94
|
+
}
|
|
95
|
+
if (utils.isTrueString(bsConfig.run_settings.cache_dependencies)) {
|
|
96
|
+
Object.assign(data, { npm_package_md5sum });
|
|
97
|
+
Object.assign(obj, { npm_package_md5sum });
|
|
98
|
+
}
|
|
77
99
|
|
|
78
100
|
let options = {
|
|
79
101
|
url: config.checkMd5sum,
|
|
@@ -85,11 +107,13 @@ const checkUploadedMd5 = (bsConfig, args) => {
|
|
|
85
107
|
'Content-Type': 'application/json',
|
|
86
108
|
"User-Agent": utils.getUserAgent(),
|
|
87
109
|
},
|
|
88
|
-
body: data
|
|
110
|
+
body: JSON.stringify(data)
|
|
89
111
|
};
|
|
90
112
|
|
|
113
|
+
instrumentBlocks.markBlockStart("checkAlreadyUploaded.railsCheck");
|
|
91
114
|
request.post(options, function (err, resp, body) {
|
|
92
115
|
if (err) {
|
|
116
|
+
instrumentBlocks.markBlockEnd("checkAlreadyUploaded.railsCheck");
|
|
93
117
|
resolve(obj);
|
|
94
118
|
} else {
|
|
95
119
|
let zipData = null;
|
|
@@ -98,14 +122,31 @@ const checkUploadedMd5 = (bsConfig, args) => {
|
|
|
98
122
|
} catch (error) {
|
|
99
123
|
zipData = {};
|
|
100
124
|
}
|
|
101
|
-
if (resp.statusCode === 200
|
|
102
|
-
|
|
125
|
+
if (resp.statusCode === 200) {
|
|
126
|
+
if (!utils.isUndefined(zipData.zipUrl)) {
|
|
127
|
+
Object.assign(obj, zipData, {zipUrlPresent: true});
|
|
128
|
+
}
|
|
129
|
+
if (!utils.isUndefined(zipData.npmPackageUrl)) {
|
|
130
|
+
Object.assign(obj, zipData, {packageUrlPresent: true});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (utils.isTrueString(zipData.disableNpmSuiteCache)) {
|
|
134
|
+
bsConfig.run_settings.cache_dependencies = false;
|
|
135
|
+
Object.assign(obj, {packageUrlPresent: false});
|
|
136
|
+
delete obj.npm_package_md5sum;
|
|
137
|
+
}
|
|
138
|
+
if (utils.isTrueString(zipData.disableTestSuiteCache)) {
|
|
139
|
+
args["force-upload"] = true;
|
|
140
|
+
Object.assign(obj, {zipUrlPresent: false});
|
|
141
|
+
delete obj.zip_md5sum;
|
|
103
142
|
}
|
|
143
|
+
instrumentBlocks.markBlockEnd("checkAlreadyUploaded.railsCheck");
|
|
104
144
|
resolve(obj);
|
|
105
145
|
}
|
|
106
146
|
});
|
|
107
|
-
}).catch((
|
|
108
|
-
|
|
147
|
+
}).catch((err) => {
|
|
148
|
+
let errString = err.stack ? err.stack.toString().substring(0,100) : err.toString().substring(0,100);
|
|
149
|
+
resolve({zipUrlPresent: false, packageUrlPresent: false, error: errString});
|
|
109
150
|
});
|
|
110
151
|
});
|
|
111
152
|
};
|
package/bin/helpers/config.js
CHANGED
|
@@ -17,6 +17,8 @@ config.buildUrl = `${config.cypress_v1}/builds/`;
|
|
|
17
17
|
config.buildStopUrl = `${config.cypress_v1}/builds/stop/`;
|
|
18
18
|
config.checkMd5sum = `${config.cypress_v1}/md5sumcheck/`;
|
|
19
19
|
config.fileName = "tests.zip";
|
|
20
|
+
config.packageFileName = "bstackPackages.tar.gz";
|
|
21
|
+
config.packageDirName = "tmpBstackPackages";
|
|
20
22
|
config.retries = 5;
|
|
21
23
|
config.networkErrorExitCode = 2;
|
|
22
24
|
|
package/bin/helpers/constants.js
CHANGED
|
@@ -5,7 +5,9 @@ const syncCLI = {
|
|
|
5
5
|
LOGS: {
|
|
6
6
|
INIT_LOG: "All tests:"
|
|
7
7
|
},
|
|
8
|
-
INITIAL_DELAY_MULTIPLIER: 10
|
|
8
|
+
INITIAL_DELAY_MULTIPLIER: 10,
|
|
9
|
+
DEFAULT_LINE_SEP: "\n--------------------------------------------------------------------------------",
|
|
10
|
+
STARTUP_MESSAGE: "BrowserStack machines are now setting up Cypress with the specified npm dependencies for running your tests. It might take some time before your tests start runnning and showing up below..."
|
|
9
11
|
};
|
|
10
12
|
|
|
11
13
|
const userMessages = {
|
|
@@ -24,8 +26,12 @@ const userMessages = {
|
|
|
24
26
|
MD5_CHECK_FAILED: "There was some issue while checking if zip is already uploaded.",
|
|
25
27
|
ZIP_DELETE_FAILED: "Could not delete tests.zip successfully.",
|
|
26
28
|
ZIP_DELETED: "Deleted tests.zip successfully.",
|
|
29
|
+
NPM_INSTALL_AND_UPLOAD: "Installing required dependencies and building the package to upload to BrowserStack",
|
|
30
|
+
NPM_DELETE_FAILED: "Could not delete the dependency packages.",
|
|
31
|
+
NPM_DELETED: "Deleted dependency packages successfully.",
|
|
27
32
|
API_DEPRECATED: "This version of API is deprecated, please use latest version of API.",
|
|
28
33
|
FAILED_TO_ZIP: "Failed to zip files.",
|
|
34
|
+
FAILED_CREATE_NPM_ARCHIVE: "CLI execution failed due to some issue in npm setup. Please retry.",
|
|
29
35
|
FAILED_MD5_CHECK: "Something went wrong - you can retry running browserstack-cypress with ‘--force-upload’ parameter, or contact BrowserStack Support.",
|
|
30
36
|
VISIT_DASHBOARD: "Visit the Automate dashboard for real-time test reporting:",
|
|
31
37
|
CONFLICTING_INIT_ARGUMENTS: "Conflicting arguments given. You can use --path only with a file name, and not with a file path.",
|
|
@@ -34,18 +40,27 @@ const userMessages = {
|
|
|
34
40
|
NO_NPM_DEPENDENCIES_READ_MORE: "Read more about npm dependencies here: https://www.browserstack.com/docs/automate/cypress/npm-packages. You can suppress this warning by using --disable-npm-warning flag.",
|
|
35
41
|
VALIDATING_CONFIG: "Validating the config",
|
|
36
42
|
UPLOADING_TESTS: "Uploading the tests to BrowserStack",
|
|
43
|
+
UPLOADING_TESTS_SUCCESS: "Uploaded tests successfully",
|
|
44
|
+
UPLOADING_NPM_PACKAGES: "Uploading required node_modules to BrowserStack",
|
|
45
|
+
UPLOADING_NPM_PACKAGES_SUCCESS: "Uploaded node_modules successfully",
|
|
46
|
+
SKIP_UPLOADING_TESTS: "Skipping zip upload since BrowserStack already has your test suite that has not changed since the last run.",
|
|
47
|
+
SKIP_UPLOADING_NPM_PACKAGES: "Skipping the upload of node_modules since BrowserStack has already cached your npm dependencies that have not changed since the last run.",
|
|
37
48
|
LOCAL_TRUE: "you will now be able to test localhost / private URLs",
|
|
38
49
|
LOCAL_FALSE: "you won't be able to test localhost / private URLs",
|
|
39
50
|
EXIT_SYNC_CLI_MESSAGE: "Exiting the CLI, but your build is still running. You can use the --sync option to keep getting test updates. You can also use the build-info <build-id> command now.",
|
|
40
51
|
FATAL_NETWORK_ERROR: `fatal: unable to access '${config.buildUrl}': Could not resolve host: ${config.rails_host}`,
|
|
41
52
|
RETRY_LIMIT_EXCEEDED: `Max retries exceeded trying to connect to the host (retries: ${config.retries})`,
|
|
42
53
|
CHECK_DASHBOARD_AT: "Please check the build status at: ",
|
|
43
|
-
CYPRESS_VERSION_CHANGED: "Your build will run using Cypress <actualVersion> instead of Cypress <preferredVersion
|
|
54
|
+
CYPRESS_VERSION_CHANGED: "Your build will run using Cypress <actualVersion> instead of Cypress <preferredVersion>.<frameworkUpgradeMessage> Read more about supported versions here: http://browserstack.com/docs/automate/cypress/supported-versions",
|
|
44
55
|
LOCAL_START_FAILED: "Local Testing setup failed.",
|
|
45
56
|
LOCAL_STOP_FAILED: "Local Binary stop failed.",
|
|
46
57
|
INVALID_LOCAL_MODE_WARNING: "Invalid value specified for local_mode. local_mode: (\"always-on\" | \"on-demand\"). For more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference",
|
|
47
58
|
SPEC_LIMIT_WARNING: "You might not see all your results on the dashboard because of high spec count, please consider reducing the number of spec files in this folder.",
|
|
48
|
-
|
|
59
|
+
DOWNLOAD_BUILD_ARTIFACTS_FAILED: "Downloading build artifacts for the build <build-id> failed for <machine-count> machines.",
|
|
60
|
+
ASYNC_DOWNLOADS: "Test artifacts as specified under 'downloads' can be downloaded after the build has completed its run, using 'browserstack-cypress generate-downloads <build-id>'",
|
|
61
|
+
DOWNLOAD_BUILD_ARTIFACTS_SUCCESS: "Your build artifact(s) have been successfully downloaded in '<user-path>/build_artifacts/<build-id>' directory",
|
|
62
|
+
LATEST_SYNTAX_TO_ACTUAL_VERSION_MESSAGE: "Your build will run using Cypress <actualVersion> as you had specified <latestSyntaxVersion>.<frameworkUpgradeMessage> Read more about supported versions here: http://browserstack.com/docs/automate/cypress/supported-versions",
|
|
63
|
+
PROCESS_KILL_MESSAGE: "Stopping the CLI and the execution of the build on BrowserStack",
|
|
49
64
|
};
|
|
50
65
|
|
|
51
66
|
const validationMessages = {
|
|
@@ -69,7 +84,9 @@ const validationMessages = {
|
|
|
69
84
|
INVALID_CLI_LOCAL_IDENTIFIER: "When using --local-identifier, a value needs to be supplied. \n--local-identifier <String>.\nFor more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference",
|
|
70
85
|
INVALID_LOCAL_MODE: "When using --local-mode, a value needs to be supplied. \n--local-mode (\"always-on\" | \"on-demand\").\nFor more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference",
|
|
71
86
|
INVALID_LOCAL_CONFIG_FILE: "Using --local-config-file requires an input of the form /path/to/config-file.yml.\nFor more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference",
|
|
72
|
-
INVALID_LOCAL_IDENTIFIER: "Invalid value specified for local_identifier. For more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference"
|
|
87
|
+
INVALID_LOCAL_IDENTIFIER: "Invalid value specified for local_identifier. For more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference",
|
|
88
|
+
INVALID_BROWSER_ARGS: "Aborting as an unacceptable value was passed for --browser. Read more at https://www.browserstack.com/docs/automate/cypress/cli-reference",
|
|
89
|
+
INVALID_LOCAL_ASYNC_ARGS: "Cannot run in --async mode when local is set to true. Please run the build after removing --async",
|
|
73
90
|
};
|
|
74
91
|
|
|
75
92
|
const cliMessages = {
|
|
@@ -86,17 +103,13 @@ const cliMessages = {
|
|
|
86
103
|
INFO: "Check status of your build.",
|
|
87
104
|
STOP: "Stop your build.",
|
|
88
105
|
DEMAND: "Requires a build id.",
|
|
89
|
-
DESC: "Path to BrowserStack config",
|
|
90
|
-
CONFIG_DEMAND: "config file is required",
|
|
91
106
|
INFO_MESSAGE: "Getting information for buildId ",
|
|
92
107
|
STOP_MESSAGE: "Stopping build with given buildId ",
|
|
93
108
|
},
|
|
94
109
|
RUN: {
|
|
95
110
|
PARALLEL_DESC: "The maximum number of parallels to use to run your test suite",
|
|
96
|
-
INFO: "Run your tests on BrowserStack.",
|
|
97
|
-
DESC: "Path to BrowserStack config",
|
|
111
|
+
INFO: "Run your tests on BrowserStack. For more help: `browserstack-cypress run --help`.",
|
|
98
112
|
CYPRESS_DESC: "Path to Cypress config file",
|
|
99
|
-
CONFIG_DEMAND: "config file is required",
|
|
100
113
|
CYPRESS_CONFIG_DEMAND: "Cypress config file is required",
|
|
101
114
|
BUILD_NAME: "The build name you want to use to name your test runs",
|
|
102
115
|
EXCLUDE: "Exclude files matching a pattern from zipping and uploading",
|
|
@@ -104,13 +117,18 @@ const cliMessages = {
|
|
|
104
117
|
SPECS_DESCRIPTION: "Specify the spec files to run",
|
|
105
118
|
ENV_DESCRIPTION: "Specify the environment variables for your spec files",
|
|
106
119
|
SYNC_DESCRIPTION: "Makes the run command in sync",
|
|
120
|
+
ASYNC_DESCRIPTION: "Makes the run command in async",
|
|
107
121
|
BUILD_REPORT_MESSAGE: "See the entire build report here",
|
|
108
122
|
HEADED: "Run your tests in a headed browser instead of a headless browser",
|
|
109
123
|
LOCAL: "Accepted values: (true | false) - create a local testing connection to let you test staging and localhost websites, or sites behind proxies; learn more at browserstack.com/local-testing",
|
|
110
124
|
LOCAL_MODE: 'Accepted values: ("always-on" | "on-demand") - if you choose to keep the binary "always-on", it will speed up your tests by keeping the Local connection warmed up in the background; otherwise, you can choose to have it spawn and killed for every build',
|
|
111
125
|
LOCAL_IDENTIFIER: "Accepted values: String - assign an identifier to your Local process instance",
|
|
112
126
|
LOCAL_CONFIG_FILE: "Accepted values: String - path to local config-file to your Local process instance. Learn more at https://www.browserstack.com/local-testing/binary-params",
|
|
113
|
-
SYNC_NO_WRAP: "Wrap the spec names in --sync mode in case of smaller terminal window size pass --no-wrap"
|
|
127
|
+
SYNC_NO_WRAP: "Wrap the spec names in --sync mode in case of smaller terminal window size pass --no-wrap",
|
|
128
|
+
BROWSER_DESCRIPTION: "Specify the browsers you need to run your tests on.",
|
|
129
|
+
CONFIG_DESCRIPTION: "Set configuration values. Separate multiple values with a comma. The values set here override any values set in your configuration file.",
|
|
130
|
+
REPORTER: "Specify the custom reporter to use",
|
|
131
|
+
REPORTER_OPTIONS: "Specify reporter options for custom reporter",
|
|
114
132
|
},
|
|
115
133
|
COMMON: {
|
|
116
134
|
DISABLE_USAGE_REPORTING: "Disable usage reporting",
|
|
@@ -118,10 +136,15 @@ const cliMessages = {
|
|
|
118
136
|
USERNAME: "Your BrowserStack username",
|
|
119
137
|
ACCESS_KEY: "Your BrowserStack access key",
|
|
120
138
|
NO_NPM_WARNING: "No NPM warning if npm_dependencies is empty",
|
|
139
|
+
CONFIG_DEMAND: "config file is required",
|
|
140
|
+
CONFIG_FILE_PATH: "Path to BrowserStack config",
|
|
121
141
|
},
|
|
122
142
|
GENERATE_REPORT: {
|
|
123
143
|
INFO: "Generates the build report"
|
|
124
144
|
},
|
|
145
|
+
GENERATE_DOWNLOADS: {
|
|
146
|
+
INFO: "Downloads the build artifacts"
|
|
147
|
+
},
|
|
125
148
|
};
|
|
126
149
|
|
|
127
150
|
const messageTypes = {
|
|
@@ -133,7 +156,7 @@ const messageTypes = {
|
|
|
133
156
|
NULL: null
|
|
134
157
|
}
|
|
135
158
|
|
|
136
|
-
const allowedFileTypes = ['js', 'json', 'txt', 'ts', 'feature', 'features', 'pdf', 'jpg', 'jpeg', 'png', 'zip', 'npmrc', 'xml', 'doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx', 'jsx', 'coffee', 'cjsx', 'csv', 'tsv', 'yml', 'yaml', 'env'];
|
|
159
|
+
const allowedFileTypes = ['js', 'json', 'txt', 'ts', 'feature', 'features', 'pdf', 'jpg', 'jpeg', 'png', 'zip', 'npmrc', 'xml', 'doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx', 'jsx', 'coffee', 'cjsx', 'csv', 'tsv', 'yml', 'yaml', 'env', 'mov', 'mp4', 'mp3', 'wav'];
|
|
137
160
|
|
|
138
161
|
const filesToIgnoreWhileUploading = [
|
|
139
162
|
'**/node_modules/**',
|
|
@@ -146,7 +169,10 @@ const filesToIgnoreWhileUploading = [
|
|
|
146
169
|
'.idea/**',
|
|
147
170
|
'.vscode/**',
|
|
148
171
|
'.npm/**',
|
|
172
|
+
'bstackPackages.tar.gz',
|
|
173
|
+
'tmpBstackPackages/**',
|
|
149
174
|
'.yarn/**',
|
|
175
|
+
'build_artifacts/**'
|
|
150
176
|
];
|
|
151
177
|
|
|
152
178
|
const readDirOptions = {
|
|
@@ -164,6 +190,15 @@ const hashingOptions = {
|
|
|
164
190
|
encoding: 'hex',
|
|
165
191
|
};
|
|
166
192
|
|
|
193
|
+
const packageInstallerOptions = {
|
|
194
|
+
npmLoad: {
|
|
195
|
+
loglevel: 'silent',
|
|
196
|
+
only: 'dev',
|
|
197
|
+
'save-dev': true,
|
|
198
|
+
'only-dev': true,
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
167
202
|
const specFileTypes = ['js', 'ts', 'feature', 'jsx', 'coffee', 'cjsx'];
|
|
168
203
|
|
|
169
204
|
const DEFAULT_CYPRESS_SPEC_PATH = "cypress/integration"
|
|
@@ -171,8 +206,20 @@ const DEFAULT_CYPRESS_SPEC_PATH = "cypress/integration"
|
|
|
171
206
|
const SPEC_TOTAL_CHAR_LIMIT = 32243;
|
|
172
207
|
const METADATA_CHAR_BUFFER_PER_SPEC = 175;
|
|
173
208
|
|
|
209
|
+
const usageReportingConstants = {
|
|
210
|
+
GENERATE_DOWNLOADS: 'generate-downloads called',
|
|
211
|
+
}
|
|
212
|
+
|
|
174
213
|
const LATEST_VERSION_SYNTAX_REGEX = /\d*.latest(.\d*)?/gm
|
|
175
214
|
|
|
215
|
+
const AUTH_REGEX = /"auth" *: *{[\s\S]*?}/g
|
|
216
|
+
|
|
217
|
+
const ERROR_EXIT_CODE = 1;
|
|
218
|
+
|
|
219
|
+
const REDACTED = "[REDACTED]";
|
|
220
|
+
|
|
221
|
+
const REDACTED_AUTH =`auth: { "username": ${REDACTED}, "access_key": ${REDACTED} }`;
|
|
222
|
+
|
|
176
223
|
module.exports = Object.freeze({
|
|
177
224
|
syncCLI,
|
|
178
225
|
userMessages,
|
|
@@ -183,9 +230,14 @@ module.exports = Object.freeze({
|
|
|
183
230
|
filesToIgnoreWhileUploading,
|
|
184
231
|
readDirOptions,
|
|
185
232
|
hashingOptions,
|
|
233
|
+
packageInstallerOptions,
|
|
186
234
|
specFileTypes,
|
|
187
235
|
DEFAULT_CYPRESS_SPEC_PATH,
|
|
188
236
|
SPEC_TOTAL_CHAR_LIMIT,
|
|
189
237
|
METADATA_CHAR_BUFFER_PER_SPEC,
|
|
190
|
-
|
|
238
|
+
usageReportingConstants,
|
|
239
|
+
LATEST_VERSION_SYNTAX_REGEX,
|
|
240
|
+
ERROR_EXIT_CODE,
|
|
241
|
+
AUTH_REGEX,
|
|
242
|
+
REDACTED_AUTH
|
|
191
243
|
});
|
|
@@ -4,6 +4,7 @@ const fs = require('fs-extra'),
|
|
|
4
4
|
|
|
5
5
|
const logger = require('./logger').winstonLogger,
|
|
6
6
|
Constants = require('../helpers/constants'),
|
|
7
|
+
process = require('process'),
|
|
7
8
|
config = require('../helpers/config');
|
|
8
9
|
|
|
9
10
|
exports.write = function (f, message, args, cb) {
|
|
@@ -35,6 +36,19 @@ exports.deleteZip = () => {
|
|
|
35
36
|
}
|
|
36
37
|
};
|
|
37
38
|
|
|
39
|
+
exports.deletePackageArchieve = (logging = true) => {
|
|
40
|
+
try {
|
|
41
|
+
delete process.env.CYPRESS_INSTALL_BINARY;
|
|
42
|
+
fs.removeSync(config.packageFileName);
|
|
43
|
+
fs.removeSync(config.packageDirName);
|
|
44
|
+
if (logging) logger.info(Constants.userMessages.NPM_DELETED);
|
|
45
|
+
return 0;
|
|
46
|
+
} catch (err) {
|
|
47
|
+
if (logging) logger.info(Constants.userMessages.NPM_DELETE_FAILED);
|
|
48
|
+
return 1;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
38
52
|
exports.dirExists = function (filePath, cb) {
|
|
39
53
|
let exists = false;
|
|
40
54
|
if (fs.existsSync(path.dirname(filePath), cb)) {
|
package/bin/helpers/hashUtil.js
CHANGED
|
@@ -4,12 +4,16 @@ const glob = require('readdir-glob'),
|
|
|
4
4
|
crypto = require('crypto'),
|
|
5
5
|
fs = require('fs');
|
|
6
6
|
|
|
7
|
-
const hashWrapper = (options) => {
|
|
7
|
+
const hashWrapper = (options, instrumentBlocks) => {
|
|
8
|
+
instrumentBlocks.markBlockStart("checkAlreadyUploaded.md5Stats");
|
|
8
9
|
return folderStats(options).then((files) => {
|
|
10
|
+
instrumentBlocks.markBlockEnd("checkAlreadyUploaded.md5Stats");
|
|
11
|
+
instrumentBlocks.markBlockStart("checkAlreadyUploaded.md5Batch");
|
|
9
12
|
return batchHashFile(files);
|
|
10
13
|
}).then((hashes) => {
|
|
11
14
|
const combinedHash = crypto.createHash(Constants.hashingOptions.algo);
|
|
12
15
|
hashes.forEach((hash) => combinedHash.update(hash));
|
|
16
|
+
instrumentBlocks.markBlockEnd("checkAlreadyUploaded.md5Batch");
|
|
13
17
|
return combinedHash.digest(Constants.hashingOptions.encoding);
|
|
14
18
|
});
|
|
15
19
|
}
|