Skip to content

Commit 7867925

Browse files
committed
finalized the result and summary printing
1 parent 037e31e commit 7867925

File tree

3 files changed

+179
-60
lines changed

3 files changed

+179
-60
lines changed

bin/helpers/sync/specsSummary.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ let printSpecsRunSummary = (data, time, machines) => {
3030
});
3131

3232
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`);
33+
logger.info(`Done in ${time/1000} seconds using ${machines} machines\n`);
3434

3535
resolve(data);
3636
})

bin/helpers/sync/syncSpecsLogs.js

Lines changed: 151 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,168 @@
1-
'use strict';
2-
const request = require('request'),
3-
config = require('../config'),
4-
utils = require('../utils'),
5-
logger = require("../logger").syncCliLogger;
6-
7-
let printSpecsStatus = (bsConfig, buildId) => {
8-
new Promise((resolve, reject) => {
9-
poll(data, 2000, 10000).then(resolve(data));
10-
});
11-
}
12-
13-
let poll = (interval, timeout) => {
14-
data = []
1+
"use strict";
2+
const request = require("request"),
3+
config = require("../config"),
4+
utils = require("../utils"),
5+
logger = require("../logger").syncCliLogger,
6+
async = require('async'),
7+
tableStream = require('table').createStream,
8+
chalk = require('chalk');
159

16-
return pollRecursive()
17-
.timeout(timeout)
18-
.catch(Promise.TimeoutError, function () {
19-
return false;
20-
});
10+
let whileLoop = true, whileTries = 40, options, timeout = 3000, n = 10, tableConfig, stream, startTime, endTime;
11+
let specSummary = {
12+
"specs": [],
13+
"duration": null
2114
}
2215

23-
let pollRecursive = () => {
24-
return signal() ? Promise.resolve(true) : Promise.delay(interval).then(pollRecursive);
25-
}
2616

27-
let makeReqest = () => {
28-
let backOffFactor = 3; // 3 seconds
29-
let options = {
30-
url: `${config.buildUrl}${buildId}`,
17+
let getOptions = (auth, build_id) => {
18+
return {
19+
url: `${config.buildUrl}${build_id}`,
3120
auth: {
32-
user: bsConfig.auth.username,
33-
password: bsConfig.auth.access_key
21+
user: auth.username,
22+
password: auth.access_key
3423
},
3524
headers: {
36-
'Content-Type': 'application/json',
37-
"User-Agent": utils.getUserAgent(),
25+
"Content-Type": "application/json",
26+
"User-Agent": utils.getUserAgent()
3827
}
39-
}
40-
request.post(options, function (err, resp, body) {
41-
if (err) {
42-
reject(err);
43-
} else {
44-
try {
45-
data = JSON.parse(body);
46-
} catch (error) {
47-
data = null;
48-
}
49-
if (resp.statusCode != 202) {
50-
if (data) {
51-
reject(`${Constants.userMessages.BUILD_FAILED} Error: ${build.message}`);
28+
};
29+
}
30+
31+
let getTableConfig = () => {
32+
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+
},
53+
singleLine: true,
54+
columns: {
55+
0: { alignment: 'right' }
56+
},
57+
columnDefault: {
58+
width: 50
59+
},
60+
columnCount: 2
61+
};
62+
}
63+
64+
let printSpecsStatus = (bsConfig, buildDetails) => {
65+
return new Promise((resolve, reject) => {
66+
options = getOptions(bsConfig.auth, buildDetails.build_id)
67+
tableConfig = getTableConfig();
68+
stream = tableStream(tableConfig);
69+
70+
async.whilst(
71+
function() {
72+
return whileLoop;
73+
},
74+
function(callback) {
75+
whileProcess(callback)
76+
},
77+
function(err, result) {
78+
if (err) {
79+
reject(err)
5280
} else {
53-
reject(Constants.userMessages.BUILD_FAILED);
81+
specSummary.duration = endTime - startTime
82+
logger.info();
83+
resolve(specSummary)
5484
}
55-
} else {
56-
resolve(build);
5785
}
58-
resolve(build);
86+
);
87+
});
88+
};
89+
90+
function whileProcess(whilstCallback) {
91+
request.post(options, function(error, response, body) {
92+
if (error) {
93+
return whilstCallback(error);
94+
}
95+
switch (response.statusCode) {
96+
case 202: // get data here and print it
97+
n = 2
98+
showSpecsStatus(body);
99+
return setTimeout(whilstCallback, timeout * n, null);
100+
case 204: // No data available, wait for some time and ask again
101+
n = 1
102+
return setTimeout(whilstCallback, timeout * n, null);
103+
case 200: // Build is completed.
104+
whileLoop = false;
105+
endTime = Date.now();
106+
showSpecsStatus(body);
107+
return whilstCallback(null, body);
108+
default:
109+
whileLoop = false;
110+
whileTries -= 1;
111+
if (whileTries === 0) {
112+
return whilstCallback({ status: 504, message: "Tries limit reached" }); //Gateway Timeout
113+
}
114+
return whilstCallback({ status: response.statusCode, message: body });
115+
}
116+
});
117+
}
59118

119+
let showSpecsStatus = (data) => {
120+
let specData = JSON.parse(data);
121+
specData.forEach(specDetails => {
122+
if (specDetails == "created") {
123+
startTime = Date.now();
124+
logger.info("Running Tests: ...")
125+
n = 10
126+
} else {
127+
try {
128+
specDetails = JSON.parse(specDetails)
129+
printSpecData(specDetails)
130+
} catch (error) {
131+
}
60132
}
61133
});
62134
}
63135

136+
let printSpecData = (data) => {
137+
let combination = getCombinationName(data["spec"]);
138+
let specName = data["path"]
139+
let status = getStatus(data["spec"]["status"]);
140+
141+
stream.write([combination + ":", `${specName} ${status}`]);
142+
143+
// for part 3
144+
// Format: {specName: 'spec1.failed.js', status: 'Failed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'},
145+
specSummary["specs"].push({
146+
"specName": specName,
147+
"status": data["spec"]["status"],
148+
"combination": combination,
149+
"sessionId": data["session_id"]
150+
})
151+
}
152+
153+
let getCombinationName = (spec) => {
154+
return `${spec["os"]} ${spec["osVersion"]} / ${spec["browser"]} ${spec["browserVersion"]}`
155+
}
156+
157+
let getStatus = (status) => {
158+
switch(status) {
159+
case "passed":
160+
return chalk.green("✔");
161+
case "failed":
162+
return chalk.red("✘");
163+
default:
164+
return chalk.blue(`[${status}]`);
165+
}
166+
}
167+
64168
exports.printSpecsStatus = printSpecsStatus;

bin/helpers/syncRunner.js

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,34 @@ const Config = require("./config"),
1111
chalk = require('chalk');
1212

1313
exports.pollBuildStatus = (bsConfig, buildDetails) => {
14-
logBuildDetails(bsConfig, buildDetails);
15-
syncSpecsLogs.printSpecsStatus(bsConfig, buildDetails).then((data) => {
16-
return specsSummary.printSpecsRunSummary(data.specs, data.time, data.machines);
17-
}).then((data) => {
18-
return specDetails.failedSpecsDetails(data);
19-
}).then((successExitCode) => {
20-
return resolveExitCode(successExitCode); // exit code 0
21-
}).catch((nonZeroExitCode) => {
22-
return resolveExitCode(nonZeroExitCode); // exit code 1
23-
}).finally(() => {
24-
logger.info(Constants.userMessages.BUILD_REPORT_MESSAGE);
25-
logger.info(`${Config.dashboardUrl}${buildDetails.dashboard_url}`);
14+
return new Promise((resolve, reject) => {
15+
logBuildDetails(bsConfig, buildDetails);
16+
syncSpecsLogs.printSpecsStatus(bsConfig, buildDetails).then((data) => {
17+
return specsSummary.printSpecsRunSummary(data.specs, data.duration, buildDetails.machines);
18+
}).then((data) => {
19+
return specDetails.failedSpecsDetails(data);
20+
}).then((successExitCode) => {
21+
resolve(successExitCode); // exit code 0
22+
}).catch((nonZeroExitCode) => {
23+
resolve(nonZeroExitCode); // exit code 1
24+
}).finally(() => {
25+
logger.info(Constants.userMessages.BUILD_REPORT_MESSAGE);
26+
logger.info(`${Config.dashboardUrl}${buildDetails.dashboard_url}`);
27+
});
2628
});
29+
// logBuildDetails(bsConfig, buildDetails);
30+
// syncSpecsLogs.printSpecsStatus(bsConfig, buildDetails).then((data) => {
31+
// return specsSummary.printSpecsRunSummary(data.specs, data.duration, buildDetails.machines);
32+
// }).then((data) => {
33+
// return specDetails.failedSpecsDetails(data);
34+
// }).then((successExitCode) => {
35+
// return resolveExitCode(successExitCode); // exit code 0
36+
// }).catch((nonZeroExitCode) => {
37+
// return resolveExitCode(nonZeroExitCode); // exit code 1
38+
// }).finally(() => {
39+
// logger.info(Constants.userMessages.BUILD_REPORT_MESSAGE);
40+
// logger.info(`${Config.dashboardUrl}${buildDetails.dashboard_url}`);
41+
// });
2742
};
2843

2944
let logBuildDetails = (bsConfig, buildDetails) => {

0 commit comments

Comments
 (0)