diff --git a/bin/commands/runs.js b/bin/commands/runs.js index fb9af132..8f6d0593 100644 --- a/bin/commands/runs.js +++ b/bin/commands/runs.js @@ -54,6 +54,9 @@ module.exports = function run(args) { // run test in headed mode utils.setHeaded(bsConfig, args); + // set the no-wrap + utils.setNoWrap(bsConfig, args); + // Validate browserstack.json values and parallels specified via arguments return capabilityHelper.validate(bsConfig, args).then(function (cypressJson) { @@ -119,7 +122,7 @@ module.exports = function run(args) { utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'build_failed'); }); }).catch(function (err) { - // Zip Upload failed | Local Start failed + // Zip Upload failed | Local Start failed logger.error(err); if(err === Constants.userMessages.LOCAL_START_FAILED){ utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.LOCAL_START_FAILED}`, Constants.messageTypes.ERROR, 'local_start_failed'); diff --git a/bin/helpers/constants.js b/bin/helpers/constants.js index 17eb1afc..157e5650 100644 --- a/bin/helpers/constants.js +++ b/bin/helpers/constants.js @@ -104,7 +104,8 @@ const cliMessages = { LOCAL: "Accepted values: (true | false) - create a local testing connection to let you test staging and localhost websites, or sites behind proxies; learn more at browserstack.com/local-testing", LOCAL_MODE: 'Accepted values: ("always-on" | "on-demand") - if you choose to keep the binary "always-on", it will speed up your tests by keeping the Local connection warmed up in the background; otherwise, you can choose to have it spawn and killed for every build', LOCAL_IDENTIFIER: "Accepted values: String - assign an identifier to your Local process instance", - LOCAL_CONFIG_FILE: "Accepted values: String - path to local config-file to your Local process instance. Learn more at https://www.browserstack.com/local-testing/binary-params" + LOCAL_CONFIG_FILE: "Accepted values: String - path to local config-file to your Local process instance. Learn more at https://www.browserstack.com/local-testing/binary-params", + SYNC_NO_WRAP: "Wrap the spec names in --sync mode in case of smaller terminal window size pass --no-wrap" }, COMMON: { DISABLE_USAGE_REPORTING: "Disable usage reporting", diff --git a/bin/helpers/sync/syncSpecsLogs.js b/bin/helpers/sync/syncSpecsLogs.js index 6893ad49..8d42616d 100644 --- a/bin/helpers/sync/syncSpecsLogs.js +++ b/bin/helpers/sync/syncSpecsLogs.js @@ -13,7 +13,9 @@ let specSummary = { "specs": [], "duration": null } - +let noWrap = false; +let terminalWidth = (process.stdout.columns) * 0.9; +let lineSeparator = "\n" + "-".repeat(terminalWidth); let getOptions = (auth, build_id) => { return { @@ -31,14 +33,25 @@ let getOptions = (auth, build_id) => { } let getTableConfig = () => { + let centerWidth = Math.ceil(terminalWidth * 0.01), + leftWidth = Math.floor(terminalWidth * 0.75), + colWidth = Math.floor(terminalWidth * 0.2); + + // Do not autosize on terminal's width if no-wrap provided + if (noWrap) { + centerWidth = 1; + leftWidth = 100; + colWidth = 30; + } + return { border: getBorderConfig(), columns: { - 1: {alignment: 'center', width: 1}, - 2: {alignment: 'left', width: 100} + 1: {alignment: 'center', width: centerWidth}, + 2: {alignment: 'left', width: leftWidth} }, columnDefault: { - width: 30, + width: colWidth, }, columnCount: 3, }; @@ -67,7 +80,16 @@ let getBorderConfig = () => { } } +let setNoWrapParams = () => { + noWrap = (process.env.SYNC_NO_WRAP && (process.env.SYNC_NO_WRAP === 'true')); + // Do not show the separator based on terminal width if no-wrap provided. + if (noWrap) { + lineSeparator = "\n--------------------------------------------------------------------------------"; + } +}; + let printSpecsStatus = (bsConfig, buildDetails) => { + setNoWrapParams(); return new Promise((resolve, reject) => { options = getOptions(bsConfig.auth, buildDetails.build_id) tableConfig = getTableConfig(); @@ -81,7 +103,7 @@ let printSpecsStatus = (bsConfig, buildDetails) => { whileProcess(callback) }, function(err, result) { // when loop ends - logger.info("\n--------------------------------------------------------------------------------") + logger.info(lineSeparator); specSummary.duration = endTime - startTime resolve(specSummary) } @@ -139,7 +161,7 @@ let showSpecsStatus = (data) => { let printInitialLog = () => { logger.info(`\n${Constants.syncCLI.LOGS.INIT_LOG}`) - logger.info("--------------------------------------------------------------------------------") + logger.info(lineSeparator); n = Constants.syncCLI.INITIAL_DELAY_MULTIPLIER } diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index ad02fd64..fbf9e8a4 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -571,6 +571,14 @@ exports.setHeaded = (bsConfig, args) => { } }; +exports.setNoWrap = (_bsConfig, args) => { + if (args.noWrap === true || this.searchForOption('--no-wrap')) { + process.env.SYNC_NO_WRAP = true; + } else { + process.env.SYNC_NO_WRAP = false; + } +} + exports.getNumberOfSpecFiles = (bsConfig, args, cypressJson) => { let testFolderPath = cypressJson.integrationFolder || Constants.DEFAULT_CYPRESS_SPEC_PATH; let globSearchPattern = this.sanitizeSpecsPattern(bsConfig.run_settings.specs) || `${testFolderPath}/**/*.+(${Constants.specFileTypes.join("|")})`; diff --git a/bin/runner.js b/bin/runner.js index 30586293..1a53b058 100755 --- a/bin/runner.js +++ b/bin/runner.js @@ -221,6 +221,11 @@ var argv = yargs 'local-config-file': { describe: Constants.cliMessages.RUN.LOCAL_CONFIG_FILE, type: "string" + }, + 'no-wrap': { + default: false, + describe: Constants.cliMessages.RUN.SYNC_NO_WRAP, + type: "boolean" } }) .help('help') diff --git a/test/unit/bin/commands/runs.js b/test/unit/bin/commands/runs.js index e1a17365..cf7e874c 100644 --- a/test/unit/bin/commands/runs.js +++ b/test/unit/bin/commands/runs.js @@ -101,6 +101,7 @@ describe("runs", () => { setLocalStub = sandbox.stub(); setLocalIdentifierStub = sandbox.stub(); setHeadedStub = sandbox.stub(); + setNoWrapStub = sandbox.stub(); deleteResultsStub = sandbox.stub(); setDefaultsStub = sandbox.stub(); setLocalModeStub = sandbox.stub(); @@ -133,6 +134,7 @@ describe("runs", () => { setLocal: setLocalStub, setLocalIdentifier: setLocalIdentifierStub, setHeaded: setHeadedStub, + setNoWrap: setNoWrapStub, deleteResults: deleteResultsStub, setDefaults: setDefaultsStub, setupLocalTesting: setupLocalTestingStub, @@ -169,6 +171,7 @@ describe("runs", () => { sinon.assert.calledOnce(setLocalModeStub); sinon.assert.calledOnce(setLocalConfigFileStub); sinon.assert.calledOnce(setHeadedStub); + sinon.assert.calledOnce(setNoWrapStub); sinon.assert.calledOnce(capabilityValidatorStub); sinon.assert.calledOnce(getErrorCodeFromMsgStub); sinon.assert.calledOnce(setLocalIdentifierStub); @@ -211,6 +214,7 @@ describe("runs", () => { setupLocalTestingStub = sandbox.stub(); setLocalIdentifierStub = sandbox.stub(); setHeadedStub = sandbox.stub(); + setNoWrapStub = sandbox.stub(); deleteResultsStub = sandbox.stub(); getNumberOfSpecFilesStub = sandbox.stub().returns([]); setDefaultsStub = sandbox.stub(); @@ -245,6 +249,7 @@ describe("runs", () => { setupLocalTesting: setupLocalTestingStub, setLocalIdentifier: setLocalIdentifierStub, setHeaded: setHeadedStub, + setNoWrap: setNoWrapStub, deleteResults: deleteResultsStub, setDefaults: setDefaultsStub, getNumberOfSpecFiles: getNumberOfSpecFilesStub, @@ -284,6 +289,7 @@ describe("runs", () => { sinon.assert.calledOnce(setLocalStub); sinon.assert.calledOnce(setLocalIdentifierStub); sinon.assert.calledOnce(setHeadedStub); + sinon.assert.calledOnce(setNoWrapStub); sinon.assert.calledOnce(validateBstackJsonStub); sinon.assert.calledOnce(capabilityValidatorStub); sinon.assert.calledOnce(archiverStub); @@ -330,6 +336,7 @@ describe("runs", () => { setupLocalTestingStub = sandbox.stub(); setLocalIdentifierStub = sandbox.stub(); setHeadedStub = sandbox.stub(); + setNoWrapStub = sandbox.stub(); deleteResultsStub = sandbox.stub(); getNumberOfSpecFilesStub = sandbox.stub().returns([]); setDefaultsStub = sandbox.stub(); @@ -364,6 +371,7 @@ describe("runs", () => { setupLocalTesting: setupLocalTestingStub, setLocalIdentifier: setLocalIdentifierStub, setHeaded: setHeadedStub, + setNoWrap: setNoWrapStub, deleteResults: deleteResultsStub, getNumberOfSpecFiles: getNumberOfSpecFilesStub, setDefaults: setDefaultsStub, @@ -403,6 +411,7 @@ describe("runs", () => { sinon.assert.calledOnce(setLocalStub); sinon.assert.calledOnce(setLocalIdentifierStub); sinon.assert.calledOnce(setHeadedStub); + sinon.assert.calledOnce(setNoWrapStub); sinon.assert.calledOnce(validateBstackJsonStub); sinon.assert.calledOnce(capabilityValidatorStub); sinon.assert.calledOnce(archiverStub); @@ -453,6 +462,7 @@ describe("runs", () => { setupLocalTestingStub = sandbox.stub(); setLocalIdentifierStub = sandbox.stub(); setHeadedStub = sandbox.stub(); + setNoWrapStub = sandbox.stub(); deleteResultsStub = sandbox.stub(); getNumberOfSpecFilesStub = sandbox.stub().returns([]); setDefaultsStub = sandbox.stub(); @@ -488,6 +498,7 @@ describe("runs", () => { setupLocalTesting: setupLocalTestingStub, setLocalIdentifier: setLocalIdentifierStub, setHeaded: setHeadedStub, + setNoWrap: setNoWrapStub, deleteResults: deleteResultsStub, getNumberOfSpecFiles: getNumberOfSpecFilesStub, setDefaults: setDefaultsStub, @@ -538,6 +549,7 @@ describe("runs", () => { sinon.assert.calledOnce(setLocalStub); sinon.assert.calledOnce(setLocalIdentifierStub); sinon.assert.calledOnce(setHeadedStub); + sinon.assert.calledOnce(setNoWrapStub); sinon.assert.calledOnce(archiverStub); sinon.assert.calledOnce(setUsageReportingFlagStub); sinon.assert.calledOnce(zipUploadStub); @@ -593,6 +605,7 @@ describe("runs", () => { setupLocalTestingStub = sandbox.stub(); setLocalIdentifierStub = sandbox.stub(); setHeadedStub = sandbox.stub(); + setNoWrapStub = sandbox.stub(); getNumberOfSpecFilesStub = sandbox.stub().returns([]); setLocalConfigFileStub = sandbox.stub(); }); @@ -626,6 +639,7 @@ describe("runs", () => { setupLocalTesting: setupLocalTestingStub, setLocalIdentifier: setLocalIdentifierStub, setHeaded: setHeadedStub, + setNoWrap: setNoWrapStub, exportResults: exportResultsStub, deleteResults: deleteResultsStub, setDefaults: setDefaultsStub, @@ -679,6 +693,7 @@ describe("runs", () => { sinon.assert.calledOnce(setupLocalTestingStub); sinon.assert.calledOnce(setLocalIdentifierStub); sinon.assert.calledOnce(setHeadedStub); + sinon.assert.calledOnce(setNoWrapStub); sinon.assert.calledOnce(archiverStub); sinon.assert.calledOnce(setUsageReportingFlagStub); sinon.assert.calledOnce(zipUploadStub); diff --git a/test/unit/bin/helpers/sync/syncSpecsLogs.js b/test/unit/bin/helpers/sync/syncSpecsLogs.js index 50d1dd0c..46bec65f 100644 --- a/test/unit/bin/helpers/sync/syncSpecsLogs.js +++ b/test/unit/bin/helpers/sync/syncSpecsLogs.js @@ -92,11 +92,11 @@ describe("syncSpecsLogs", () => { syncSpecsLogs.__set__('getBorderConfig', getBorderConfigStub); let options = getTableConfig(); - expect(options.columnDefault.width).to.equal(30); + expect(options.columnDefault.width).to.equal(Math.floor(((process.stdout.columns) * 0.9) * 0.2)); expect(options.columns[1].alignment).to.equal('center'); expect(options.columns[2].alignment).to.equal('left'); - expect(options.columns[1].width).to.equal(1); - expect(options.columns[2].width).to.equal(100); + expect(options.columns[1].width).to.equal(Math.ceil(((process.stdout.columns) * 0.9) * 0.01)); + expect(options.columns[2].width).to.equal(Math.floor(((process.stdout.columns) * 0.9) * 0.75)); expect(options.columnCount).to.equal(3); expect(getBorderConfigStub.calledOnce).to.be.true; }); diff --git a/test/unit/bin/helpers/utils.js b/test/unit/bin/helpers/utils.js index 5772a34e..82583037 100644 --- a/test/unit/bin/helpers/utils.js +++ b/test/unit/bin/helpers/utils.js @@ -600,6 +600,44 @@ describe('utils', () => { }); }); + describe('setNoWrap', () => { + it('sets the no-wrap to process.env.SYNC_NO_WRAP to true', () => { + let args = { + noWrap: true + }; + let bsConfig = { + run_settings: {} + }; + + utils.setNoWrap(bsConfig, args); + expect(process.env.SYNC_NO_WRAP).to.be.eq('true'); + }); + + it('false to not set the no-wrap to process.env.SYNC_NO_WRAP to true', () => { + let args = { + noWrap: false + }; + let bsConfig = { + run_settings: {} + }; + + utils.setNoWrap(bsConfig, args); + expect(process.env.SYNC_NO_WRAP).to.be.eq('false'); + }); + + it('string to not set the no-wrap to process.env.SYNC_NO_WRAP to true', () => { + let args = { + noWrap: "true" + }; + let bsConfig = { + run_settings: {} + }; + + utils.setNoWrap(bsConfig, args); + expect(process.env.SYNC_NO_WRAP).to.be.eq('false'); + }); + }); + describe('exportResults', () => { it('should export results to log/build_results.txt', () => { sinon.stub(fs, 'writeFileSync').returns(true);