Skip to content

Commit 6c86641

Browse files
authored
Merge pull request #67 from browserstack/sync-cli-part-3
Sync CLI Part 3
2 parents daea598 + d3e58a6 commit 6c86641

File tree

3 files changed

+97
-1
lines changed

3 files changed

+97
-1
lines changed

bin/helpers/sync/specsSummary.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
const logger = require("../logger").syncCliLogger;
2+
3+
/**
4+
*
5+
* @param {Array.<{specName: string, status: string, combination: string, sessionId: string}>} data
6+
* @param {String} time
7+
* @param {Number} machines
8+
* @returns {Promise.resolve || Promise.reject}
9+
*/
10+
// Example:
11+
// [
12+
// {specName: 'spec1.failed.js', status: 'Failed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'},
13+
// {specName: 'spec2.name.js', status: 'Skipped', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'},
14+
// {specName: 'spec3.network.js', status: 'Failed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'},
15+
// {specName: 'spec6.utils.js', status: 'Failed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'},
16+
// {specName: 'spec8.alias.js', status: 'Skipped', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'}
17+
// ]
18+
//
19+
let printSpecsRunSummary = (data, time, machines) => {
20+
return new Promise((resolve, _reject) => {
21+
let summary = {
22+
total: 0,
23+
failed: 0,
24+
passed: 0,
25+
skipped: 0
26+
};
27+
28+
data.forEach((spec) => {
29+
specSummaryCount(summary, spec.status.toLowerCase());
30+
});
31+
32+
logger.info(`Total tests: ${summary.total}, passed: ${summary.passed}, failed: ${summary.failed}, skipped: ${summary.skipped}`);
33+
logger.info(`Done in ${time} using ${machines} machines\n`);
34+
35+
resolve(data);
36+
})
37+
};
38+
39+
let specSummaryCount = (summary, status) => {
40+
switch (status) {
41+
case 'failed':
42+
summary.failed++;
43+
break;
44+
case 'skipped':
45+
summary.skipped++;
46+
break;
47+
case 'passed':
48+
summary.passed++;
49+
break;
50+
}
51+
summary.total++;
52+
};
53+
54+
exports.printSpecsRunSummary = printSpecsRunSummary;

bin/helpers/syncRunner.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ const Config = require("./config"),
55
utils = require("./utils"),
66
request = require('request'),
77
specDetails = require('./sync/failedSpecsDetails'),
8+
specsSummary = require('./sync/specsSummary'),
89
{ table, getBorderCharacters } = require('table'),
910
chalk = require('chalk');
1011

1112
exports.pollBuildStatus = (bsConfig, buildId) => {
1213
logBuildDetails().then((data) => {
1314
printSpecsStatus();
1415
}).then((data) => {
15-
printSpecsRunSummary();
16+
return specsSummary.printSpecsRunSummary(data.specs, data.time, data.machines);
1617
}).then((data) => {
1718
return specDetails.failedSpecsDetails(data);
1819
}).then((successExitCode) => {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use strict';
2+
const chai = require("chai"),
3+
sinon = require("sinon"),
4+
expect = chai.expect,
5+
chaiAsPromised = require("chai-as-promised");
6+
7+
chai.use(chaiAsPromised);
8+
var logger = require("../../../../../bin/helpers/logger").syncCliLogger;
9+
var specSummary = require('../../../../../bin/helpers/sync/specsSummary');
10+
11+
describe("printSpecsRunSummary", () => {
12+
context("data is empty", () => {
13+
let data = [], time = '2 minutes', machines = 2;
14+
it('returns passed specs data', () => {
15+
return specSummary.printSpecsRunSummary(data, time, machines).then((specsData) => {
16+
expect(data).to.equal(specsData);
17+
});
18+
});
19+
});
20+
21+
context("with data", () => {
22+
let time = '2 minutes',
23+
machines = 2,
24+
data = [
25+
{specName: 'spec2.name.js', status: 'Failed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'},
26+
{specName: 'spec2.name.js', status: 'Skipped', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'},
27+
{specName: 'spec2.name.js', status: 'Failed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'},
28+
{specName: 'spec2.name.js', status: 'Passed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'}
29+
];
30+
31+
it('returns passed specs data', () => {
32+
var loggerInfoSpy = sinon.spy(logger, 'info');
33+
34+
specSummary.printSpecsRunSummary(data, time, machines);
35+
sinon.assert.calledWith(loggerInfoSpy, 'Total tests: 4, passed: 1, failed: 2, skipped: 1');
36+
sinon.assert.calledWith(loggerInfoSpy, `Done in ${time} using ${machines} machines\n`);
37+
38+
loggerInfoSpy.restore();
39+
});
40+
});
41+
});

0 commit comments

Comments
 (0)