Skip to content

text resizing based on the terminal column's width for sync logs #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion bin/commands/runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down Expand Up @@ -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');
Expand Down
3 changes: 2 additions & 1 deletion bin/helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
29 changes: 23 additions & 6 deletions bin/helpers/sync/syncSpecsLogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ let specSummary = {
"specs": [],
"duration": null
}

let noWrap = (process.env.SYNC_NO_WRAP && (process.env.SYNC_NO_WRAP === 'true'));
let terminalWidth = (process.stdout.columns) * 0.9;
let lineSeparator = "\n" + "-".repeat(terminalWidth);
// Do not show the separator based on terminal width if no-wrap provided.
if (noWrap) {
lineSeparator = "\n--------------------------------------------------------------------------------";
}

let getOptions = (auth, build_id) => {
return {
Expand All @@ -31,14 +37,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,
};
Expand Down Expand Up @@ -81,7 +98,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)
}
Expand Down Expand Up @@ -139,7 +156,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
}

Expand Down
8 changes: 8 additions & 0 deletions bin/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,14 @@ exports.setHeaded = (bsConfig, args) => {
}
};

exports.setNoWrap = (_bsConfig, args) => {
if (args.noWrap === true) {
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("|")})`;
Expand Down
5 changes: 5 additions & 0 deletions bin/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ var argv = yargs
'local-config-file': {
describe: Constants.cliMessages.RUN.LOCAL_CONFIG_FILE,
type: "string"
},
'no-wrap': {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a default value, type, and alias

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

default: false,
describe: Constants.cliMessages.RUN.SYNC_NO_WRAP,
type: "boolean"
}
})
.help('help')
Expand Down
15 changes: 15 additions & 0 deletions test/unit/bin/commands/runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -133,6 +134,7 @@ describe("runs", () => {
setLocal: setLocalStub,
setLocalIdentifier: setLocalIdentifierStub,
setHeaded: setHeadedStub,
setNoWrap: setNoWrapStub,
deleteResults: deleteResultsStub,
setDefaults: setDefaultsStub,
setupLocalTesting: setupLocalTestingStub,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -245,6 +249,7 @@ describe("runs", () => {
setupLocalTesting: setupLocalTestingStub,
setLocalIdentifier: setLocalIdentifierStub,
setHeaded: setHeadedStub,
setNoWrap: setNoWrapStub,
deleteResults: deleteResultsStub,
setDefaults: setDefaultsStub,
getNumberOfSpecFiles: getNumberOfSpecFilesStub,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -364,6 +371,7 @@ describe("runs", () => {
setupLocalTesting: setupLocalTestingStub,
setLocalIdentifier: setLocalIdentifierStub,
setHeaded: setHeadedStub,
setNoWrap: setNoWrapStub,
deleteResults: deleteResultsStub,
getNumberOfSpecFiles: getNumberOfSpecFilesStub,
setDefaults: setDefaultsStub,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -488,6 +498,7 @@ describe("runs", () => {
setupLocalTesting: setupLocalTestingStub,
setLocalIdentifier: setLocalIdentifierStub,
setHeaded: setHeadedStub,
setNoWrap: setNoWrapStub,
deleteResults: deleteResultsStub,
getNumberOfSpecFiles: getNumberOfSpecFilesStub,
setDefaults: setDefaultsStub,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
});
Expand Down Expand Up @@ -626,6 +639,7 @@ describe("runs", () => {
setupLocalTesting: setupLocalTestingStub,
setLocalIdentifier: setLocalIdentifierStub,
setHeaded: setHeadedStub,
setNoWrap: setNoWrapStub,
exportResults: exportResultsStub,
deleteResults: deleteResultsStub,
setDefaults: setDefaultsStub,
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions test/unit/bin/helpers/sync/syncSpecsLogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down
38 changes: 38 additions & 0 deletions test/unit/bin/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down