Skip to content

Commit 751b75e

Browse files
committed
chore: push specs for CLI
1 parent 3f6cb7a commit 751b75e

File tree

3 files changed

+38
-14
lines changed

3 files changed

+38
-14
lines changed

bin/helpers/sync/syncSpecsLogs.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
"use strict";
2-
3-
const { util } = require("chai");
4-
52
const request = require("request"),
63
config = require("../config"),
74
utils = require("../utils"),

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,14 @@ describe("printSpecsRunSummary", () => {
4545

4646
it('returns passed specs data', () => {
4747
var loggerInfoSpy = sinon.spy(logger, 'info');
48+
var loggerDebugSpy = sinon.spy(logger, 'debug');
4849

4950
specSummary.printSpecsRunSummary(data, machines);
5051
sinon.assert.calledWith(loggerInfoSpy, 'Total tests: 4, passed: 1, failed: 2, skipped: 1, passed_with_skipped: 0, pending: 0');
51-
sinon.assert.calledWith(loggerInfoSpy, `Done in ${time / 1000} seconds using ${machines} machines\n`);
52+
sinon.assert.calledWith(loggerDebugSpy, `CLI calculated duration: ${time / 1000} seconds using ${machines} machines\n`);
5253

5354
loggerInfoSpy.restore();
55+
loggerDebugSpy.restore();
5456
});
5557
});
5658

