Skip to content

Fix: Handle dynamic width calculation for CI/CD tests running with --sync #163

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 2 commits into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion bin/helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const syncCLI = {
LOGS: {
INIT_LOG: "All tests:"
},
INITIAL_DELAY_MULTIPLIER: 10
INITIAL_DELAY_MULTIPLIER: 10,
DEFAULT_LINE_SEP: "\n--------------------------------------------------------------------------------",
};

const userMessages = {
Expand Down
17 changes: 9 additions & 8 deletions bin/helpers/sync/syncSpecsLogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ let specSummary = {
}
let noWrap = false;
let terminalWidth = (process.stdout.columns) * 0.9;
let lineSeparator = "\n" + "-".repeat(terminalWidth);
let lineSeparator = Constants.syncCLI.DEFAULT_LINE_SEP;
if (!isNaN(terminalWidth)) lineSeparator = "\n" + "-".repeat(terminalWidth);

let getOptions = (auth, build_id) => {
return {
Expand All @@ -32,13 +33,13 @@ 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);
let getTableConfig = (termWidth) => {
let centerWidth = Math.ceil(termWidth * 0.01),
leftWidth = Math.floor(termWidth * 0.75),
colWidth = Math.floor(termWidth * 0.2);

// Do not autosize on terminal's width if no-wrap provided
if (noWrap) {
if (noWrap || isNaN(termWidth)) {
centerWidth = 1;
leftWidth = 100;
colWidth = 30;
Expand Down Expand Up @@ -84,15 +85,15 @@ 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--------------------------------------------------------------------------------";
lineSeparator = Constants.syncCLI.DEFAULT_LINE_SEP;
}
};

let printSpecsStatus = (bsConfig, buildDetails) => {
setNoWrapParams();
return new Promise((resolve, reject) => {
options = getOptions(bsConfig.auth, buildDetails.build_id)
tableConfig = getTableConfig();
tableConfig = getTableConfig(terminalWidth);
stream = tableStream(tableConfig);

async.whilst(
Expand Down
16 changes: 15 additions & 1 deletion test/unit/bin/helpers/sync/syncSpecsLogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe("syncSpecsLogs", () => {
var getBorderConfigStub = sandbox.stub();
syncSpecsLogs.__set__('getBorderConfig', getBorderConfigStub);

let options = getTableConfig();
let options = getTableConfig((process.stdout.columns) * 0.9);
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');
Expand All @@ -103,6 +103,20 @@ describe("syncSpecsLogs", () => {
expect(options.columnCount).to.equal(3);
expect(getBorderConfigStub.calledOnce).to.be.true;
});

it('should return proper table config option for spec table if process.stdout.columns is not defined', () => {
var getBorderConfigStub = sandbox.stub();
syncSpecsLogs.__set__('getBorderConfig', getBorderConfigStub);

let options = getTableConfig(NaN);
expect(options.columnDefault.width).to.equal(30);
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.columnCount).to.equal(3);
expect(getBorderConfigStub.calledOnce).to.be.true;
});
});

context("getBorderConfig", () => {
Expand Down