Skip to content

Commit 719ac27

Browse files
committed
Added spec failure/skipped message with table.
- Print an ASCII table with Failed / Skipped specs in it. - Details include spec name, status, combiantion, and session id in the order. - The status and header are colour printed for better readability. - Handle the resolve and reject which bubble up the exit code to main run. - process will now exit as zero or non zero code. - Fixed typo in constant.
1 parent ccd2b86 commit 719ac27

File tree

3 files changed

+80
-18
lines changed

3 files changed

+80
-18
lines changed

bin/helpers/constants.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
const syncCLI = {
2+
FAILED_SPEC_DETAILS_COL_HEADER: ['Spec', 'Status', 'Browser', 'BrowserStack Session ID']
3+
};
4+
15
const userMessages = {
26
BUILD_FAILED: "Build creation failed.",
37
BUILD_CREATED: "Build created",
48
BUILD_INFO_FAILED: "Failed to get build info.",
59
BUILD_STOP_FAILED: "Failed to stop build.",
6-
BUILD_REPORT_MESDSAGE: "See the entire build report here:",
10+
BUILD_REPORT_MESSAGE: "See the entire build report here:",
711
ZIP_UPLOADER_NOT_REACHABLE: "Could not reach to zip uploader.",
812
ZIP_UPLOAD_FAILED: "Zip Upload failed.",
913
CONFIG_FILE_CREATED: "BrowserStack Config File created, you can now run browserstack-cypress --config-file run",
@@ -94,6 +98,7 @@ const allowedFileTypes = ['js', 'json', 'txt', 'ts', 'feature', 'features', 'pdf
9498
const filesToIgnoreWhileUploading = ['node_modules/**', 'package-lock.json', 'package.json', 'browserstack-package.json', 'tests.zip', 'cypress.json']
9599

96100
module.exports = Object.freeze({
101+
syncCLI,
97102
userMessages,
98103
cliMessages,
99104
validationMessages,

bin/helpers/syncRunner.js

Lines changed: 73 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
'use strict';
2-
const config = require("./config"),
2+
const Config = require("./config"),
33
logger = require("./logger").syncCliLogger,
44
Constants = require("./constants"),
55
utils = require("./utils"),
6-
request = require('request');
6+
request = require('request'),
7+
{ table, getBorderCharacters } = require('table'),
8+
chalk = require('chalk');
79

810
exports.pollBuildStatus = (bsConfig, buildId) => {
911
logBuildDetails().then((data) => {
1012
printSpecsStatus();
1113
}).then((data) => {
1214
printSpecsRunSummary();
1315
}).then((data) => {
14-
printFailedSpecsDetails();
15-
}).then((data) => {
16-
printBuildDashboardLink(buildId);
17-
}).then((data) => {
18-
// success case!
19-
return 0; // exit code 0
20-
}).catch((err) => {
21-
// failed case!
22-
return 1; // exit code 1
16+
printFailedSpecsDetails(data);
17+
}).then((successExitCode) => {
18+
return resolveExitCode(successExitCode); // exit code 0
19+
}).catch((nonZeroExitCode) => {
20+
return resolveExitCode(nonZeroExitCode); // exit code 1
21+
}).finally(() => {
22+
logger.info(Constants.userMessages.BUILD_REPORT_MESSAGE);
23+
logger.info(`${Config.dashboardUrl}${buildId}`);
2324
});
2425
};
2526

@@ -35,13 +36,68 @@ let printSpecsRunSummary = () => {
3536

3637
};
3738

38-
let printFailedSpecsDetails = () => {
39+
/**
40+
*
41+
* @param {Array.<{specName: string, status: string, combination: string, sessionId: string}>} data
42+
* @returns {Promise.resolve || Promise.reject}
43+
*/
44+
// Example:
45+
// [
46+
// {specName: 'spec1.failed.js', status: 'Failed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'},
47+
// {specName: 'spec2.name.js', status: 'Skipped', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'},
48+
// {specName: 'spec3.network.js', status: 'Failed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'},
49+
// {specName: 'spec6.utils.js', status: 'Failed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'},
50+
// {specName: 'spec8.alias.js', status: 'Skipped', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'}
51+
// ]
52+
let printFailedSpecsDetails = (data) => {
53+
return new Promise((resolve, reject) => {
54+
if (data.length === 0) resolve(0); // return if no failed/skipped tests.
3955

40-
};
56+
let failedSpecs = false;
57+
let specResultHeader = Constants.syncCLI.FAILED_SPEC_DETAILS_COL_HEADER.map((col) => {
58+
return chalk.blueBright(col);
59+
});
4160

42-
let printBuildDashboardLink = (buildId) => {
43-
new Promise((resolve, reject) => {
44-
logger.info(Constants.userMessages.BUILD_REPORT_MESSAGE);
45-
logger.info(`${config.dashboardUrl}${buildId}`);
61+
let specData = [specResultHeader]; // 2-D array
62+
63+
data.forEach((spec) => {
64+
if (spec.status && spec.status.toLowerCase() === 'failed' && !failedSpecs)
65+
failedSpecs = true;
66+
67+
let specStatus = (spec.status && spec.status.toLowerCase() === 'failed') ?
68+
chalk.red(spec.status) : chalk.yellow(spec.status);
69+
specData.push([spec.specName, specStatus, spec.combination, spec.sessionId]);
70+
});
71+
72+
let config = {
73+
border: getBorderCharacters('ramac'),
74+
columns: {
75+
0: { alignment: 'center' },
76+
1: { alignment: 'center' },
77+
2: { alignment: 'center' },
78+
3: { alignment: 'center' },
79+
},
80+
/**
81+
* @typedef {function} drawHorizontalLine
82+
* @param {number} index
83+
* @param {number} size
84+
* @return {boolean}
85+
*/
86+
drawHorizontalLine: (index, size) => {
87+
return (index === 0 || index === 1 || index === size);
88+
}
89+
}
90+
91+
let result = table(specData, config);
92+
93+
logger.info('Failed / skipped test report');
94+
logger.info(result);
95+
96+
if (failedSpecs) reject(1); // specs failed, send exitCode as 1
97+
resolve(0); // No Specs failed, maybe skipped, but not failed, send exitCode as 0
4698
});
4799
};
100+
101+
let resolveExitCode = (exitCode) => {
102+
return new Promise((resolve, _reject) => { resolve(exitCode) });
103+
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
},
1414
"dependencies": {
1515
"archiver": "^3.1.1",
16+
"chalk": "^4.1.0",
1617
"fs-extra": "^8.1.0",
1718
"mkdirp": "^1.0.3",
1819
"request": "^2.88.0",

0 commit comments

Comments
 (0)