@@ -74,14 +76,16 @@ describe("printSpecsRunSummary", () => {
7476

7577
it('prints the custom error message along with build details', () => {
7678
var loggerInfoSpy = sinon.spy(logger, 'info');
79+
var loggerDebugSpy = sinon.spy(logger, 'debug');
7780
var loggerWarnSpy = sinon.spy(winstonLogger, 'warn');
7881

7982
specSummary.printSpecsRunSummary(data, machines, customErrorsToPrint);
8083
sinon.assert.calledWith(loggerInfoSpy, 'Total tests: 4, passed: 1, failed: 2, skipped: 1, passed_with_skipped: 0, pending: 0');
81-
sinon.assert.calledWith(loggerInfoSpy, `Done in ${time / 1000} seconds using ${machines} machines\n`);
84+
sinon.assert.calledWith(loggerDebugSpy, `CLI calculated duration: ${time / 1000} seconds using ${machines} machines\n`);
8285
sinon.assert.calledWith(loggerWarnSpy, `custom error message`);
8386

8487
loggerInfoSpy.restore();
88+
loggerDebugSpy.restore();
8589
loggerWarnSpy.restore();
8690
});
8791
});

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

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ describe("syncSpecsLogs", () => {
8080

8181
it('should return proper request option for polling', () => {
8282
let options = getOptions(auth, build_id);
83-
expect(options.url).to.equal(`${config.buildUrl}${build_id}`);
83+
expect(options.url).to.equal(`${config.buildUrlV2}${build_id}`);
8484
expect(options.auth.user).to.equal(auth.username);
8585
expect(options.auth.password).to.equal(auth.access_key);
8686
expect(options.headers["Content-Type"]).to.equal("application/json");
@@ -216,35 +216,38 @@ describe("syncSpecsLogs", () => {
216216

217217
context("showSpecsStatus", () => {
218218
const showSpecsStatus = syncSpecsLogs.__get__("showSpecsStatus");
219+
const buildCreatedStatusCode = 202
220+
const buildRunningStatusCode = 204
221+
const buildCompletedStatusCode = 200
219222

220223
it('should not print initial log for running specs when it is the 1st polling response', () => {
221-
let data = JSON.stringify(["created"])
224+
let data = JSON.stringify({ "specData": ["created"], "buildData": {"duration": "NA", "parallels": "NA"}})
222225
var printInitialLog = sandbox.stub();
223226
syncSpecsLogs.__set__('printInitialLog', printInitialLog);
224227

225-
showSpecsStatus(data);
228+
showSpecsStatus(data, buildCreatedStatusCode);
226229

227230
expect(printInitialLog.calledOnce).to.be.false;
228231
});
229232

230233
it('should print spec details when spec related data is sent in polling response', () => {
231234
let specResult = JSON.stringify({"path": "path"})
232-
let data = JSON.stringify([specResult])
235+
let data = JSON.stringify({ "specData": [specResult], "buildData": {"duration": "NA", "parallels": "NA"}})
233236
var printSpecData = sandbox.stub();
234237
syncSpecsLogs.__set__('printSpecData', printSpecData);
235-
showSpecsStatus(data);
238+
showSpecsStatus(data, buildRunningStatusCode);
236239
expect(printSpecData.calledOnce).to.be.true;
237240
});
238241

239242
it('should print initial and spec details when spec related data is sent in polling response', () => {
240243
let specResult = JSON.stringify({"path": "path"})
241244
syncSpecsLogs.__set__('buildStarted', false)
242-
let data = JSON.stringify(["created", specResult])
245+
let data = JSON.stringify({ "specData": [specResult], "buildData": {"duration": "NA", "parallels": "NA"}})
243246
var printSpecData = sandbox.stub();
244247
syncSpecsLogs.__set__('printSpecData', printSpecData);
245248
var printInitialLog = sandbox.stub();
246249
syncSpecsLogs.__set__('printInitialLog', printInitialLog);
247-
showSpecsStatus(data);
250+
showSpecsStatus(data, buildCreatedStatusCode);
248251
expect(printSpecData.calledOnce).to.be.true;
249252
expect(printInitialLog.calledOnce).to.be.true;
250253
});
@@ -253,18 +256,38 @@ describe("syncSpecsLogs", () => {
253256
let specResult = JSON.stringify({"path": "path"})
254257
let customError = { id: "custom_error_1", type: "custom_errors_to_print", level: "warn", should_be_unique: true, message: "custom error message" }
255258
syncSpecsLogs.__set__('buildStarted', false)
256-
let data = JSON.stringify(["created", specResult, customError])
259+
let data = JSON.stringify({ "specData": ["created", specResult, customError], "buildData": {"duration": "NA", "parallels": "NA"}})
257260
var printSpecData = sandbox.stub();
258261
syncSpecsLogs.__set__('printSpecData', printSpecData);
259262
var printInitialLog = sandbox.stub();
260263
syncSpecsLogs.__set__('printInitialLog', printInitialLog);
261264
var addCustomErrorToPrint = sandbox.stub();
262265
syncSpecsLogs.__set__('addCustomErrorToPrint', addCustomErrorToPrint);
263-
showSpecsStatus(data);
266+
showSpecsStatus(data, buildRunningStatusCode);
264267
expect(printSpecData.calledOnce).to.be.true;
265268
expect(printInitialLog.calledOnce).to.be.true;
266269
expect(addCustomErrorToPrint.calledOnce).to.be.true;
267270
});
271+
272+
it('should add custom error, print initial and spec details when spec related data and duration is sent in polling response', () => {
273+
let specResult = JSON.stringify({"path": "path"})
274+
let customError = { id: "custom_error_1", type: "custom_errors_to_print", level: "warn", should_be_unique: true, message: "custom error message" }
275+
var loggerInfoSpy = sinon.spy(logger, 'info');
276+
syncSpecsLogs.__set__('buildStarted', false)
277+
let data = JSON.stringify({ "specData": ["created", specResult, customError], "buildData": {"duration": {"total_duration": "87"}, "parallels": "2"}})
278+
var printSpecData = sandbox.stub();
279+
syncSpecsLogs.__set__('printSpecData', printSpecData);
280+
var printInitialLog = sandbox.stub();
281+
syncSpecsLogs.__set__('printInitialLog', printInitialLog);
282+
var addCustomErrorToPrint = sandbox.stub();
283+
syncSpecsLogs.__set__('addCustomErrorToPrint', addCustomErrorToPrint);
284+
showSpecsStatus(data, buildCompletedStatusCode);
285+
expect(printSpecData.calledOnce).to.be.true;
286+
expect(printInitialLog.calledOnce).to.be.true;
287+
expect(addCustomErrorToPrint.calledOnce).to.be.true;
288+
sinon.assert.calledWith(loggerInfoSpy, 'Done in 87 seconds with 2 parallels.\n');
289+
loggerInfoSpy.restore();
290+
});
268291
});
269292

270293
context("printSpecsStatus", () => {

0 commit comments

Comments
 (0)