Skip to content

Commit 1ec2908

Browse files
committed
Add test cases for part 2
1 parent deff51d commit 1ec2908

File tree

5 files changed

+435
-49
lines changed

5 files changed

+435
-49
lines changed

bin/helpers/constants.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
const syncCLI = {
2-
FAILED_SPEC_DETAILS_COL_HEADER: ['Spec', 'Status', 'Browser', 'BrowserStack Session ID']
2+
FAILED_SPEC_DETAILS_COL_HEADER: ['Spec', 'Status', 'Browser', 'BrowserStack Session ID'],
3+
LOGS: {
4+
INIT_LOG: "Running Tests: ..."
5+
},
6+
INITIAL_DELAY_MULTIPLIER: 10
37
};
48

59
const userMessages = {

bin/helpers/sync/failedSpecsDetails.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ let failedSpecsDetails = (data) => {
2929
let specData = [specResultHeader]; // 2-D array
3030

3131
data.forEach((spec) => {
32+
if (spec.status.toLowerCase() === 'passed') {
33+
return;
34+
}
3235
if (spec.status && spec.status.toLowerCase() === 'failed' && !failedSpecs)
3336
failedSpecs = true;
3437

bin/helpers/sync/syncSpecsLogs.js

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const request = require("request"),
44
utils = require("../utils"),
55
logger = require("../logger").syncCliLogger,
66
async = require('async'),
7+
Constants = require("../constants"),
78
tableStream = require('table').createStream,
89
chalk = require('chalk');
910

@@ -30,26 +31,7 @@ let getOptions = (auth, build_id) => {
3031

3132
let getTableConfig = () => {
3233
return {
33-
border: {
34-
topBody: `-`,
35-
topJoin: ``,
36-
topLeft: ``,
37-
topRight: ``,
38-
39-
bottomBody: `-`,
40-
bottomJoin: ``,
41-
bottomLeft: ``,
42-
bottomRight: ``,
43-
44-
bodyLeft: ``,
45-
bodyRight: ``,
46-
bodyJoin: ``,
47-
48-
joinBody: ``,
49-
joinLeft: ``,
50-
joinRight: ``,
51-
joinJoin: ``
52-
},
34+
border: getBorderConfig(),
5335
singleLine: true,
5436
columns: {
5537
0: { alignment: 'right' }
@@ -61,33 +43,52 @@ let getTableConfig = () => {
6143
};
6244
}
6345

46+
let getBorderConfig = () => {
47+
return {
48+
topBody: `-`,
49+
topJoin: ``,
50+
topLeft: ``,
51+
topRight: ``,
52+
53+
bottomBody: `-`,
54+
bottomJoin: ``,
55+
bottomLeft: ``,
56+
bottomRight: ``,
57+
58+
bodyLeft: ``,
59+
bodyRight: ``,
60+
bodyJoin: ``,
61+
62+
joinBody: ``,
63+
joinLeft: ``,
64+
joinRight: ``,
65+
joinJoin: ``
66+
}
67+
}
68+
6469
let printSpecsStatus = (bsConfig, buildDetails) => {
6570
return new Promise((resolve, reject) => {
6671
options = getOptions(bsConfig.auth, buildDetails.build_id)
6772
tableConfig = getTableConfig();
6873
stream = tableStream(tableConfig);
6974

7075
async.whilst(
71-
function() {
76+
function() { // condition for loop
7277
return whileLoop;
7378
},
74-
function(callback) {
79+
function(callback) { // actual loop
7580
whileProcess(callback)
7681
},
77-
function(err, result) {
78-
if (err) {
79-
reject(err)
80-
} else {
81-
specSummary.duration = endTime - startTime
82-
logger.info();
83-
resolve(specSummary)
84-
}
82+
function(err, result) { // when loop ends
83+
specSummary.duration = endTime - startTime
84+
logger.info();
85+
resolve(specSummary)
8586
}
8687
);
8788
});
8889
};
8990

90-
function whileProcess(whilstCallback) {
91+
let whileProcess = (whilstCallback) => {
9192
request.post(options, function(error, response, body) {
9293
if (error) {
9394
return whilstCallback(error);
@@ -107,10 +108,6 @@ function whileProcess(whilstCallback) {
107108
return whilstCallback(null, body);
108109
default:
109110
whileLoop = false;
110-
whileTries -= 1;
111-
if (whileTries === 0) {
112-
return whilstCallback({ status: 504, message: "Tries limit reached" }); //Gateway Timeout
113-
}
114111
return whilstCallback({ status: response.statusCode, message: body });
115112
}
116113
});
@@ -120,33 +117,40 @@ let showSpecsStatus = (data) => {
120117
let specData = JSON.parse(data);
121118
specData.forEach(specDetails => {
122119
if (specDetails == "created") {
123-
startTime = Date.now();
124-
logger.info("Running Tests: ...")
125-
n = 10
120+
printInitialLog();
126121
} else {
127122
try {
128-
specDetails = JSON.parse(specDetails)
129-
printSpecData(specDetails)
123+
printSpecData(JSON.parse(specDetails))
130124
} catch (error) {
131125
}
132126
}
133127
});
134128
}
135129

130+
let printInitialLog = () => {
131+
startTime = Date.now();
132+
logger.info(Constants.syncCLI.LOGS.INIT_LOG)
133+
n = Constants.syncCLI.INITIAL_DELAY_MULTIPLIER
134+
}
135+
136136
let printSpecData = (data) => {
137137
let combination = getCombinationName(data["spec"]);
138-
let specName = data["path"]
139138
let status = getStatus(data["spec"]["status"]);
139+
writeToTable(combination, data["path"], status)
140+
addSpecToSummary(data["path"], data["spec"]["status"], combination, data["session_id"])
141+
}
140142

143+
let writeToTable = (combination, specName, status) => {
141144
stream.write([combination + ":", `${specName} ${status}`]);
145+
}
142146

143-
// for part 3
144-
// Format: {specName: 'spec1.failed.js', status: 'Failed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'},
147+
let addSpecToSummary = (specName, status, combination, session_id) => {
148+
// Format for part 3: {specName: 'spec1.failed.js', status: 'Failed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'},
145149
specSummary["specs"].push({
146150
"specName": specName,
147-
"status": data["spec"]["status"],
151+
"status": status,
148152
"combination": combination,
149-
"sessionId": data["session_id"]
153+
"sessionId": session_id
150154
})
151155
}
152156

test/unit/bin/helpers/sync/specSummary.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var specSummary = require('../../../../../bin/helpers/sync/specsSummary');
1010

1111
describe("printSpecsRunSummary", () => {
1212
context("data is empty", () => {
13-
let data = [], time = '2 minutes', machines = 2;
13+
let data = [], time = 6000, machines = 2;
1414
it('returns passed specs data', () => {
1515
return specSummary.printSpecsRunSummary(data, time, machines).then((specsData) => {
1616
expect(data).to.equal(specsData);
@@ -19,7 +19,7 @@ describe("printSpecsRunSummary", () => {
1919
});
2020

2121
context("with data", () => {
22-
let time = '2 minutes',
22+
let time = 6000,
2323
machines = 2,
2424
data = [
2525
{specName: 'spec2.name.js', status: 'Failed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'},
@@ -33,7 +33,7 @@ describe("printSpecsRunSummary", () => {
3333

3434
specSummary.printSpecsRunSummary(data, time, machines);
3535
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`);
36+
sinon.assert.calledWith(loggerInfoSpy, `Done in ${time / 1000} seconds using ${machines} machines\n`);
3737

3838
loggerInfoSpy.restore();
3939
});

0 commit comments

Comments
 (0)