Skip to content

Commit 98a120b

Browse files
committed
add methods to print custom error messages
1 parent 5dd2cff commit 98a120b

File tree

4 files changed

+57
-14
lines changed

4 files changed

+57
-14
lines changed

bin/helpers/constants.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ const REDACTED_AUTH =`auth: { "username": ${REDACTED}, "access_key": ${REDACTED}
241241

242242
const SPEC_TIMEOUT_LIMIT = 120 // IN MINS
243243

244+
const CYPRESS_CUSTOM_ERRORS_TO_PRINT_KEY = "custom_errors_to_print";
245+
244246
module.exports = Object.freeze({
245247
syncCLI,
246248
userMessages,
@@ -262,5 +264,6 @@ module.exports = Object.freeze({
262264
AUTH_REGEX,
263265
REDACTED_AUTH,
264266
BUILD_FAILED_EXIT_CODE,
265-
SPEC_TIMEOUT_LIMIT
267+
SPEC_TIMEOUT_LIMIT,
268+
CYPRESS_CUSTOM_ERRORS_TO_PRINT_KEY
266269
});

bin/helpers/sync/specsSummary.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const logger = require("../logger").syncCliLogger;
2+
const winstonlogger = require("../logger").winstonLogger;
23

34
/**
45
*
@@ -16,7 +17,7 @@ const logger = require("../logger").syncCliLogger;
1617
// {specName: 'spec8.alias.js', status: 'Skipped', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'}
1718
// ]
1819
//
19-
let printSpecsRunSummary = (data, machines) => {
20+
let printSpecsRunSummary = (data, machines, customErrorsToPrint) => {
2021
return new Promise((resolve, _reject) => {
2122
let summary = {
2223
total: 0,
@@ -32,6 +33,24 @@ let printSpecsRunSummary = (data, machines) => {
3233
logger.info(`Total tests: ${summary.total}, passed: ${summary.passed}, failed: ${summary.failed}, skipped: ${summary.skipped}`);
3334
logger.info(`Done in ${data.duration/1000} seconds using ${machines} machines\n`);
3435

36+
if (customErrorsToPrint && customErrorsToPrint.length > 0) {
37+
for (const error of customErrorsToPrint) {
38+
switch(error.level) {
39+
case 'info':
40+
winstonlogger.info(error.message);
41+
break;
42+
case 'warn':
43+
winstonlogger.warn(error.message);
44+
break;
45+
case 'error':
46+
winstonlogger.error(error.message);
47+
break;
48+
default:
49+
winstonlogger.warn(error.message);
50+
}
51+
}
52+
}
53+
3554
resolve(data.exitCode);
3655
})
3756
};

bin/helpers/sync/syncSpecsLogs.js

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ let whileLoop = true, whileTries = config.retries, options, timeout = 3000, n =
1313
let specSummary = {
1414
"buildError": null,
1515
"specs": [],
16-
"duration": null
16+
"duration": null,
17+
"customErrorsToPrint": []
1718
}
19+
1820
let noWrap = false;
1921
let terminalWidth = (process.stdout.columns) * 0.9;
2022
let lineSeparator = Constants.syncCLI.DEFAULT_LINE_SEP;
@@ -166,18 +168,22 @@ let getStackTraceUrl = () => {
166168
let showSpecsStatus = (data) => {
167169
let specData = JSON.parse(data);
168170
specData.forEach(specDetails => {
169-
if (specDetails == "created") {
170-
return;
171-
} else if (specDetails["stacktrace_url"]) {
172-
specSummary.exitCode = Constants.BUILD_FAILED_EXIT_CODE;
173-
specSummary.buildError = specDetails["stacktrace_url"]
174-
winstonLogger.error(chalk.red(specDetails["message"]));
171+
if (specDetails.type === Constants.CYPRESS_CUSTOM_ERRORS_TO_PRINT_KEY) {
172+
addCustomErrorToPrint(specDetails);
175173
} else {
176-
if(!buildStarted) {
177-
buildStarted = true
178-
printInitialLog();
174+
if (specDetails == "created") {
175+
return;
176+
} else if (specDetails["stacktrace_url"]) {
177+
specSummary.exitCode = Constants.BUILD_FAILED_EXIT_CODE;
178+
specSummary.buildError = specDetails["stacktrace_url"]
179+
winstonLogger.error(chalk.red(specDetails["message"]));
180+
} else {
181+
if(!buildStarted) {
182+
buildStarted = true
183+
printInitialLog();
184+
}
185+
printSpecData(JSON.parse(specDetails));
179186
}
180-
printSpecData(JSON.parse(specDetails));
181187
}
182188
});
183189
}
@@ -200,6 +206,17 @@ let writeToTable = (combination, specName, status) => {
200206
stream.write([combination , ":", `${specName} ${status}`]);
201207
}
202208

209+
let addCustomErrorToPrint = (error_object) => {
210+
if (error_object["should_be_unique"]) {
211+
for (const error of specSummary.customErrorsToPrint) {
212+
if (error.id === error_object.id) {
213+
return;
214+
}
215+
}
216+
}
217+
specSummary.customErrorsToPrint.push(error_object);
218+
}
219+
203220
let addSpecToSummary = (specName, status, combination, session_id) => {
204221
// Format for part 3: {specName: 'spec1.failed.js', status: 'Failed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'},
205222
specSummary["specs"].push({

bin/helpers/syncRunner.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ const syncSpecsLogs = require('./sync/syncSpecsLogs'),
44
specsSummary = require('./sync/specsSummary');
55

66
exports.pollBuildStatus = (bsConfig, buildDetails) => {
7+
let customErrorsToPrint;
78
return new Promise((resolve, reject) => {
89
syncSpecsLogs.printSpecsStatus(bsConfig, buildDetails).then((data) => {
10+
if(data.customErrorsToPrint && data.customErrorsToPrint.length > 0) {
11+
customErrorsToPrint = data.customErrorsToPrint;
12+
}
913
return specDetails.failedSpecsDetails(data);
1014
}).then((data) => {
11-
return specsSummary.printSpecsRunSummary(data, buildDetails.machines);
15+
return specsSummary.printSpecsRunSummary(data, buildDetails.machines, customErrorsToPrint);
1216
}).then((successExitCode) => {
1317
resolve(successExitCode); // exit code 0
1418
}).catch((nonZeroExitCode) => {

0 commit comments

Comments
 (0)