browserstack-cypress-cli 1.8.0 → 1.11.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/.nyc_output/4a952689-f098-4108-8a3e-26deb80519a8.json +1 -0
- package/.nyc_output/97ba506f-6310-4b5c-b0cf-54cdd82c7af6.json +1 -0
- package/.nyc_output/processinfo/4a952689-f098-4108-8a3e-26deb80519a8.json +1 -0
- package/.nyc_output/processinfo/97ba506f-6310-4b5c-b0cf-54cdd82c7af6.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -0
- package/bin/commands/generateDownloads.js +39 -0
- package/bin/commands/generateReport.js +1 -0
- package/bin/commands/info.js +1 -0
- package/bin/commands/runs.js +186 -60
- package/bin/commands/stop.js +3 -63
- package/bin/helpers/archiver.js +5 -20
- package/bin/helpers/buildArtifacts.js +220 -0
- package/bin/helpers/capabilityHelper.js +15 -22
- package/bin/helpers/checkUploaded.js +153 -0
- package/bin/helpers/config.js +3 -0
- package/bin/helpers/constants.js +98 -13
- package/bin/helpers/fileHelpers.js +14 -0
- package/bin/helpers/hashUtil.js +70 -0
- package/bin/helpers/packageInstaller.js +138 -0
- package/bin/helpers/reporterHTML.js +117 -9
- package/bin/helpers/sync/syncSpecsLogs.js +36 -8
- package/bin/helpers/timeComponents.js +71 -0
- package/bin/helpers/usageReporting.js +5 -4
- package/bin/helpers/utils.js +388 -9
- package/bin/helpers/zipUpload.js +42 -24
- package/bin/runner.js +108 -113
- package/package.json +6 -2
- package/test/test_files/dummy_bstack.json +0 -0
- package/test/test_files/dummy_bstack_2.json +0 -1
- package/test/test_files/dummy_bstack_3.json +0 -3
- package/test/unit/bin/commands/generateReport.js +0 -112
- package/test/unit/bin/commands/info.js +0 -374
- package/test/unit/bin/commands/init.js +0 -187
- package/test/unit/bin/commands/runs.js +0 -700
- package/test/unit/bin/commands/stop.js +0 -388
- package/test/unit/bin/helpers/archiver.js +0 -57
- package/test/unit/bin/helpers/build.js +0 -210
- package/test/unit/bin/helpers/capabilityHelper.js +0 -1049
- package/test/unit/bin/helpers/fileHelpers.js +0 -102
- package/test/unit/bin/helpers/reporterHTML.js +0 -272
- package/test/unit/bin/helpers/sync/failedSpecDetails.js +0 -76
- package/test/unit/bin/helpers/sync/specSummary.js +0 -55
- package/test/unit/bin/helpers/sync/syncSpecsLogs.js +0 -403
- package/test/unit/bin/helpers/usageReporting.js +0 -411
- package/test/unit/bin/helpers/utils.js +0 -1743
- package/test/unit/bin/helpers/zipUpload.js +0 -205
- package/test/unit/support/fixtures/testObjects.js +0 -149
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('fs'),
|
|
4
|
+
path = require('path');
|
|
5
|
+
|
|
6
|
+
const axios = require('axios'),
|
|
7
|
+
unzipper = require('unzipper');
|
|
8
|
+
|
|
9
|
+
const logger = require('./logger').winstonLogger,
|
|
10
|
+
utils = require("./utils"),
|
|
11
|
+
Constants = require("./constants"),
|
|
12
|
+
config = require("./config");
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
let BUILD_ARTIFACTS_TOTAL_COUNT = 0;
|
|
16
|
+
let BUILD_ARTIFACTS_FAIL_COUNT = 0;
|
|
17
|
+
|
|
18
|
+
const parseAndDownloadArtifacts = async (buildId, data) => {
|
|
19
|
+
return new Promise(async (resolve, reject) => {
|
|
20
|
+
let all_promises = [];
|
|
21
|
+
let combs = Object.keys(data);
|
|
22
|
+
for(let i = 0; i < combs.length; i++) {
|
|
23
|
+
let comb = combs[i];
|
|
24
|
+
let sessions = Object.keys(data[comb]);
|
|
25
|
+
for(let j = 0; j < sessions.length; j++) {
|
|
26
|
+
let sessionId = sessions[j];
|
|
27
|
+
let filePath = path.join('./', 'build_artifacts', buildId, comb, sessionId);
|
|
28
|
+
let fileName = 'build_artifacts.zip';
|
|
29
|
+
BUILD_ARTIFACTS_TOTAL_COUNT += 1;
|
|
30
|
+
all_promises.push(downloadAndUnzip(filePath, fileName, data[comb][sessionId]).catch((error) => {
|
|
31
|
+
BUILD_ARTIFACTS_FAIL_COUNT += 1;
|
|
32
|
+
// delete malformed zip if present
|
|
33
|
+
let tmpFilePath = path.join(filePath, fileName);
|
|
34
|
+
if(fs.existsSync(tmpFilePath)){
|
|
35
|
+
fs.unlinkSync(tmpFilePath);
|
|
36
|
+
}
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
await Promise.all(all_promises);
|
|
41
|
+
resolve();
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const createDirIfNotPresent = async (dir) => {
|
|
46
|
+
return new Promise((resolve) => {
|
|
47
|
+
if (!fs.existsSync(dir)){
|
|
48
|
+
fs.mkdirSync(dir);
|
|
49
|
+
}
|
|
50
|
+
resolve();
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const createDirectories = async (buildId, data) => {
|
|
55
|
+
// create dir for build_artifacts if not already present
|
|
56
|
+
let artifactsDir = path.join('./', 'build_artifacts');
|
|
57
|
+
if (!fs.existsSync(artifactsDir)){
|
|
58
|
+
fs.mkdirSync(artifactsDir);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// create dir for buildId if not already present
|
|
62
|
+
let buildDir = path.join('./', 'build_artifacts', buildId);
|
|
63
|
+
if (fs.existsSync(buildDir)){
|
|
64
|
+
// remove dir in case already exists
|
|
65
|
+
fs.rmdirSync(buildDir, { recursive: true, force: true });
|
|
66
|
+
}
|
|
67
|
+
fs.mkdirSync(buildDir);
|
|
68
|
+
|
|
69
|
+
let combDirs = [];
|
|
70
|
+
let sessionDirs = [];
|
|
71
|
+
let combs = Object.keys(data);
|
|
72
|
+
|
|
73
|
+
for(let i = 0; i < combs.length; i++) {
|
|
74
|
+
let comb = combs[i];
|
|
75
|
+
let combDir = path.join('./', 'build_artifacts', buildId, comb);
|
|
76
|
+
combDirs.push(createDirIfNotPresent(combDir));
|
|
77
|
+
let sessions = Object.keys(data[comb]);
|
|
78
|
+
for(let j = 0; j < sessions.length; j++) {
|
|
79
|
+
let sessionId = sessions[j];
|
|
80
|
+
let sessionDir = path.join('./', 'build_artifacts', buildId, comb, sessionId);
|
|
81
|
+
sessionDirs.push(createDirIfNotPresent(sessionDir));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return new Promise(async (resolve) => {
|
|
86
|
+
// create sub dirs for each combination in build
|
|
87
|
+
await Promise.all(combDirs);
|
|
88
|
+
// create sub dirs for each machine id in combination
|
|
89
|
+
await Promise.all(sessionDirs);
|
|
90
|
+
resolve();
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const downloadAndUnzip = async (filePath, fileName, url) => {
|
|
95
|
+
let tmpFilePath = path.join(filePath, fileName);
|
|
96
|
+
const writer = fs.createWriteStream(tmpFilePath);
|
|
97
|
+
|
|
98
|
+
return axios({
|
|
99
|
+
method: 'get',
|
|
100
|
+
url: url,
|
|
101
|
+
responseType: 'stream',
|
|
102
|
+
}).then(response => {
|
|
103
|
+
|
|
104
|
+
//ensure that the user can call `then()` only when the file has
|
|
105
|
+
//been downloaded entirely.
|
|
106
|
+
|
|
107
|
+
return new Promise(async (resolve, reject) => {
|
|
108
|
+
response.data.pipe(writer);
|
|
109
|
+
let error = null;
|
|
110
|
+
writer.on('error', err => {
|
|
111
|
+
error = err;
|
|
112
|
+
writer.close();
|
|
113
|
+
reject(err);
|
|
114
|
+
});
|
|
115
|
+
writer.on('close', async () => {
|
|
116
|
+
if (!error) {
|
|
117
|
+
await unzipFile(filePath, fileName);
|
|
118
|
+
fs.unlinkSync(tmpFilePath);
|
|
119
|
+
resolve(true);
|
|
120
|
+
}
|
|
121
|
+
//no need to call the reject here, as it will have been called in the
|
|
122
|
+
//'error' stream;
|
|
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) => {
|
|
138
|
+
let 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
|
+
try {
|
|
160
|
+
await axios.post(url, data, options);
|
|
161
|
+
} catch (err) {
|
|
162
|
+
utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'api_failed_build_artifacts_status_update');
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
exports.downloadBuildArtifacts = async (bsConfig, buildId, args) => {
|
|
167
|
+
BUILD_ARTIFACTS_FAIL_COUNT = 0;
|
|
168
|
+
BUILD_ARTIFACTS_TOTAL_COUNT = 0;
|
|
169
|
+
|
|
170
|
+
let url = `${config.buildUrl}${buildId}/build_artifacts`;
|
|
171
|
+
let options = {
|
|
172
|
+
auth: {
|
|
173
|
+
username: bsConfig.auth.username,
|
|
174
|
+
password: bsConfig.auth.access_key,
|
|
175
|
+
},
|
|
176
|
+
headers: {
|
|
177
|
+
'User-Agent': utils.getUserAgent(),
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
let message = null;
|
|
182
|
+
let messageType = null;
|
|
183
|
+
let errorCode = null;
|
|
184
|
+
|
|
185
|
+
try {
|
|
186
|
+
const res = await axios.get(url, options);
|
|
187
|
+
let buildDetails = res.data;
|
|
188
|
+
|
|
189
|
+
await createDirectories(buildId, buildDetails);
|
|
190
|
+
await parseAndDownloadArtifacts(buildId, buildDetails);
|
|
191
|
+
|
|
192
|
+
if (BUILD_ARTIFACTS_FAIL_COUNT > 0) {
|
|
193
|
+
messageType = Constants.messageTypes.ERROR;
|
|
194
|
+
message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_FAILED.replace('<build-id>', buildId).replace('<machine-count>', BUILD_ARTIFACTS_FAIL_COUNT);
|
|
195
|
+
logger.error(message);
|
|
196
|
+
process.exitCode = Constants.ERROR_EXIT_CODE;
|
|
197
|
+
} else {
|
|
198
|
+
messageType = Constants.messageTypes.SUCCESS;
|
|
199
|
+
message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_SUCCESS.replace('<build-id>', buildId).replace('<user-path>', process.cwd());
|
|
200
|
+
logger.info(message);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
await sendUpdatesToBstack(bsConfig, buildId, args, options);
|
|
204
|
+
utils.sendUsageReport(bsConfig, args, message, messageType, null);
|
|
205
|
+
} catch (err) {
|
|
206
|
+
messageType = Constants.messageTypes.ERROR;
|
|
207
|
+
errorCode = 'api_failed_build_artifacts';
|
|
208
|
+
|
|
209
|
+
if (BUILD_ARTIFACTS_FAIL_COUNT > 0) {
|
|
210
|
+
messageType = Constants.messageTypes.ERROR;
|
|
211
|
+
message = Constants.userMessages.DOWNLOAD_BUILD_ARTIFACTS_FAILED.replace('<build-id>', buildId).replace('<machine-count>', BUILD_ARTIFACTS_FAIL_COUNT);
|
|
212
|
+
logger.error(message);
|
|
213
|
+
} else {
|
|
214
|
+
logger.error('Downloading the build artifacts failed.');
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
utils.sendUsageReport(bsConfig, args, err, messageType, errorCode);
|
|
218
|
+
process.exitCode = Constants.ERROR_EXIT_CODE;
|
|
219
|
+
}
|
|
220
|
+
};
|
|
@@ -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) {
|
|
@@ -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) {
|
|
@@ -93,32 +98,18 @@ const caps = (bsConfig, zip) => {
|
|
|
93
98
|
obj.projectNotifyURL = null;
|
|
94
99
|
|
|
95
100
|
if (bsConfig.run_settings) {
|
|
96
|
-
obj.project = bsConfig.run_settings.project || bsConfig.run_settings.project_name;
|
|
97
|
-
obj.customBuildName = bsConfig.run_settings.build_name || bsConfig.run_settings.customBuildName;
|
|
101
|
+
obj.project = bsConfig.run_settings.project || bsConfig.run_settings.project_name || obj.project;
|
|
102
|
+
obj.customBuildName = bsConfig.run_settings.build_name || bsConfig.run_settings.customBuildName || obj.customBuildName;
|
|
98
103
|
obj.callbackURL = bsConfig.run_settings.callback_url;
|
|
99
104
|
obj.projectNotifyURL = bsConfig.run_settings.project_notify_URL;
|
|
100
105
|
obj.parallels = bsConfig.run_settings.parallels;
|
|
101
106
|
|
|
102
|
-
if (!Utils.isUndefined(bsConfig.run_settings.
|
|
103
|
-
obj.cypress_config_filename = bsConfig.run_settings.cypress_config_filename;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (!Utils.isUndefined(bsConfig.run_settings.specs)){
|
|
107
|
-
obj.specs = bsConfig.run_settings.specs;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (!Utils.isUndefined(bsConfig.run_settings.env)){
|
|
111
|
-
obj.env = bsConfig.run_settings.env;
|
|
112
|
-
}
|
|
113
|
-
if (!Utils.isUndefined(bsConfig.run_settings.cypress_version)){
|
|
114
|
-
obj.cypress_version = bsConfig.run_settings.cypress_version;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (!Utils.isUndefined(bsConfig.run_settings.headless) && String(bsConfig.run_settings.headless) === "false"){
|
|
118
|
-
obj.headless = bsConfig.run_settings.headless;
|
|
119
|
-
} else {
|
|
107
|
+
if (!(!Utils.isUndefined(bsConfig.run_settings.headless) && String(bsConfig.run_settings.headless) === "false")) {
|
|
120
108
|
logger.info(`Running your tests in headless mode. Use --headed arg to run in headful mode.`);
|
|
121
109
|
}
|
|
110
|
+
|
|
111
|
+
// send run_settings as is for other capabilities
|
|
112
|
+
obj.run_settings = JSON.stringify(bsConfig.run_settings);
|
|
122
113
|
}
|
|
123
114
|
|
|
124
115
|
if(obj.parallels === Constants.cliMessages.RUN.DEFAULT_PARALLEL_MESSAGE) obj.parallels = undefined
|
|
@@ -171,6 +162,8 @@ const validate = (bsConfig, args) => {
|
|
|
171
162
|
|
|
172
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);
|
|
173
164
|
|
|
165
|
+
if( Utils.searchForOption('--async') && ( !Utils.isUndefined(args.async) && bsConfig["connection_settings"]["local"])) reject(Constants.validationMessages.INVALID_LOCAL_ASYNC_ARGS);
|
|
166
|
+
|
|
174
167
|
// validate if config file provided exists or not when cypress_config_file provided
|
|
175
168
|
// validate the cypressProjectDir key otherwise.
|
|
176
169
|
let cypressConfigFilePath = bsConfig.run_settings.cypressConfigFilePath;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const request = require('request');
|
|
3
|
+
|
|
4
|
+
const crypto = require('crypto'),
|
|
5
|
+
Constants = require('./constants'),
|
|
6
|
+
hashHelper = require('./hashUtil'),
|
|
7
|
+
config = require('./config'),
|
|
8
|
+
path = require('path'),
|
|
9
|
+
fs = require("fs"),
|
|
10
|
+
utils = require('./utils');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
const checkSpecsMd5 = (runSettings, args, instrumentBlocks) => {
|
|
14
|
+
return new Promise(function (resolve, reject) {
|
|
15
|
+
if (args["force-upload"]) {
|
|
16
|
+
return resolve("force-upload");
|
|
17
|
+
}
|
|
18
|
+
let cypressFolderPath = path.dirname(runSettings.cypressConfigFilePath);
|
|
19
|
+
let ignoreFiles = utils.getFilesToIgnore(runSettings, args.exclude, false);
|
|
20
|
+
let options = {
|
|
21
|
+
cwd: cypressFolderPath,
|
|
22
|
+
ignore: ignoreFiles,
|
|
23
|
+
pattern: `**/*.+(${Constants.allowedFileTypes.join("|")})`
|
|
24
|
+
};
|
|
25
|
+
hashHelper.hashWrapper(options, instrumentBlocks).then(function (data) {
|
|
26
|
+
const outputHash = crypto.createHash(Constants.hashingOptions.algo);
|
|
27
|
+
outputHash.update(data);
|
|
28
|
+
outputHash.update(checkPackageMd5(runSettings));
|
|
29
|
+
|
|
30
|
+
if (
|
|
31
|
+
runSettings.cypress_config_file &&
|
|
32
|
+
runSettings.cypress_config_filename !== 'false'
|
|
33
|
+
) {
|
|
34
|
+
let cypressJSON = JSON.parse(
|
|
35
|
+
fs.readFileSync(runSettings.cypressConfigFilePath)
|
|
36
|
+
);
|
|
37
|
+
let cypressJSONString = JSON.stringify(cypressJSON);
|
|
38
|
+
outputHash.update(cypressJSONString);
|
|
39
|
+
}
|
|
40
|
+
resolve(outputHash.digest(Constants.hashingOptions.encoding));
|
|
41
|
+
}).catch(function (error) {
|
|
42
|
+
reject(error);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const checkPackageMd5 = (runSettings) => {
|
|
48
|
+
const outputHash = crypto.createHash(Constants.hashingOptions.algo);
|
|
49
|
+
let packageJSON = {};
|
|
50
|
+
if (typeof runSettings.package_config_options === 'object') {
|
|
51
|
+
Object.assign(packageJSON, utils.sortJsonKeys(runSettings.package_config_options));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (typeof runSettings.npm_dependencies === 'object') {
|
|
55
|
+
Object.assign(packageJSON, {
|
|
56
|
+
devDependencies: utils.sortJsonKeys(runSettings.npm_dependencies),
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (Object.keys(packageJSON).length > 0) {
|
|
61
|
+
let packageJSONString = JSON.stringify(packageJSON);
|
|
62
|
+
outputHash.update(packageJSONString);
|
|
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
|
+
}
|
|
70
|
+
|
|
71
|
+
return outputHash.digest(Constants.hashingOptions.encoding)
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const checkUploadedMd5 = (bsConfig, args, instrumentBlocks) => {
|
|
75
|
+
return new Promise(function (resolve) {
|
|
76
|
+
let obj = {
|
|
77
|
+
zipUrlPresent: false,
|
|
78
|
+
packageUrlPresent: false,
|
|
79
|
+
};
|
|
80
|
+
if (args["force-upload"] && !utils.isTrueString(bsConfig.run_settings.cache_dependencies)) {
|
|
81
|
+
return resolve(obj);
|
|
82
|
+
}
|
|
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
|
+
}
|
|
99
|
+
|
|
100
|
+
let options = {
|
|
101
|
+
url: config.checkMd5sum,
|
|
102
|
+
auth: {
|
|
103
|
+
user: bsConfig.auth.username,
|
|
104
|
+
password: bsConfig.auth.access_key
|
|
105
|
+
},
|
|
106
|
+
headers: {
|
|
107
|
+
'Content-Type': 'application/json',
|
|
108
|
+
"User-Agent": utils.getUserAgent(),
|
|
109
|
+
},
|
|
110
|
+
body: JSON.stringify(data)
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
instrumentBlocks.markBlockStart("checkAlreadyUploaded.railsCheck");
|
|
114
|
+
request.post(options, function (err, resp, body) {
|
|
115
|
+
if (err) {
|
|
116
|
+
instrumentBlocks.markBlockEnd("checkAlreadyUploaded.railsCheck");
|
|
117
|
+
resolve(obj);
|
|
118
|
+
} else {
|
|
119
|
+
let zipData = null;
|
|
120
|
+
try {
|
|
121
|
+
zipData = JSON.parse(body);
|
|
122
|
+
} catch (error) {
|
|
123
|
+
zipData = {};
|
|
124
|
+
}
|
|
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;
|
|
142
|
+
}
|
|
143
|
+
instrumentBlocks.markBlockEnd("checkAlreadyUploaded.railsCheck");
|
|
144
|
+
resolve(obj);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}).catch((err) => {
|
|
148
|
+
resolve({zipUrlPresent: false, packageUrlPresent: false, error: err.stack.substring(0,100)});
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
exports.checkUploadedMd5 = checkUploadedMd5;
|
package/bin/helpers/config.js
CHANGED
|
@@ -15,7 +15,10 @@ if(config.env !== "production") {
|
|
|
15
15
|
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
|
+
config.checkMd5sum = `${config.cypress_v1}/md5sumcheck/`;
|
|
18
19
|
config.fileName = "tests.zip";
|
|
20
|
+
config.packageFileName = "bstackPackages.tar.gz";
|
|
21
|
+
config.packageDirName = "tmpBstackPackages";
|
|
19
22
|
config.retries = 5;
|
|
20
23
|
config.networkErrorExitCode = 2;
|
|
21
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 = {
|
|
@@ -17,13 +19,19 @@ const userMessages = {
|
|
|
17
19
|
BUILD_REPORT_MESSAGE: "See the entire build report here:",
|
|
18
20
|
ZIP_UPLOADER_NOT_REACHABLE: "Could not reach BrowserStack APIs. Please check your network or see if you need to whitelist *.browserstack.com",
|
|
19
21
|
ZIP_UPLOAD_FAILED: "Zip Upload failed.",
|
|
22
|
+
ZIP_UPLOAD_LIMIT_EXCEEDED: "The directory size which contains the cypress config file is more than 200 MB. For more info, check out https://www.browserstack.com/docs/automate/cypress/exclude-files",
|
|
20
23
|
CONFIG_FILE_CREATED: "BrowserStack Config File created, you can now run browserstack-cypress --config-file run",
|
|
21
24
|
CONFIG_FILE_EXISTS: "File already exists, delete the browserstack.json file manually. skipping...",
|
|
22
25
|
DIR_NOT_FOUND: "Given path does not exist. Failed to create browserstack.json in %s",
|
|
26
|
+
MD5_CHECK_FAILED: "There was some issue while checking if zip is already uploaded.",
|
|
23
27
|
ZIP_DELETE_FAILED: "Could not delete tests.zip successfully.",
|
|
24
28
|
ZIP_DELETED: "Deleted tests.zip successfully.",
|
|
29
|
+
NPM_DELETE_FAILED: "Could not delete the dependency packages.",
|
|
30
|
+
NPM_DELETED: "Deleted dependency packages successfully.",
|
|
25
31
|
API_DEPRECATED: "This version of API is deprecated, please use latest version of API.",
|
|
26
32
|
FAILED_TO_ZIP: "Failed to zip files.",
|
|
33
|
+
FAILED_CREATE_NPM_ARCHIVE: "CLI execution failed due to some issue in npm setup. Please retry.",
|
|
34
|
+
FAILED_MD5_CHECK: "Something went wrong - you can retry running browserstack-cypress with ‘--force-upload’ parameter, or contact BrowserStack Support.",
|
|
27
35
|
VISIT_DASHBOARD: "Visit the Automate dashboard for real-time test reporting:",
|
|
28
36
|
CONFLICTING_INIT_ARGUMENTS: "Conflicting arguments given. You can use --path only with a file name, and not with a file path.",
|
|
29
37
|
NO_PARALLELS: "Your specs will run sequentially on a single machine. Read more about running your specs in parallel here: https://www.browserstack.com/docs/automate/cypress/run-tests-in-parallel",
|
|
@@ -31,16 +39,25 @@ const userMessages = {
|
|
|
31
39
|
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.",
|
|
32
40
|
VALIDATING_CONFIG: "Validating the config",
|
|
33
41
|
UPLOADING_TESTS: "Uploading the tests to BrowserStack",
|
|
42
|
+
UPLOADING_TESTS_SUCCESS: "Uploaded tests successfully",
|
|
43
|
+
UPLOADING_NPM_PACKAGES: "Uploading required node_modules to BrowserStack",
|
|
44
|
+
UPLOADING_NPM_PACKAGES_SUCCESS: "Uploaded node_modules successfully",
|
|
34
45
|
LOCAL_TRUE: "you will now be able to test localhost / private URLs",
|
|
35
46
|
LOCAL_FALSE: "you won't be able to test localhost / private URLs",
|
|
36
47
|
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.",
|
|
37
48
|
FATAL_NETWORK_ERROR: `fatal: unable to access '${config.buildUrl}': Could not resolve host: ${config.rails_host}`,
|
|
38
49
|
RETRY_LIMIT_EXCEEDED: `Max retries exceeded trying to connect to the host (retries: ${config.retries})`,
|
|
39
50
|
CHECK_DASHBOARD_AT: "Please check the build status at: ",
|
|
40
|
-
CYPRESS_VERSION_CHANGED: "Your build will run using Cypress <actualVersion> instead of Cypress <preferredVersion
|
|
51
|
+
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",
|
|
41
52
|
LOCAL_START_FAILED: "Local Testing setup failed.",
|
|
42
53
|
LOCAL_STOP_FAILED: "Local Binary stop failed.",
|
|
43
|
-
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"
|
|
54
|
+
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",
|
|
55
|
+
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.",
|
|
56
|
+
DOWNLOAD_BUILD_ARTIFACTS_FAILED: "Downloading build artifacts for the build <build-id> failed for <machine-count> machines.",
|
|
57
|
+
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>'",
|
|
58
|
+
DOWNLOAD_BUILD_ARTIFACTS_SUCCESS: "Your build artifact(s) have been successfully downloaded in '<user-path>/build_artifacts/<build-id>' directory",
|
|
59
|
+
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",
|
|
60
|
+
PROCESS_KILL_MESSAGE: "Stopping the CLI and the execution of the build on BrowserStack",
|
|
44
61
|
};
|
|
45
62
|
|
|
46
63
|
const validationMessages = {
|
|
@@ -64,7 +81,9 @@ const validationMessages = {
|
|
|
64
81
|
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",
|
|
65
82
|
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",
|
|
66
83
|
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",
|
|
67
|
-
INVALID_LOCAL_IDENTIFIER: "Invalid value specified for local_identifier. For more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference"
|
|
84
|
+
INVALID_LOCAL_IDENTIFIER: "Invalid value specified for local_identifier. For more info, check out https://www.browserstack.com/docs/automate/cypress/cli-reference",
|
|
85
|
+
INVALID_BROWSER_ARGS: "Aborting as an unacceptable value was passed for --browser. Read more at https://www.browserstack.com/docs/automate/cypress/cli-reference",
|
|
86
|
+
INVALID_LOCAL_ASYNC_ARGS: "Cannot run in --async mode when local is set to true. Please run the build after removing --async",
|
|
68
87
|
};
|
|
69
88
|
|
|
70
89
|
const cliMessages = {
|
|
@@ -81,17 +100,13 @@ const cliMessages = {
|
|
|
81
100
|
INFO: "Check status of your build.",
|
|
82
101
|
STOP: "Stop your build.",
|
|
83
102
|
DEMAND: "Requires a build id.",
|
|
84
|
-
DESC: "Path to BrowserStack config",
|
|
85
|
-
CONFIG_DEMAND: "config file is required",
|
|
86
103
|
INFO_MESSAGE: "Getting information for buildId ",
|
|
87
104
|
STOP_MESSAGE: "Stopping build with given buildId ",
|
|
88
105
|
},
|
|
89
106
|
RUN: {
|
|
90
107
|
PARALLEL_DESC: "The maximum number of parallels to use to run your test suite",
|
|
91
|
-
INFO: "Run your tests on BrowserStack.",
|
|
92
|
-
DESC: "Path to BrowserStack config",
|
|
108
|
+
INFO: "Run your tests on BrowserStack. For more help: `browserstack-cypress run --help`.",
|
|
93
109
|
CYPRESS_DESC: "Path to Cypress config file",
|
|
94
|
-
CONFIG_DEMAND: "config file is required",
|
|
95
110
|
CYPRESS_CONFIG_DEMAND: "Cypress config file is required",
|
|
96
111
|
BUILD_NAME: "The build name you want to use to name your test runs",
|
|
97
112
|
EXCLUDE: "Exclude files matching a pattern from zipping and uploading",
|
|
@@ -99,22 +114,34 @@ const cliMessages = {
|
|
|
99
114
|
SPECS_DESCRIPTION: "Specify the spec files to run",
|
|
100
115
|
ENV_DESCRIPTION: "Specify the environment variables for your spec files",
|
|
101
116
|
SYNC_DESCRIPTION: "Makes the run command in sync",
|
|
117
|
+
ASYNC_DESCRIPTION: "Makes the run command in async",
|
|
102
118
|
BUILD_REPORT_MESSAGE: "See the entire build report here",
|
|
103
119
|
HEADED: "Run your tests in a headed browser instead of a headless browser",
|
|
104
120
|
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",
|
|
105
121
|
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',
|
|
106
122
|
LOCAL_IDENTIFIER: "Accepted values: String - assign an identifier to your Local process instance",
|
|
107
|
-
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"
|
|
123
|
+
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",
|
|
124
|
+
SYNC_NO_WRAP: "Wrap the spec names in --sync mode in case of smaller terminal window size pass --no-wrap",
|
|
125
|
+
BROWSER_DESCRIPTION: "Specify the browsers you need to run your tests on.",
|
|
126
|
+
CONFIG_DESCRIPTION: "Set configuration values. Separate multiple values with a comma. The values set here override any values set in your configuration file.",
|
|
127
|
+
REPORTER: "Specify the custom reporter to use",
|
|
128
|
+
REPORTER_OPTIONS: "Specify reporter options for custom reporter",
|
|
108
129
|
},
|
|
109
130
|
COMMON: {
|
|
110
131
|
DISABLE_USAGE_REPORTING: "Disable usage reporting",
|
|
132
|
+
FORCE_UPLOAD: "Force the upload of your test files even if BrowserStack has detected no changes in your suite since you last ran",
|
|
111
133
|
USERNAME: "Your BrowserStack username",
|
|
112
134
|
ACCESS_KEY: "Your BrowserStack access key",
|
|
113
135
|
NO_NPM_WARNING: "No NPM warning if npm_dependencies is empty",
|
|
136
|
+
CONFIG_DEMAND: "config file is required",
|
|
137
|
+
CONFIG_FILE_PATH: "Path to BrowserStack config",
|
|
114
138
|
},
|
|
115
139
|
GENERATE_REPORT: {
|
|
116
140
|
INFO: "Generates the build report"
|
|
117
141
|
},
|
|
142
|
+
GENERATE_DOWNLOADS: {
|
|
143
|
+
INFO: "Downloads the build artifacts"
|
|
144
|
+
},
|
|
118
145
|
};
|
|
119
146
|
|
|
120
147
|
const messageTypes = {
|
|
@@ -126,14 +153,64 @@ const messageTypes = {
|
|
|
126
153
|
NULL: null
|
|
127
154
|
}
|
|
128
155
|
|
|
129
|
-
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'];
|
|
156
|
+
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'];
|
|
130
157
|
|
|
131
|
-
const filesToIgnoreWhileUploading = [
|
|
158
|
+
const filesToIgnoreWhileUploading = [
|
|
159
|
+
'**/node_modules/**',
|
|
160
|
+
'node_modules/**',
|
|
161
|
+
'package-lock.json',
|
|
162
|
+
'package.json',
|
|
163
|
+
'browserstack-package.json',
|
|
164
|
+
'tests.zip',
|
|
165
|
+
'cypress.json',
|
|
166
|
+
'.idea/**',
|
|
167
|
+
'.vscode/**',
|
|
168
|
+
'.npm/**',
|
|
169
|
+
'bstackPackages.tar.gz',
|
|
170
|
+
'tmpBstackPackages/**',
|
|
171
|
+
'.yarn/**',
|
|
172
|
+
'build_artifacts/**'
|
|
173
|
+
];
|
|
174
|
+
|
|
175
|
+
const readDirOptions = {
|
|
176
|
+
cwd: '.',
|
|
177
|
+
matchBase: true,
|
|
178
|
+
ignore: [],
|
|
179
|
+
dot: true,
|
|
180
|
+
stat: true,
|
|
181
|
+
pattern: ''
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const hashingOptions = {
|
|
185
|
+
parallel: 10,
|
|
186
|
+
algo: 'md5',
|
|
187
|
+
encoding: 'hex',
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const packageInstallerOptions = {
|
|
191
|
+
npmLoad: {
|
|
192
|
+
loglevel: 'silent',
|
|
193
|
+
only: 'dev',
|
|
194
|
+
'save-dev': true,
|
|
195
|
+
'only-dev': true,
|
|
196
|
+
}
|
|
197
|
+
}
|
|
132
198
|
|
|
133
199
|
const specFileTypes = ['js', 'ts', 'feature', 'jsx', 'coffee', 'cjsx'];
|
|
134
200
|
|
|
135
201
|
const DEFAULT_CYPRESS_SPEC_PATH = "cypress/integration"
|
|
136
202
|
|
|
203
|
+
const SPEC_TOTAL_CHAR_LIMIT = 32243;
|
|
204
|
+
const METADATA_CHAR_BUFFER_PER_SPEC = 175;
|
|
205
|
+
|
|
206
|
+
const usageReportingConstants = {
|
|
207
|
+
GENERATE_DOWNLOADS: 'generate-downloads called',
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const LATEST_VERSION_SYNTAX_REGEX = /\d*.latest(.\d*)?/gm
|
|
211
|
+
|
|
212
|
+
const ERROR_EXIT_CODE = 1;
|
|
213
|
+
|
|
137
214
|
module.exports = Object.freeze({
|
|
138
215
|
syncCLI,
|
|
139
216
|
userMessages,
|
|
@@ -142,6 +219,14 @@ module.exports = Object.freeze({
|
|
|
142
219
|
messageTypes,
|
|
143
220
|
allowedFileTypes,
|
|
144
221
|
filesToIgnoreWhileUploading,
|
|
222
|
+
readDirOptions,
|
|
223
|
+
hashingOptions,
|
|
224
|
+
packageInstallerOptions,
|
|
145
225
|
specFileTypes,
|
|
146
|
-
DEFAULT_CYPRESS_SPEC_PATH
|
|
226
|
+
DEFAULT_CYPRESS_SPEC_PATH,
|
|
227
|
+
SPEC_TOTAL_CHAR_LIMIT,
|
|
228
|
+
METADATA_CHAR_BUFFER_PER_SPEC,
|
|
229
|
+
usageReportingConstants,
|
|
230
|
+
LATEST_VERSION_SYNTAX_REGEX,
|
|
231
|
+
ERROR_EXIT_CODE
|
|
147
232
|
});
|