browserstack-cypress-cli 1.8.1 → 1.11.1
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 +227 -64
- package/bin/commands/stop.js +5 -65
- package/bin/helpers/archiver.js +5 -20
- package/bin/helpers/buildArtifacts.js +250 -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 +109 -13
- package/bin/helpers/fileHelpers.js +14 -0
- package/bin/helpers/hashUtil.js +70 -0
- package/bin/helpers/packageInstaller.js +134 -0
- package/bin/helpers/reporterHTML.js +169 -11
- package/bin/helpers/sync/syncSpecsLogs.js +37 -9
- package/bin/helpers/timeComponents.js +71 -0
- package/bin/helpers/usageReporting.js +35 -6
- package/bin/helpers/utils.js +420 -12
- package/bin/helpers/zipUpload.js +106 -27
- package/bin/runner.js +119 -118
- package/package.json +4 -1
- 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 -1770
- package/test/unit/bin/helpers/zipUpload.js +0 -205
- package/test/unit/support/fixtures/testObjects.js +0 -149
|
@@ -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) {
|
|
@@ -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
|
|