Skip to content

Commit 6dfb6ee

Browse files
committed
Adding basic tests for failedSpecDetails
1 parent 165985e commit 6dfb6ee

File tree

4 files changed

+97
-63
lines changed

4 files changed

+97
-63
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
*
3+
* @param {Array.<{specName: string, status: string, combination: string, sessionId: string}>} data
4+
* @returns {Promise.resolve || Promise.reject}
5+
*/
6+
// Example:
7+
// [
8+
// {specName: 'spec1.failed.js', status: 'Failed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'},
9+
// {specName: 'spec2.name.js', status: 'Skipped', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'},
10+
// {specName: 'spec3.network.js', status: 'Failed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'},
11+
// {specName: 'spec6.utils.js', status: 'Failed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'},
12+
// {specName: 'spec8.alias.js', status: 'Skipped', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'}
13+
// ]
14+
//
15+
let failedSpecsDetails = (data) => {
16+
return new Promise((resolve, reject) => {
17+
if (data.length === 0) resolve(0); // return if no failed/skipped tests.
18+
19+
let failedSpecs = false;
20+
let specResultHeader = Constants.syncCLI.FAILED_SPEC_DETAILS_COL_HEADER.map((col) => {
21+
return chalk.blueBright(col);
22+
});
23+
24+
let specData = [specResultHeader]; // 2-D array
25+
26+
data.forEach((spec) => {
27+
if (spec.status && spec.status.toLowerCase() === 'failed' && !failedSpecs)
28+
failedSpecs = true;
29+
30+
let specStatus = (spec.status && spec.status.toLowerCase() === 'failed') ?
31+
chalk.red(spec.status) : chalk.yellow(spec.status);
32+
specData.push([spec.specName, specStatus, spec.combination, spec.sessionId]);
33+
});
34+
35+
let config = {
36+
border: getBorderCharacters('ramac'),
37+
columns: {
38+
0: { alignment: 'left' },
39+
1: { alignment: 'left' },
40+
2: { alignment: 'left' },
41+
3: { alignment: 'left' },
42+
},
43+
/**
44+
* @typedef {function} drawHorizontalLine
45+
* @param {number} index
46+
* @param {number} size
47+
* @return {boolean}
48+
*/
49+
drawHorizontalLine: (index, size) => {
50+
return (index === 0 || index === 1 || index === size);
51+
}
52+
}
53+
54+
let result = table(specData, config);
55+
56+
logger.info('Failed / skipped test report');
57+
logger.info(result);
58+
59+
if (failedSpecs) reject(1); // specs failed, send exitCode as 1
60+
resolve(0); // No Specs failed, maybe skipped, but not failed, send exitCode as 0
61+
});
62+
}
63+
64+
exports.failedSpecsDetails = failedSpecsDetails;

bin/helpers/syncRunner.js

Lines changed: 2 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const Config = require("./config"),
44
Constants = require("./constants"),
55
utils = require("./utils"),
66
request = require('request'),
7+
specDetails = require('./sync/failedSpecsDetails'),
78
{ table, getBorderCharacters } = require('table'),
89
chalk = require('chalk');
910

@@ -13,7 +14,7 @@ exports.pollBuildStatus = (bsConfig, buildId) => {
1314
}).then((data) => {
1415
printSpecsRunSummary();
1516
}).then((data) => {
16-
printFailedSpecsDetails(data);
17+
return specDetails.failedSpecsDetails(data);
1718
}).then((successExitCode) => {
1819
return resolveExitCode(successExitCode); // exit code 0
1920
}).catch((nonZeroExitCode) => {
@@ -36,68 +37,6 @@ let printSpecsRunSummary = () => {
3637

3738
};
3839

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.
55-
56-
let failedSpecs = false;
57-
let specResultHeader = Constants.syncCLI.FAILED_SPEC_DETAILS_COL_HEADER.map((col) => {
58-
return chalk.blueBright(col);
59-
});
60-
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: 'left' },
76-
1: { alignment: 'left' },
77-
2: { alignment: 'left' },
78-
3: { alignment: 'left' },
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
98-
});
99-
};
100-
10140
let resolveExitCode = (exitCode) => {
10241
return new Promise((resolve, _reject) => { resolve(exitCode) });
10342
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict';
2+
const chai = require("chai"),
3+
expect = chai.expect,
4+
sinon = require('sinon'),
5+
chaiAsPromised = require("chai-as-promised"),
6+
fs = require('fs');
7+
8+
const specDetails = require('../../../../../bin/helpers/sync/failedSpecsDetails');
9+
10+
describe("failedSpecsDetails", () => {
11+
context("data is empty", () => {
12+
let data = [];
13+
it('returns 0 exit code', () => {
14+
specDetails.failedSpecsDetails(data).then((status) => {
15+
chai.assert.equal(data, 0);
16+
});
17+
});
18+
});
19+
20+
context("data does not have failed specs", () => {
21+
let data = [
22+
{specName: 'spec2.name.js', status: 'Skipped', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'}
23+
];
24+
25+
it("returns 0 exit code", () => {
26+
specDetails.failedSpecsDetails(data).then((status) => {
27+
chai.assert.equal(data, 0);
28+
});
29+
});
30+
});
31+
});

test/unit/bin/helpers/syncRunner.js

Whitespace-only changes.

0 commit comments

Comments
 (0)