Skip to content

Commit eb47ede

Browse files
authored
Merge pull request #136 from browserstack/proper_text_in_resized_terminal_windows
text resizing based on the terminal column's width for sync logs
2 parents ec912b5 + 16cd34a commit eb47ede

File tree

8 files changed

+103
-11
lines changed

8 files changed

+103
-11
lines changed

bin/commands/runs.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ module.exports = function run(args) {
5454
// run test in headed mode
5555
utils.setHeaded(bsConfig, args);
5656

57+
// set the no-wrap
58+
utils.setNoWrap(bsConfig, args);
59+
5760
// Validate browserstack.json values and parallels specified via arguments
5861
return capabilityHelper.validate(bsConfig, args).then(function (cypressJson) {
5962

@@ -119,7 +122,7 @@ module.exports = function run(args) {
119122
utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'build_failed');
120123
});
121124
}).catch(function (err) {
122-
// Zip Upload failed | Local Start failed
125+
// Zip Upload failed | Local Start failed
123126
logger.error(err);
124127
if(err === Constants.userMessages.LOCAL_START_FAILED){
125128
utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.LOCAL_START_FAILED}`, Constants.messageTypes.ERROR, 'local_start_failed');

bin/helpers/constants.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ const cliMessages = {
105105
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",
106106
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',
107107
LOCAL_IDENTIFIER: "Accepted values: String - assign an identifier to your Local process instance",
108-
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"
108+
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",
109+
SYNC_NO_WRAP: "Wrap the spec names in --sync mode in case of smaller terminal window size pass --no-wrap"
109110
},
110111
COMMON: {
111112
DISABLE_USAGE_REPORTING: "Disable usage reporting",

bin/helpers/sync/syncSpecsLogs.js

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ let specSummary = {
1313
"specs": [],
1414
"duration": null
1515
}
16-
16+
let noWrap = false;
17+
let terminalWidth = (process.stdout.columns) * 0.9;
18+
let lineSeparator = "\n" + "-".repeat(terminalWidth);
1719

1820
let getOptions = (auth, build_id) => {
1921
return {
@@ -31,14 +33,25 @@ let getOptions = (auth, build_id) => {
3133
}
3234

3335
let getTableConfig = () => {
36+
let centerWidth = Math.ceil(terminalWidth * 0.01),
37+
leftWidth = Math.floor(terminalWidth * 0.75),
38+
colWidth = Math.floor(terminalWidth * 0.2);
39+
40+
// Do not autosize on terminal's width if no-wrap provided
41+
if (noWrap) {
42+
centerWidth = 1;
43+
leftWidth = 100;
44+
colWidth = 30;
45+
}
46+
3447
return {
3548
border: getBorderConfig(),
3649
columns: {
37-
1: {alignment: 'center', width: 1},
38-
2: {alignment: 'left', width: 100}
50+
1: {alignment: 'center', width: centerWidth},
51+
2: {alignment: 'left', width: leftWidth}
3952
},
4053
columnDefault: {
41-
width: 30,
54+
width: colWidth,
4255
},
4356
columnCount: 3,
4457
};
@@ -67,7 +80,16 @@ let getBorderConfig = () => {
6780
}
6881
}
6982

83+
let setNoWrapParams = () => {
84+
noWrap = (process.env.SYNC_NO_WRAP && (process.env.SYNC_NO_WRAP === 'true'));
85+
// Do not show the separator based on terminal width if no-wrap provided.
86+
if (noWrap) {
87+
lineSeparator = "\n--------------------------------------------------------------------------------";
88+
}
89+
};
90+
7091
let printSpecsStatus = (bsConfig, buildDetails) => {
92+
setNoWrapParams();
7193
return new Promise((resolve, reject) => {
7294
options = getOptions(bsConfig.auth, buildDetails.build_id)
7395
tableConfig = getTableConfig();
@@ -81,7 +103,7 @@ let printSpecsStatus = (bsConfig, buildDetails) => {
81103
whileProcess(callback)
82104
},
83105
function(err, result) { // when loop ends
84-
logger.info("\n--------------------------------------------------------------------------------")
106+
logger.info(lineSeparator);
85107
specSummary.duration = endTime - startTime
86108
resolve(specSummary)
87109
}
@@ -139,7 +161,7 @@ let showSpecsStatus = (data) => {
139161

140162
let printInitialLog = () => {
141163
logger.info(`\n${Constants.syncCLI.LOGS.INIT_LOG}`)
142-
logger.info("--------------------------------------------------------------------------------")
164+
logger.info(lineSeparator);
143165
n = Constants.syncCLI.INITIAL_DELAY_MULTIPLIER
144166
}
145167

bin/helpers/utils.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,14 @@ exports.setHeaded = (bsConfig, args) => {
571571
}
572572
};
573573

574+
exports.setNoWrap = (_bsConfig, args) => {
575+
if (args.noWrap === true || this.searchForOption('--no-wrap')) {
576+
process.env.SYNC_NO_WRAP = true;
577+
} else {
578+
process.env.SYNC_NO_WRAP = false;
579+
}
580+
}
581+
574582
exports.getNumberOfSpecFiles = (bsConfig, args, cypressJson) => {
575583
let testFolderPath = cypressJson.integrationFolder || Constants.DEFAULT_CYPRESS_SPEC_PATH;
576584
let globSearchPattern = this.sanitizeSpecsPattern(bsConfig.run_settings.specs) || `${testFolderPath}/**/*.+(${Constants.specFileTypes.join("|")})`;

bin/runner.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@ var argv = yargs
221221
'local-config-file': {
222222
describe: Constants.cliMessages.RUN.LOCAL_CONFIG_FILE,
223223
type: "string"
224+
},
225+
'no-wrap': {
226+
default: false,
227+
describe: Constants.cliMessages.RUN.SYNC_NO_WRAP,
228+
type: "boolean"
224229
}
225230
})
226231
.help('help')

test/unit/bin/commands/runs.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ describe("runs", () => {
101101
setLocalStub = sandbox.stub();
102102
setLocalIdentifierStub = sandbox.stub();
103103
setHeadedStub = sandbox.stub();
104+
setNoWrapStub = sandbox.stub();
104105
deleteResultsStub = sandbox.stub();
105106
setDefaultsStub = sandbox.stub();
106107
setLocalModeStub = sandbox.stub();
@@ -133,6 +134,7 @@ describe("runs", () => {
133134
setLocal: setLocalStub,
134135
setLocalIdentifier: setLocalIdentifierStub,
135136
setHeaded: setHeadedStub,
137+
setNoWrap: setNoWrapStub,
136138
deleteResults: deleteResultsStub,
137139
setDefaults: setDefaultsStub,
138140
setupLocalTesting: setupLocalTestingStub,
@@ -169,6 +171,7 @@ describe("runs", () => {
169171
sinon.assert.calledOnce(setLocalModeStub);
170172
sinon.assert.calledOnce(setLocalConfigFileStub);
171173
sinon.assert.calledOnce(setHeadedStub);
174+
sinon.assert.calledOnce(setNoWrapStub);
172175
sinon.assert.calledOnce(capabilityValidatorStub);
173176
sinon.assert.calledOnce(getErrorCodeFromMsgStub);
174177
sinon.assert.calledOnce(setLocalIdentifierStub);
@@ -211,6 +214,7 @@ describe("runs", () => {
211214
setupLocalTestingStub = sandbox.stub();
212215
setLocalIdentifierStub = sandbox.stub();
213216
setHeadedStub = sandbox.stub();
217+
setNoWrapStub = sandbox.stub();
214218
deleteResultsStub = sandbox.stub();
215219
getNumberOfSpecFilesStub = sandbox.stub().returns([]);
216220
setDefaultsStub = sandbox.stub();
@@ -245,6 +249,7 @@ describe("runs", () => {
245249
setupLocalTesting: setupLocalTestingStub,
246250
setLocalIdentifier: setLocalIdentifierStub,
247251
setHeaded: setHeadedStub,
252+
setNoWrap: setNoWrapStub,
248253
deleteResults: deleteResultsStub,
249254
setDefaults: setDefaultsStub,
250255
getNumberOfSpecFiles: getNumberOfSpecFilesStub,
@@ -284,6 +289,7 @@ describe("runs", () => {
284289
sinon.assert.calledOnce(setLocalStub);
285290
sinon.assert.calledOnce(setLocalIdentifierStub);
286291
sinon.assert.calledOnce(setHeadedStub);
292+
sinon.assert.calledOnce(setNoWrapStub);
287293
sinon.assert.calledOnce(validateBstackJsonStub);
288294
sinon.assert.calledOnce(capabilityValidatorStub);
289295
sinon.assert.calledOnce(archiverStub);
@@ -330,6 +336,7 @@ describe("runs", () => {
330336
setupLocalTestingStub = sandbox.stub();
331337
setLocalIdentifierStub = sandbox.stub();
332338
setHeadedStub = sandbox.stub();
339+
setNoWrapStub = sandbox.stub();
333340
deleteResultsStub = sandbox.stub();
334341
getNumberOfSpecFilesStub = sandbox.stub().returns([]);
335342
setDefaultsStub = sandbox.stub();
@@ -364,6 +371,7 @@ describe("runs", () => {
364371
setupLocalTesting: setupLocalTestingStub,
365372
setLocalIdentifier: setLocalIdentifierStub,
366373
setHeaded: setHeadedStub,
374+
setNoWrap: setNoWrapStub,
367375
deleteResults: deleteResultsStub,
368376
getNumberOfSpecFiles: getNumberOfSpecFilesStub,
369377
setDefaults: setDefaultsStub,
@@ -403,6 +411,7 @@ describe("runs", () => {
403411
sinon.assert.calledOnce(setLocalStub);
404412
sinon.assert.calledOnce(setLocalIdentifierStub);
405413
sinon.assert.calledOnce(setHeadedStub);
414+
sinon.assert.calledOnce(setNoWrapStub);
406415
sinon.assert.calledOnce(validateBstackJsonStub);
407416
sinon.assert.calledOnce(capabilityValidatorStub);
408417
sinon.assert.calledOnce(archiverStub);
@@ -453,6 +462,7 @@ describe("runs", () => {
453462
setupLocalTestingStub = sandbox.stub();
454463
setLocalIdentifierStub = sandbox.stub();
455464
setHeadedStub = sandbox.stub();
465+
setNoWrapStub = sandbox.stub();
456466
deleteResultsStub = sandbox.stub();
457467
getNumberOfSpecFilesStub = sandbox.stub().returns([]);
458468
setDefaultsStub = sandbox.stub();
@@ -488,6 +498,7 @@ describe("runs", () => {
488498
setupLocalTesting: setupLocalTestingStub,
489499
setLocalIdentifier: setLocalIdentifierStub,
490500
setHeaded: setHeadedStub,
501+
setNoWrap: setNoWrapStub,
491502
deleteResults: deleteResultsStub,
492503
getNumberOfSpecFiles: getNumberOfSpecFilesStub,
493504
setDefaults: setDefaultsStub,
@@ -538,6 +549,7 @@ describe("runs", () => {
538549
sinon.assert.calledOnce(setLocalStub);
539550
sinon.assert.calledOnce(setLocalIdentifierStub);
540551
sinon.assert.calledOnce(setHeadedStub);
552+
sinon.assert.calledOnce(setNoWrapStub);
541553
sinon.assert.calledOnce(archiverStub);
542554
sinon.assert.calledOnce(setUsageReportingFlagStub);
543555
sinon.assert.calledOnce(zipUploadStub);
@@ -593,6 +605,7 @@ describe("runs", () => {
593605
setupLocalTestingStub = sandbox.stub();
594606
setLocalIdentifierStub = sandbox.stub();
595607
setHeadedStub = sandbox.stub();
608+
setNoWrapStub = sandbox.stub();
596609
getNumberOfSpecFilesStub = sandbox.stub().returns([]);
597610
setLocalConfigFileStub = sandbox.stub();
598611
});
@@ -626,6 +639,7 @@ describe("runs", () => {
626639
setupLocalTesting: setupLocalTestingStub,
627640
setLocalIdentifier: setLocalIdentifierStub,
628641
setHeaded: setHeadedStub,
642+
setNoWrap: setNoWrapStub,
629643
exportResults: exportResultsStub,
630644
deleteResults: deleteResultsStub,
631645
setDefaults: setDefaultsStub,
@@ -679,6 +693,7 @@ describe("runs", () => {
679693
sinon.assert.calledOnce(setupLocalTestingStub);
680694
sinon.assert.calledOnce(setLocalIdentifierStub);
681695
sinon.assert.calledOnce(setHeadedStub);
696+
sinon.assert.calledOnce(setNoWrapStub);
682697
sinon.assert.calledOnce(archiverStub);
683698
sinon.assert.calledOnce(setUsageReportingFlagStub);
684699
sinon.assert.calledOnce(zipUploadStub);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ describe("syncSpecsLogs", () => {
9292
syncSpecsLogs.__set__('getBorderConfig', getBorderConfigStub);
9393

9494
let options = getTableConfig();
95-
expect(options.columnDefault.width).to.equal(30);
95+
expect(options.columnDefault.width).to.equal(Math.floor(((process.stdout.columns) * 0.9) * 0.2));
9696
expect(options.columns[1].alignment).to.equal('center');
9797
expect(options.columns[2].alignment).to.equal('left');
98-
expect(options.columns[1].width).to.equal(1);
99-
expect(options.columns[2].width).to.equal(100);
98+
expect(options.columns[1].width).to.equal(Math.ceil(((process.stdout.columns) * 0.9) * 0.01));
99+
expect(options.columns[2].width).to.equal(Math.floor(((process.stdout.columns) * 0.9) * 0.75));
100100
expect(options.columnCount).to.equal(3);
101101
expect(getBorderConfigStub.calledOnce).to.be.true;
102102
});

test/unit/bin/helpers/utils.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,44 @@ describe('utils', () => {
600600
});
601601
});
602602

603+
describe('setNoWrap', () => {
604+
it('sets the no-wrap to process.env.SYNC_NO_WRAP to true', () => {
605+
let args = {
606+
noWrap: true
607+
};
608+
let bsConfig = {
609+
run_settings: {}
610+
};
611+
612+
utils.setNoWrap(bsConfig, args);
613+
expect(process.env.SYNC_NO_WRAP).to.be.eq('true');
614+
});
615+
616+
it('false to not set the no-wrap to process.env.SYNC_NO_WRAP to true', () => {
617+
let args = {
618+
noWrap: false
619+
};
620+
let bsConfig = {
621+
run_settings: {}
622+
};
623+
624+
utils.setNoWrap(bsConfig, args);
625+
expect(process.env.SYNC_NO_WRAP).to.be.eq('false');
626+
});
627+
628+
it('string to not set the no-wrap to process.env.SYNC_NO_WRAP to true', () => {
629+
let args = {
630+
noWrap: "true"
631+
};
632+
let bsConfig = {
633+
run_settings: {}
634+
};
635+
636+
utils.setNoWrap(bsConfig, args);
637+
expect(process.env.SYNC_NO_WRAP).to.be.eq('false');
638+
});
639+
});
640+
603641
describe('exportResults', () => {
604642
it('should export results to log/build_results.txt', () => {
605643
sinon.stub(fs, 'writeFileSync').returns(true);

0 commit comments

Comments
 (0)