diff --git a/bin/helpers/config.js b/bin/helpers/config.js index d1684936..967f1617 100644 --- a/bin/helpers/config.js +++ b/bin/helpers/config.js @@ -13,7 +13,9 @@ if(config.env !== "production") { } config.cypress_v1 = `${config.rails_host}/automate/cypress/v1`; +config.cypress_v2 = `${config.rails_host}/automate/cypress/v2`; config.buildUrl = `${config.cypress_v1}/builds/`; +config.buildUrlV2 = `${config.cypress_v2}/builds/`; config.buildStopUrl = `${config.cypress_v1}/builds/stop/`; config.checkMd5sum = `${config.cypress_v1}/md5sumcheck/`; config.getInitialDetails = `${config.cypress_v1}/get_initial_details/`; diff --git a/bin/helpers/sync/specsSummary.js b/bin/helpers/sync/specsSummary.js index 80bcc4c1..6b6ad746 100644 --- a/bin/helpers/sync/specsSummary.js +++ b/bin/helpers/sync/specsSummary.js @@ -33,7 +33,8 @@ let printSpecsRunSummary = (data, machines, customErrorsToPrint) => { }); logger.info(`Total tests: ${summary.total}, passed: ${summary.passed}, failed: ${summary.failed}, skipped: ${summary.skipped}, passed_with_skipped: ${summary.passed_with_skipped}, pending: ${summary.pending}`); - logger.info(`Done in ${data.duration/1000} seconds using ${machines} machines\n`); + logger.info(`Done in ${data.duration} seconds using ${data.parallels} machines\n`); + winstonlogger.debug(`CLI calculated duration is ${data.cliDuration/1000}`); if (customErrorsToPrint && customErrorsToPrint.length > 0) { for (const error of customErrorsToPrint) { diff --git a/bin/helpers/sync/syncSpecsLogs.js b/bin/helpers/sync/syncSpecsLogs.js index 437371d4..5f93504f 100644 --- a/bin/helpers/sync/syncSpecsLogs.js +++ b/bin/helpers/sync/syncSpecsLogs.js @@ -14,6 +14,8 @@ let specSummary = { "buildError": null, "specs": [], "duration": null, + "parallels": null, + "cliDuration": null, "customErrorsToPrint": [] } @@ -24,7 +26,7 @@ if (!isNaN(terminalWidth)) lineSeparator = "\n" + "-".repeat(terminalWidth); let getOptions = (auth, build_id) => { return { - url: `${config.buildUrl}${build_id}`, + url: `${config.buildUrlV2}${build_id}`, auth: { user: auth.username, password: auth.access_key @@ -120,7 +122,7 @@ let printSpecsStatus = (bsConfig, buildDetails, rawArgs, buildReportData) => { } } logger.info(lineSeparator); - specSummary.duration = endTime - startTime + specSummary.cliDuration = endTime - startTime resolve(specSummary); } ); @@ -147,7 +149,7 @@ let whileProcess = (whilstCallback) => { switch (response.statusCode) { case 202: // get data here and print it n = 2 - showSpecsStatus(body); + showSpecsStatus(body, 202); return setTimeout(whilstCallback, timeout * n, null); case 204: // No data available, wait for some time and ask again n = 1 @@ -155,7 +157,7 @@ let whileProcess = (whilstCallback) => { case 200: // Build is completed. whileLoop = false; endTime = Date.now(); - showSpecsStatus(body); + showSpecsStatus(body, 200); return specSummary.exitCode == Constants.BUILD_FAILED_EXIT_CODE ? whilstCallback({ status: 204, message: "No specs ran in the build"} ) : whilstCallback(null, body); default: @@ -169,9 +171,9 @@ let getStackTraceUrl = () => { return specSummary.buildError } -let showSpecsStatus = (data) => { +let showSpecsStatus = (data, statusCode) => { let specData = JSON.parse(data); - specData.forEach(specDetails => { + specData["specData"].forEach(specDetails => { if (specDetails.type === Constants.CYPRESS_CUSTOM_ERRORS_TO_PRINT_KEY) { addCustomErrorToPrint(specDetails); } else { @@ -190,6 +192,17 @@ let showSpecsStatus = (data) => { } } }); + if ( statusCode != 200 ) return; + // Below block is for printing build details, return if non 200 status code + if ("buildData" in specData) { + const buildDetails = specData.buildData; + const totalDuration = (utils.isUndefined(buildDetails.duration)) ? "-" : buildDetails.duration.total_duration + const parallels = (utils.isUndefined(buildDetails.parallels)) ? "-" : buildDetails.parallels + specSummary.duration = totalDuration; + specSummary.parallels = parallels; + } else { + logger.debug(`Build details not sent`) + } } let printInitialLog = () => { diff --git a/test/unit/bin/helpers/sync/specSummary.js b/test/unit/bin/helpers/sync/specSummary.js index 084ead97..7e30bc67 100644 --- a/test/unit/bin/helpers/sync/specSummary.js +++ b/test/unit/bin/helpers/sync/specSummary.js @@ -29,7 +29,7 @@ describe("printSpecsRunSummary", () => { }); context("with data", () => { - let time = 6000, + let time = 6, machines = 2, specs = [ {specName: 'spec2.name.js', status: 'Failed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'}, @@ -40,6 +40,7 @@ describe("printSpecsRunSummary", () => { data = { specs: specs, duration: time, + parallels: machines, exitCode: 0 }; @@ -48,14 +49,14 @@ describe("printSpecsRunSummary", () => { specSummary.printSpecsRunSummary(data, machines); sinon.assert.calledWith(loggerInfoSpy, 'Total tests: 4, passed: 1, failed: 2, skipped: 1, passed_with_skipped: 0, pending: 0'); - sinon.assert.calledWith(loggerInfoSpy, `Done in ${time / 1000} seconds using ${machines} machines\n`); + sinon.assert.calledWith(loggerInfoSpy, `Done in ${data.duration} seconds using ${data.parallels} machines\n`); loggerInfoSpy.restore(); }); }); context("with custom error data", () => { - let time = 6000, + let time = 6, machines = 2, specs = [ {specName: 'spec2.name.js', status: 'Failed', combination: 'Win 10 / Chrome 78', sessionId: '3d3rdf3r...'}, @@ -66,6 +67,7 @@ describe("printSpecsRunSummary", () => { data = { specs: specs, duration: time, + parallels: machines, exitCode: 0 }, customErrorsToPrint = [ @@ -78,7 +80,8 @@ describe("printSpecsRunSummary", () => { specSummary.printSpecsRunSummary(data, machines, customErrorsToPrint); sinon.assert.calledWith(loggerInfoSpy, 'Total tests: 4, passed: 1, failed: 2, skipped: 1, passed_with_skipped: 0, pending: 0'); - sinon.assert.calledWith(loggerInfoSpy, `Done in ${time / 1000} seconds using ${machines} machines\n`); + sinon.assert.calledWith(loggerInfoSpy, `Done in ${data.duration} seconds using ${data.parallels} machines\n`); + sinon.assert.calledWith(loggerWarnSpy, `custom error message`); loggerInfoSpy.restore(); diff --git a/test/unit/bin/helpers/sync/syncSpecsLogs.js b/test/unit/bin/helpers/sync/syncSpecsLogs.js index d3e338e6..e19a10c2 100644 --- a/test/unit/bin/helpers/sync/syncSpecsLogs.js +++ b/test/unit/bin/helpers/sync/syncSpecsLogs.js @@ -80,7 +80,7 @@ describe("syncSpecsLogs", () => { it('should return proper request option for polling', () => { let options = getOptions(auth, build_id); - expect(options.url).to.equal(`${config.buildUrl}${build_id}`); + expect(options.url).to.equal(`${config.buildUrlV2}${build_id}`); expect(options.auth.user).to.equal(auth.username); expect(options.auth.password).to.equal(auth.access_key); expect(options.headers["Content-Type"]).to.equal("application/json"); @@ -93,6 +93,8 @@ describe("syncSpecsLogs", () => { "buildError": null, "specs": [], "duration": null, + "parallels": null, + "cliDuration": null, "customErrorsToPrint": [ { id: "custom_error_1", type: "custom_errors_to_print", level: "warn", should_be_unique: true, message: "custom error message" } ] @@ -216,35 +218,38 @@ describe("syncSpecsLogs", () => { context("showSpecsStatus", () => { const showSpecsStatus = syncSpecsLogs.__get__("showSpecsStatus"); + const buildCreatedStatusCode = 202 + const buildRunningStatusCode = 204 + const buildCompletedStatusCode = 200 it('should not print initial log for running specs when it is the 1st polling response', () => { - let data = JSON.stringify(["created"]) + let data = JSON.stringify({ "specData": ["created"], "buildData": {"duration": "NA", "parallels": "NA"}}) var printInitialLog = sandbox.stub(); syncSpecsLogs.__set__('printInitialLog', printInitialLog); - showSpecsStatus(data); + showSpecsStatus(data, buildCreatedStatusCode); expect(printInitialLog.calledOnce).to.be.false; }); it('should print spec details when spec related data is sent in polling response', () => { let specResult = JSON.stringify({"path": "path"}) - let data = JSON.stringify([specResult]) + let data = JSON.stringify({ "specData": [specResult], "buildData": {"duration": "NA", "parallels": "NA"}}) var printSpecData = sandbox.stub(); syncSpecsLogs.__set__('printSpecData', printSpecData); - showSpecsStatus(data); + showSpecsStatus(data, buildRunningStatusCode); expect(printSpecData.calledOnce).to.be.true; }); it('should print initial and spec details when spec related data is sent in polling response', () => { let specResult = JSON.stringify({"path": "path"}) syncSpecsLogs.__set__('buildStarted', false) - let data = JSON.stringify(["created", specResult]) + let data = JSON.stringify({ "specData": [specResult], "buildData": {"duration": "NA", "parallels": "NA"}}) var printSpecData = sandbox.stub(); syncSpecsLogs.__set__('printSpecData', printSpecData); var printInitialLog = sandbox.stub(); syncSpecsLogs.__set__('printInitialLog', printInitialLog); - showSpecsStatus(data); + showSpecsStatus(data, buildCreatedStatusCode); expect(printSpecData.calledOnce).to.be.true; expect(printInitialLog.calledOnce).to.be.true; }); @@ -253,14 +258,14 @@ describe("syncSpecsLogs", () => { let specResult = JSON.stringify({"path": "path"}) let customError = { id: "custom_error_1", type: "custom_errors_to_print", level: "warn", should_be_unique: true, message: "custom error message" } syncSpecsLogs.__set__('buildStarted', false) - let data = JSON.stringify(["created", specResult, customError]) + let data = JSON.stringify({ "specData": ["created", specResult, customError], "buildData": {"duration": "NA", "parallels": "NA"}}) var printSpecData = sandbox.stub(); syncSpecsLogs.__set__('printSpecData', printSpecData); var printInitialLog = sandbox.stub(); syncSpecsLogs.__set__('printInitialLog', printInitialLog); var addCustomErrorToPrint = sandbox.stub(); syncSpecsLogs.__set__('addCustomErrorToPrint', addCustomErrorToPrint); - showSpecsStatus(data); + showSpecsStatus(data, buildRunningStatusCode); expect(printSpecData.calledOnce).to.be.true; expect(printInitialLog.calledOnce).to.be.true; expect(addCustomErrorToPrint.calledOnce).to.be.true; @@ -307,7 +312,7 @@ describe("syncSpecsLogs", () => { expect(tableStream.calledOnce).to.be.true; expect(whileProcess.calledOnce).to.be.false; expect(specSummary.specs).deep.to.equal([]) - expect(specSummary.duration).to.eql(endTime - startTime); + expect(specSummary.cliDuration).to.eql(endTime - startTime); }); }); @@ -322,7 +327,7 @@ describe("syncSpecsLogs", () => { expect(getTableConfig.calledOnce).to.be.true; expect(tableStream.calledOnce).to.be.true; expect(whileProcess.callCount).to.eql(3); - expect(specSummary.duration).to.eql(endTime - startTime); + expect(specSummary.cliDuration).to.eql(endTime - startTime); }); }); });