From d037e0f9db13615cb21d3284d713018eb9940520 Mon Sep 17 00:00:00 2001 From: tnicola Date: Sun, 3 Dec 2023 15:08:44 +0100 Subject: [PATCH] Flexible column width based on spec path length --- lib/cli.js | 4 ++-- lib/test-suites.js | 13 ++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/cli.js b/lib/cli.js index 5e75ccf..f616e8c 100755 --- a/lib/cli.js +++ b/lib/cli.js @@ -6,7 +6,7 @@ const path = require('path'); const fs = require('fs-extra'); const { settings } = require('./settings'); -const { getTestSuitePaths, distributeTestsByWeight } = require('./test-suites'); +const { getTestSuitePaths, distributeTestsByWeight, getMaxPathLenghtFrom } = require('./test-suites'); const { formatTime, generateWeightsFile, @@ -55,7 +55,7 @@ async function start() { let table = new Table({ head: ['Spec', 'Time', 'Tests', 'Passing', 'Failing', 'Pending'], style: { head: ['blue'] }, - colWidths: [50, 8, 7, 9, 9, 9] + colWidths: [getMaxPathLenghtFrom(testSuitePaths), 10, 10, 10, 10, 10] }); let totalTests = 0; diff --git a/lib/test-suites.js b/lib/test-suites.js index f63f758..af73aca 100644 --- a/lib/test-suites.js +++ b/lib/test-suites.js @@ -58,6 +58,16 @@ async function getTestSuitePaths() { return fileList; } +function getMaxPathLenghtFrom(testSuitePaths) { + let maxLength = 10; + + for(let path of testSuitePaths){ + maxLength = Math.max(maxLength, path.length); + } + + return maxLength + 3; +} + function distributeTestsByWeight(testSuitePaths) { let specWeights = {}; try { @@ -101,5 +111,6 @@ function distributeTestsByWeight(testSuitePaths) { module.exports = { getTestSuitePaths, - distributeTestsByWeight + distributeTestsByWeight, + getMaxPathLenghtFrom };