Skip to content

Commit 620c581

Browse files
Merge pull request #163 from browserstack/sync_ci_bug_fix
Fix: Handle dynamic width calculation for CI/CD tests running with --sync
2 parents d94e992 + 01cf990 commit 620c581

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

bin/helpers/constants.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ const syncCLI = {
55
LOGS: {
66
INIT_LOG: "All tests:"
77
},
8-
INITIAL_DELAY_MULTIPLIER: 10
8+
INITIAL_DELAY_MULTIPLIER: 10,
9+
DEFAULT_LINE_SEP: "\n--------------------------------------------------------------------------------",
910
};
1011

1112
const userMessages = {

bin/helpers/sync/syncSpecsLogs.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ let specSummary = {
1515
}
1616
let noWrap = false;
1717
let terminalWidth = (process.stdout.columns) * 0.9;
18-
let lineSeparator = "\n" + "-".repeat(terminalWidth);
18+
let lineSeparator = Constants.syncCLI.DEFAULT_LINE_SEP;
19+
if (!isNaN(terminalWidth)) lineSeparator = "\n" + "-".repeat(terminalWidth);
1920

2021
let getOptions = (auth, build_id) => {
2122
return {
@@ -32,13 +33,13 @@ let getOptions = (auth, build_id) => {
3233
};
3334
}
3435

35-
let getTableConfig = () => {
36-
let centerWidth = Math.ceil(terminalWidth * 0.01),
37-
leftWidth = Math.floor(terminalWidth * 0.75),
38-
colWidth = Math.floor(terminalWidth * 0.2);
36+
let getTableConfig = (termWidth) => {
37+
let centerWidth = Math.ceil(termWidth * 0.01),
38+
leftWidth = Math.floor(termWidth * 0.75),
39+
colWidth = Math.floor(termWidth * 0.2);
3940

4041
// Do not autosize on terminal's width if no-wrap provided
41-
if (noWrap) {
42+
if (noWrap || isNaN(termWidth)) {
4243
centerWidth = 1;
4344
leftWidth = 100;
4445
colWidth = 30;
@@ -84,15 +85,15 @@ let setNoWrapParams = () => {
8485
noWrap = (process.env.SYNC_NO_WRAP && (process.env.SYNC_NO_WRAP === 'true'));
8586
// Do not show the separator based on terminal width if no-wrap provided.
8687
if (noWrap) {
87-
lineSeparator = "\n--------------------------------------------------------------------------------";
88+
lineSeparator = Constants.syncCLI.DEFAULT_LINE_SEP;
8889
}
8990
};
9091

9192
let printSpecsStatus = (bsConfig, buildDetails) => {
9293
setNoWrapParams();
9394
return new Promise((resolve, reject) => {
9495
options = getOptions(bsConfig.auth, buildDetails.build_id)
95-
tableConfig = getTableConfig();
96+
tableConfig = getTableConfig(terminalWidth);
9697
stream = tableStream(tableConfig);
9798

9899
async.whilst(

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ describe("syncSpecsLogs", () => {
9494
var getBorderConfigStub = sandbox.stub();
9595
syncSpecsLogs.__set__('getBorderConfig', getBorderConfigStub);
9696

97-
let options = getTableConfig();
97+
let options = getTableConfig((process.stdout.columns) * 0.9);
9898
expect(options.columnDefault.width).to.equal(Math.floor(((process.stdout.columns) * 0.9) * 0.2));
9999
expect(options.columns[1].alignment).to.equal('center');
100100
expect(options.columns[2].alignment).to.equal('left');
@@ -103,6 +103,20 @@ describe("syncSpecsLogs", () => {
103103
expect(options.columnCount).to.equal(3);
104104
expect(getBorderConfigStub.calledOnce).to.be.true;
105105
});
106+
107+
it('should return proper table config option for spec table if process.stdout.columns is not defined', () => {
108+
var getBorderConfigStub = sandbox.stub();
109+
syncSpecsLogs.__set__('getBorderConfig', getBorderConfigStub);
110+
111+
let options = getTableConfig(NaN);
112+
expect(options.columnDefault.width).to.equal(30);
113+
expect(options.columns[1].alignment).to.equal('center');
114+
expect(options.columns[2].alignment).to.equal('left');
115+
expect(options.columns[1].width).to.equal(1);
116+
expect(options.columns[2].width).to.equal(100);
117+
expect(options.columnCount).to.equal(3);
118+
expect(getBorderConfigStub.calledOnce).to.be.true;
119+
});
106120
});
107121

108122
context("getBorderConfig", () => {

0 commit comments

Comments
 (0)