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
|
@@ -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)) {
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const glob = require('readdir-glob'),
|
|
3
|
+
Constants = require('./constants'),
|
|
4
|
+
crypto = require('crypto'),
|
|
5
|
+
fs = require('fs');
|
|
6
|
+
|
|
7
|
+
const hashWrapper = (options, instrumentBlocks) => {
|
|
8
|
+
instrumentBlocks.markBlockStart("checkAlreadyUploaded.md5Stats");
|
|
9
|
+
return folderStats(options).then((files) => {
|
|
10
|
+
instrumentBlocks.markBlockEnd("checkAlreadyUploaded.md5Stats");
|
|
11
|
+
instrumentBlocks.markBlockStart("checkAlreadyUploaded.md5Batch");
|
|
12
|
+
return batchHashFile(files);
|
|
13
|
+
}).then((hashes) => {
|
|
14
|
+
const combinedHash = crypto.createHash(Constants.hashingOptions.algo);
|
|
15
|
+
hashes.forEach((hash) => combinedHash.update(hash));
|
|
16
|
+
instrumentBlocks.markBlockEnd("checkAlreadyUploaded.md5Batch");
|
|
17
|
+
return combinedHash.digest(Constants.hashingOptions.encoding);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const folderStats = (options) => {
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
let readDirOptions = {};
|
|
24
|
+
Object.assign(readDirOptions, Constants.readDirOptions, options)
|
|
25
|
+
let globber = glob(readDirOptions.cwd || '.', readDirOptions);
|
|
26
|
+
let files = [];
|
|
27
|
+
globber.on('match', (fileMatch) => {
|
|
28
|
+
files.push({relativePath: fileMatch.relative, absolutePath: fileMatch.absolute, stats: fileMatch.stat})
|
|
29
|
+
});
|
|
30
|
+
globber.on('error', (_err) => {
|
|
31
|
+
reject("Error in getting files.");
|
|
32
|
+
});
|
|
33
|
+
globber.on('end', (_) => {
|
|
34
|
+
resolve(files);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const batchHashFile = (fileBatch) => {
|
|
40
|
+
return Promise.resolve(fileBatch).then((files) => {
|
|
41
|
+
files = Array(Math.ceil(files.length / Constants.hashingOptions.parallel)).fill([]).map((_, index) => index * Constants.hashingOptions.parallel).map(begin => files.slice(begin, begin + Constants.hashingOptions.parallel));
|
|
42
|
+
files = files.map((batch) => {
|
|
43
|
+
return (res) => Promise.all(batch.map(hashFile)).then((data) => res.concat(data));
|
|
44
|
+
});
|
|
45
|
+
let hash = files.reduce((acc, curr) => acc.then(curr), Promise.resolve([]));
|
|
46
|
+
return hash;
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const hashFile = (file) => {
|
|
51
|
+
return new Promise((resolve) => {
|
|
52
|
+
let { relativePath, absolutePath, stats } = file;
|
|
53
|
+
const hash = crypto.createHash(Constants.hashingOptions.algo);
|
|
54
|
+
hash.update(relativePath);
|
|
55
|
+
if (stats.isFile()) {
|
|
56
|
+
const f = fs.createReadStream(absolutePath);
|
|
57
|
+
f.on('end', () => {
|
|
58
|
+
const hashedValue = hash.digest(Constants.hashingOptions.encoding);
|
|
59
|
+
return resolve(hashedValue);
|
|
60
|
+
});
|
|
61
|
+
f.pipe(hash, { end: false });
|
|
62
|
+
} else {
|
|
63
|
+
// paths like empty directories.
|
|
64
|
+
const hashedValue = hash.digest(Constants.hashingOptions.encoding);
|
|
65
|
+
return resolve(hashedValue);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
exports.hashWrapper = hashWrapper;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const npm = require('npm'),
|
|
3
|
+
archiver = require("archiver"),
|
|
4
|
+
path = require('path'),
|
|
5
|
+
os = require('os'),
|
|
6
|
+
fs = require('fs-extra'),
|
|
7
|
+
fileHelpers = require('./fileHelpers'),
|
|
8
|
+
logger = require("./logger").winstonLogger,
|
|
9
|
+
Constants = require('./constants'),
|
|
10
|
+
process = require('process'),
|
|
11
|
+
utils = require('./utils');
|
|
12
|
+
|
|
13
|
+
const setupPackageFolder = (runSettings, directoryPath) => {
|
|
14
|
+
return new Promise(function (resolve, reject) {
|
|
15
|
+
fileHelpers.deletePackageArchieve(false);
|
|
16
|
+
fs.mkdir(directoryPath, function (err) {
|
|
17
|
+
try {
|
|
18
|
+
if (err) {
|
|
19
|
+
return reject(err);
|
|
20
|
+
}
|
|
21
|
+
let packageJSON = {};
|
|
22
|
+
if (typeof runSettings.package_config_options === 'object') {
|
|
23
|
+
Object.assign(packageJSON, runSettings.package_config_options);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (typeof runSettings.npm_dependencies === 'object') {
|
|
27
|
+
Object.assign(packageJSON, {
|
|
28
|
+
devDependencies: runSettings.npm_dependencies,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (Object.keys(packageJSON).length > 0) {
|
|
33
|
+
let packageJSONString = JSON.stringify(packageJSON);
|
|
34
|
+
let packagePath = path.join(directoryPath, "package.json");
|
|
35
|
+
fs.writeFileSync(packagePath, packageJSONString);
|
|
36
|
+
let cypressFolderPath = path.dirname(runSettings.cypressConfigFilePath);
|
|
37
|
+
let sourceNpmrc = path.join(cypressFolderPath, ".npmrc");
|
|
38
|
+
let destNpmrc = path.join(directoryPath, ".npmrc");
|
|
39
|
+
if (fs.existsSync(sourceNpmrc)) {
|
|
40
|
+
fs.copyFileSync(sourceNpmrc, destNpmrc);
|
|
41
|
+
}
|
|
42
|
+
return resolve("package file created");
|
|
43
|
+
}
|
|
44
|
+
return reject("Nothing in package file");
|
|
45
|
+
} catch(error) {
|
|
46
|
+
return reject(error);
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
})
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const packageInstall = (packageDir) => {
|
|
53
|
+
return new Promise(function (resolve, reject) {
|
|
54
|
+
let savedPrefix = null;
|
|
55
|
+
let npmLoad = Constants.packageInstallerOptions.npmLoad
|
|
56
|
+
npmLoad["cache"] = fs.mkdtempSync(`${os.tmpdir()}${path.sep}`);
|
|
57
|
+
const installCallback = (err, result) => {
|
|
58
|
+
npm.prefix = savedPrefix;
|
|
59
|
+
if (err) {
|
|
60
|
+
return reject(err);
|
|
61
|
+
}
|
|
62
|
+
resolve(result);
|
|
63
|
+
};
|
|
64
|
+
const loadCallback = (err) => {
|
|
65
|
+
if (err) {
|
|
66
|
+
return reject(err);
|
|
67
|
+
}
|
|
68
|
+
savedPrefix = npm.prefix;
|
|
69
|
+
npm.prefix = packageDir;
|
|
70
|
+
npm.commands.install(packageDir, [], installCallback);
|
|
71
|
+
};
|
|
72
|
+
npm.load(npmLoad, loadCallback);
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const packageArchiver = (packageDir, packageFile) => {
|
|
77
|
+
return new Promise(function (resolve, reject) {
|
|
78
|
+
let output = fs.createWriteStream(packageFile);
|
|
79
|
+
let archive = archiver('tar', {
|
|
80
|
+
gzip: true
|
|
81
|
+
});
|
|
82
|
+
archive.on('warning', function (err) {
|
|
83
|
+
if (err.code === 'ENOENT') {
|
|
84
|
+
logger.info(err);
|
|
85
|
+
} else {
|
|
86
|
+
reject(err);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
output.on('close', function () {
|
|
91
|
+
resolve('Zipping completed');
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
output.on('end', function () {
|
|
95
|
+
logger.info('Data has been drained');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
archive.on('error', function (err) {
|
|
99
|
+
reject(err);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
archive.pipe(output);
|
|
103
|
+
archive.directory(packageDir, false);
|
|
104
|
+
archive.finalize();
|
|
105
|
+
})
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const packageWrapper = (bsConfig, packageDir, packageFile, md5data, instrumentBlocks) => {
|
|
109
|
+
return new Promise(function (resolve) {
|
|
110
|
+
let obj = {
|
|
111
|
+
packageArchieveCreated: false
|
|
112
|
+
};
|
|
113
|
+
if (md5data.packageUrlPresent || !utils.isTrueString(bsConfig.run_settings.cache_dependencies)) {
|
|
114
|
+
return resolve(obj);
|
|
115
|
+
}
|
|
116
|
+
logger.info(`Installing required dependencies and building the package to upload to BrowserStack`);
|
|
117
|
+
instrumentBlocks.markBlockStart("packageInstaller.folderSetup");
|
|
118
|
+
return setupPackageFolder(bsConfig.run_settings, packageDir).then((_result) => {
|
|
119
|
+
process.env.CYPRESS_INSTALL_BINARY = 0
|
|
120
|
+
instrumentBlocks.markBlockEnd("packageInstaller.folderSetup");
|
|
121
|
+
instrumentBlocks.markBlockStart("packageInstaller.packageInstall");
|
|
122
|
+
return packageInstall(packageDir);
|
|
123
|
+
}).then((_result) => {
|
|
124
|
+
instrumentBlocks.markBlockEnd("packageInstaller.packageInstall");
|
|
125
|
+
instrumentBlocks.markBlockStart("packageInstaller.packageArchive");
|
|
126
|
+
return packageArchiver(packageDir, packageFile);
|
|
127
|
+
}).then((_result) => {
|
|
128
|
+
instrumentBlocks.markBlockEnd("packageInstaller.packageArchive");
|
|
129
|
+
Object.assign(obj, { packageArchieveCreated: true });
|
|
130
|
+
return resolve(obj);
|
|
131
|
+
}).catch((err) => {
|
|
132
|
+
obj.error = err.stack.substring(0,100);
|
|
133
|
+
return resolve(obj);
|
|
134
|
+
})
|
|
135
|
+
})
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
exports.packageWrapper = packageWrapper;
|
|
@@ -4,7 +4,8 @@ const fs = require('fs'),
|
|
|
4
4
|
logger = require('./logger').winstonLogger,
|
|
5
5
|
utils = require("./utils"),
|
|
6
6
|
Constants = require('./constants'),
|
|
7
|
-
config = require("./config")
|
|
7
|
+
config = require("./config"),
|
|
8
|
+
axios = require("axios");
|
|
8
9
|
|
|
9
10
|
let templatesDir = path.join(__dirname, '../', 'templates');
|
|
10
11
|
|
|
@@ -100,7 +101,7 @@ let reportGenerator = (bsConfig, buildId, args, cb) => {
|
|
|
100
101
|
},
|
|
101
102
|
};
|
|
102
103
|
|
|
103
|
-
return request.get(options, function (err, resp, body) {
|
|
104
|
+
return request.get(options, async function (err, resp, body) {
|
|
104
105
|
let message = null;
|
|
105
106
|
let messageType = null;
|
|
106
107
|
let errorCode = null;
|
|
@@ -163,7 +164,7 @@ let reportGenerator = (bsConfig, buildId, args, cb) => {
|
|
|
163
164
|
} else {
|
|
164
165
|
messageType = Constants.messageTypes.SUCCESS;
|
|
165
166
|
message = `Report for build: ${buildId} was successfully created.`;
|
|
166
|
-
renderReportHTML(build);
|
|
167
|
+
await renderReportHTML(build);
|
|
167
168
|
logger.info(message);
|
|
168
169
|
}
|
|
169
170
|
utils.sendUsageReport(bsConfig, args, message, messageType, errorCode);
|
|
@@ -173,7 +174,7 @@ let reportGenerator = (bsConfig, buildId, args, cb) => {
|
|
|
173
174
|
});
|
|
174
175
|
}
|
|
175
176
|
|
|
176
|
-
function renderReportHTML(report_data) {
|
|
177
|
+
async function renderReportHTML(report_data) {
|
|
177
178
|
let resultsDir = 'results';
|
|
178
179
|
let metaCharSet = `<meta charset="utf-8">`;
|
|
179
180
|
let metaViewPort = `<meta name="viewport" content="width=device-width, initial-scale=1"> `;
|
|
@@ -194,12 +195,17 @@ function renderReportHTML(report_data) {
|
|
|
194
195
|
}
|
|
195
196
|
|
|
196
197
|
// Writing the JSON used in creating the HTML file.
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
198
|
+
let reportData = await cypressReportData(report_data);
|
|
199
|
+
fs.writeFileSync(
|
|
200
|
+
`${resultsDir}/browserstack-cypress-report.json`,
|
|
201
|
+
JSON.stringify(reportData),
|
|
202
|
+
() => {
|
|
203
|
+
if (err) {
|
|
204
|
+
return logger.error(err);
|
|
205
|
+
}
|
|
206
|
+
logger.info("The JSON file is saved");
|
|
200
207
|
}
|
|
201
|
-
|
|
202
|
-
});
|
|
208
|
+
);
|
|
203
209
|
|
|
204
210
|
// Writing the HTML file generated from the JSON data.
|
|
205
211
|
fs.writeFileSync(`${resultsDir}/browserstack-cypress-report.html`, html, () => {
|
|
@@ -210,4 +216,106 @@ function renderReportHTML(report_data) {
|
|
|
210
216
|
});
|
|
211
217
|
}
|
|
212
218
|
|
|
219
|
+
async function cypressReportData(report_data) {
|
|
220
|
+
specFiles = Object.keys(report_data.rows);
|
|
221
|
+
combinationPromises = [];
|
|
222
|
+
for (let spec of specFiles) {
|
|
223
|
+
let specSessions = report_data.rows[spec]["sessions"];
|
|
224
|
+
if (specSessions.length > 0) {
|
|
225
|
+
for (let combination of specSessions) {
|
|
226
|
+
if(utils.isUndefined(report_data.cypress_version) || report_data.cypress_version < "6"){
|
|
227
|
+
combinationPromises.push(generateCypressCombinationSpecReportDataWithoutConfigJson(combination));
|
|
228
|
+
}else{
|
|
229
|
+
combinationPromises.push(generateCypressCombinationSpecReportDataWithConfigJson(combination));
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
await Promise.all(combinationPromises);
|
|
235
|
+
return report_data;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function generateCypressCombinationSpecReportDataWithConfigJson(combination){
|
|
239
|
+
return new Promise(async (resolve, reject) => {
|
|
240
|
+
try {
|
|
241
|
+
let configJsonError, resultsJsonError;
|
|
242
|
+
let [configJsonResponse, resultsJsonResponse] = await axios.all([
|
|
243
|
+
axios.get(combination.tests.config_json).catch(function (error) {
|
|
244
|
+
configJsonError = true;
|
|
245
|
+
}),
|
|
246
|
+
axios.get(combination.tests.result_json).catch(function(error){
|
|
247
|
+
resultsJsonError = true;
|
|
248
|
+
})
|
|
249
|
+
]);
|
|
250
|
+
if(resultsJsonError || configJsonError){
|
|
251
|
+
resolve();
|
|
252
|
+
}
|
|
253
|
+
let tests = {};
|
|
254
|
+
let configJson = configJsonResponse.data;
|
|
255
|
+
let resultsJson = resultsJsonResponse.data;
|
|
256
|
+
if(utils.isUndefined(configJson.tests) || utils.isUndefined(resultsJson.tests)){
|
|
257
|
+
resolve();
|
|
258
|
+
}
|
|
259
|
+
configJson.tests.forEach((test) => {
|
|
260
|
+
tests[test["clientId"]] = test;
|
|
261
|
+
});
|
|
262
|
+
resultsJson.tests.forEach((test) => {
|
|
263
|
+
tests[test["clientId"]] = Object.assign(
|
|
264
|
+
tests[test["clientId"]],
|
|
265
|
+
test
|
|
266
|
+
);
|
|
267
|
+
});
|
|
268
|
+
let sessionTests = [];
|
|
269
|
+
Object.keys(tests).forEach((testId) => {
|
|
270
|
+
sessionTests.push({
|
|
271
|
+
name: tests[testId]["title"].pop(),
|
|
272
|
+
status: tests[testId]["state"],
|
|
273
|
+
duration: parseFloat(
|
|
274
|
+
tests[testId]["attempts"].pop()["wallClockDuration"] / 1000
|
|
275
|
+
).toFixed(2),
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
combination.tests = sessionTests;
|
|
279
|
+
resolve(combination.tests);
|
|
280
|
+
} catch (error) {
|
|
281
|
+
process.exitCode = Constants.ERROR_EXIT_CODE;
|
|
282
|
+
reject(error);
|
|
283
|
+
}
|
|
284
|
+
})
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function generateCypressCombinationSpecReportDataWithoutConfigJson(combination){
|
|
288
|
+
return new Promise(async (resolve, reject) => {
|
|
289
|
+
try {
|
|
290
|
+
let resultsJsonError;
|
|
291
|
+
let resultsJsonResponse = await axios.get(combination.tests.result_json).catch(function(error){
|
|
292
|
+
resultsJsonError = true;
|
|
293
|
+
});
|
|
294
|
+
if(resultsJsonError || utils.isUndefined(resultsJsonResponse)){
|
|
295
|
+
resolve();
|
|
296
|
+
}
|
|
297
|
+
let resultsJson = resultsJsonResponse.data;
|
|
298
|
+
let sessionTests = [];
|
|
299
|
+
if(utils.isUndefined(resultsJson.tests)){
|
|
300
|
+
resolve();
|
|
301
|
+
}
|
|
302
|
+
resultsJson.tests.forEach((test) => {
|
|
303
|
+
durationKey = utils.isUndefined(test["attempts"]) ? test : test["attempts"].pop()
|
|
304
|
+
sessionTests.push({
|
|
305
|
+
name: test["title"].pop(),
|
|
306
|
+
status: test["state"],
|
|
307
|
+
duration: parseFloat(
|
|
308
|
+
durationKey["wallClockDuration"] / 1000
|
|
309
|
+
).toFixed(2)
|
|
310
|
+
})
|
|
311
|
+
});
|
|
312
|
+
combination.tests = sessionTests;
|
|
313
|
+
resolve(combination.tests);
|
|
314
|
+
} catch (error) {
|
|
315
|
+
process.exitCode = Constants.ERROR_EXIT_CODE;
|
|
316
|
+
reject(error);
|
|
317
|
+
}
|
|
318
|
+
})
|
|
319
|
+
}
|
|
320
|
+
|
|
213
321
|
exports.reportGenerator = reportGenerator;
|
|
@@ -3,6 +3,7 @@ const request = require("request"),
|
|
|
3
3
|
config = require("../config"),
|
|
4
4
|
utils = require("../utils"),
|
|
5
5
|
logger = require("../logger").syncCliLogger,
|
|
6
|
+
winstonLogger = require("../logger").winstonLogger,
|
|
6
7
|
async = require('async'),
|
|
7
8
|
Constants = require("../constants"),
|
|
8
9
|
tableStream = require('table').createStream,
|
|
@@ -13,7 +14,10 @@ let specSummary = {
|
|
|
13
14
|
"specs": [],
|
|
14
15
|
"duration": null
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
+
let noWrap = false;
|
|
18
|
+
let terminalWidth = (process.stdout.columns) * 0.9;
|
|
19
|
+
let lineSeparator = Constants.syncCLI.DEFAULT_LINE_SEP;
|
|
20
|
+
if (!isNaN(terminalWidth)) lineSeparator = "\n" + "-".repeat(terminalWidth);
|
|
17
21
|
|
|
18
22
|
let getOptions = (auth, build_id) => {
|
|
19
23
|
return {
|
|
@@ -30,15 +34,26 @@ let getOptions = (auth, build_id) => {
|
|
|
30
34
|
};
|
|
31
35
|
}
|
|
32
36
|
|
|
33
|
-
let getTableConfig = () => {
|
|
37
|
+
let getTableConfig = (termWidth) => {
|
|
38
|
+
let centerWidth = Math.ceil(termWidth * 0.01),
|
|
39
|
+
leftWidth = Math.floor(termWidth * 0.75),
|
|
40
|
+
colWidth = Math.floor(termWidth * 0.2);
|
|
41
|
+
|
|
42
|
+
// Do not autosize on terminal's width if no-wrap provided
|
|
43
|
+
if (noWrap || isNaN(termWidth)) {
|
|
44
|
+
centerWidth = 1;
|
|
45
|
+
leftWidth = 100;
|
|
46
|
+
colWidth = 30;
|
|
47
|
+
}
|
|
48
|
+
|
|
34
49
|
return {
|
|
35
50
|
border: getBorderConfig(),
|
|
36
51
|
columns: {
|
|
37
|
-
1: {alignment: 'center', width:
|
|
38
|
-
2: {alignment: 'left', width:
|
|
52
|
+
1: {alignment: 'center', width: centerWidth},
|
|
53
|
+
2: {alignment: 'left', width: leftWidth}
|
|
39
54
|
},
|
|
40
55
|
columnDefault: {
|
|
41
|
-
width:
|
|
56
|
+
width: colWidth,
|
|
42
57
|
},
|
|
43
58
|
columnCount: 3,
|
|
44
59
|
};
|
|
@@ -67,10 +82,19 @@ let getBorderConfig = () => {
|
|
|
67
82
|
}
|
|
68
83
|
}
|
|
69
84
|
|
|
85
|
+
let setNoWrapParams = () => {
|
|
86
|
+
noWrap = (process.env.SYNC_NO_WRAP && (process.env.SYNC_NO_WRAP === 'true'));
|
|
87
|
+
// Do not show the separator based on terminal width if no-wrap provided.
|
|
88
|
+
if (noWrap) {
|
|
89
|
+
lineSeparator = Constants.syncCLI.DEFAULT_LINE_SEP;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
70
93
|
let printSpecsStatus = (bsConfig, buildDetails) => {
|
|
94
|
+
setNoWrapParams();
|
|
71
95
|
return new Promise((resolve, reject) => {
|
|
72
96
|
options = getOptions(bsConfig.auth, buildDetails.build_id)
|
|
73
|
-
tableConfig = getTableConfig();
|
|
97
|
+
tableConfig = getTableConfig(terminalWidth);
|
|
74
98
|
stream = tableStream(tableConfig);
|
|
75
99
|
|
|
76
100
|
async.whilst(
|
|
@@ -81,7 +105,10 @@ let printSpecsStatus = (bsConfig, buildDetails) => {
|
|
|
81
105
|
whileProcess(callback)
|
|
82
106
|
},
|
|
83
107
|
function(err, result) { // when loop ends
|
|
84
|
-
|
|
108
|
+
if (err) {
|
|
109
|
+
utils.sendUsageReport(bsConfig, {}, `buildId: ${buildDetails.build_id}`, 'error', 'sync_cli_error', err);
|
|
110
|
+
}
|
|
111
|
+
logger.info(lineSeparator);
|
|
85
112
|
specSummary.duration = endTime - startTime
|
|
86
113
|
resolve(specSummary)
|
|
87
114
|
}
|
|
@@ -138,8 +165,9 @@ let showSpecsStatus = (data) => {
|
|
|
138
165
|
}
|
|
139
166
|
|
|
140
167
|
let printInitialLog = () => {
|
|
168
|
+
winstonLogger.info(Constants.syncCLI.STARTUP_MESSAGE);
|
|
141
169
|
logger.info(`\n${Constants.syncCLI.LOGS.INIT_LOG}`)
|
|
142
|
-
logger.info(
|
|
170
|
+
logger.info(lineSeparator);
|
|
143
171
|
n = Constants.syncCLI.INITIAL_DELAY_MULTIPLIER
|
|
144
172
|
}
|
|
145
173
|
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { isUndefined } = require('./utils');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
let sessionTimes = {
|
|
7
|
+
referenceTimes: {
|
|
8
|
+
absoluteStartTime: Date.now()
|
|
9
|
+
}, // Absolute times which needs to be used later to calculate logTimes
|
|
10
|
+
logTimes: {}, // Time Difference in ms which we need to push to EDS
|
|
11
|
+
eventTime: {}, // Time for particular events
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const initTimeComponents = () => {
|
|
15
|
+
sessionTimes = {referenceTimes: {absoluteStartTime: Date.now()}, logTimes: {}, eventTime: {}};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const markBlockStart = (blockName) => {
|
|
19
|
+
sessionTimes.referenceTimes[blockName] = Date.now();
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const markBlockEnd = (blockName) => {
|
|
23
|
+
const startTime = sessionTimes.referenceTimes[blockName] || sessionTimes.referenceTimes.absoluteStartTime;
|
|
24
|
+
markBlockDiff(blockName, startTime, Date.now());
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const markBlockDiff = (blockName, startTime, stopTime) => {
|
|
28
|
+
sessionTimes.logTimes[blockName] = stopTime - startTime;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const instrumentEventTime = (eventName) => {
|
|
32
|
+
sessionTimes.eventTime[eventName] = new Date(new Date().toUTCString());
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const getTimeComponents = () => {
|
|
36
|
+
const data = convertDotToNestedObject(sessionTimes.logTimes);
|
|
37
|
+
return Object.assign(data, sessionTimes.eventTime);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const convertDotToNestedObject = (dotNotationObject) => {
|
|
41
|
+
let nestedObject = {};
|
|
42
|
+
|
|
43
|
+
Object.keys(dotNotationObject).forEach((key) => {
|
|
44
|
+
let dotKeys = key.split('.');
|
|
45
|
+
let currentKey = nestedObject;
|
|
46
|
+
for(let i = 0; i < dotKeys.length - 1; i++) {
|
|
47
|
+
if (isUndefined(currentKey[dotKeys[i]])) {
|
|
48
|
+
currentKey[dotKeys[i]] = {};
|
|
49
|
+
} else if (Number.isInteger(currentKey[dotKeys[i]])) {
|
|
50
|
+
currentKey[dotKeys[i]] = {total: currentKey[dotKeys[i]]};
|
|
51
|
+
}
|
|
52
|
+
currentKey = currentKey[dotKeys[i]];
|
|
53
|
+
}
|
|
54
|
+
if (isUndefined(currentKey[dotKeys[dotKeys.length - 1]]) || Number.isInteger(currentKey[dotKeys[dotKeys.length - 1]])) {
|
|
55
|
+
currentKey[dotKeys[dotKeys.length - 1]] = dotNotationObject[key];
|
|
56
|
+
} else {
|
|
57
|
+
currentKey[dotKeys[dotKeys.length - 1]].total = dotNotationObject[key];
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
return nestedObject;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
module.exports = {
|
|
65
|
+
initTimeComponents,
|
|
66
|
+
instrumentEventTime,
|
|
67
|
+
markBlockStart,
|
|
68
|
+
markBlockEnd,
|
|
69
|
+
markBlockDiff,
|
|
70
|
+
getTimeComponents,
|
|
71
|
+
};
|
|
@@ -6,7 +6,8 @@ const cp = require("child_process"),
|
|
|
6
6
|
path = require('path');
|
|
7
7
|
|
|
8
8
|
const config = require('./config'),
|
|
9
|
-
fileLogger = require('./logger').fileLogger
|
|
9
|
+
fileLogger = require('./logger').fileLogger,
|
|
10
|
+
utils = require('./utils');
|
|
10
11
|
|
|
11
12
|
function get_version(package_name) {
|
|
12
13
|
try {
|
|
@@ -33,7 +34,7 @@ function local_cypress_version(bsConfig) {
|
|
|
33
34
|
// 1. check version of Cypress installed in local project
|
|
34
35
|
// 2. check version of Cypress installed globally if not present in project
|
|
35
36
|
|
|
36
|
-
if (bsConfig && bsConfig.run_settings.cypressProjectDir) {
|
|
37
|
+
if (bsConfig && bsConfig.run_settings && bsConfig.run_settings.cypressProjectDir) {
|
|
37
38
|
let version = get_version(path.join(bsConfig.run_settings.cypressProjectDir, 'node_modules', '.bin', 'cypress'));
|
|
38
39
|
if (!version) {
|
|
39
40
|
version = get_version('cypress');
|
|
@@ -80,7 +81,7 @@ function cli_version_and_path(bsConfig) {
|
|
|
80
81
|
// 1. check version of Cypress installed in local project
|
|
81
82
|
// 2. check version of Cypress installed globally if not present in project
|
|
82
83
|
|
|
83
|
-
if (bsConfig && bsConfig.run_settings.cypressProjectDir) {
|
|
84
|
+
if (bsConfig && bsConfig.run_settings && bsConfig.run_settings.cypressProjectDir) {
|
|
84
85
|
let _path = path.join(bsConfig.run_settings.cypressProjectDir, 'node_modules', 'browserstack-cypress');
|
|
85
86
|
let version = get_version(_path);
|
|
86
87
|
if (!version) {
|
|
@@ -174,7 +175,7 @@ function send(args) {
|
|
|
174
175
|
|
|
175
176
|
let bsConfig = args.bstack_config;
|
|
176
177
|
let cli_details = cli_version_and_path(bsConfig);
|
|
177
|
-
let data = {}
|
|
178
|
+
let data = utils.isUndefined(args.data) ? {} : args.data;
|
|
178
179
|
|
|
179
180
|
if (bsConfig && bsConfig.run_settings) {
|
|
180
181
|
data.cypress_version = bsConfig.run_settings.cypress_version
|