Skip to content

Commit 01cf990

Browse files
Karan NagpalKaran Nagpal
authored andcommitted
Add unit tests and handle NaN
1 parent 0ef7dc5 commit 01cf990

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

bin/helpers/sync/syncSpecsLogs.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ let specSummary = {
1616
let noWrap = false;
1717
let terminalWidth = (process.stdout.columns) * 0.9;
1818
let lineSeparator = Constants.syncCLI.DEFAULT_LINE_SEP;
19-
if (!utils.isUndefined(terminalWidth)) lineSeparator = "\n" + "-".repeat(terminalWidth);
19+
if (!isNaN(terminalWidth)) lineSeparator = "\n" + "-".repeat(terminalWidth);
2020

2121
let getOptions = (auth, build_id) => {
2222
return {
@@ -33,13 +33,13 @@ let getOptions = (auth, build_id) => {
3333
};
3434
}
3535

36-
let getTableConfig = () => {
37-
let centerWidth = Math.ceil(terminalWidth * 0.01),
38-
leftWidth = Math.floor(terminalWidth * 0.75),
39-
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);
4040

4141
// Do not autosize on terminal's width if no-wrap provided
42-
if (noWrap || utils.isUndefined(terminalWidth)) {
42+
if (noWrap || isNaN(termWidth)) {
4343
centerWidth = 1;
4444
leftWidth = 100;
4545
colWidth = 30;
@@ -93,7 +93,7 @@ let printSpecsStatus = (bsConfig, buildDetails) => {
9393
setNoWrapParams();
9494
return new Promise((resolve, reject) => {
9595
options = getOptions(bsConfig.auth, buildDetails.build_id)
96-
tableConfig = getTableConfig();
96+
tableConfig = getTableConfig(terminalWidth);
9797
stream = tableStream(tableConfig);
9898

9999
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)