From 1423d0a478405d68f972f99408d1c41e9b3b538a Mon Sep 17 00:00:00 2001 From: sverweij Date: Sat, 24 Dec 2022 11:33:12 +0100 Subject: [PATCH] bugfix(report): improves instability alignment in metrics reporter some locales put a space between the number and the percentage sign. The max width of the I column didn't account for that - resulting in misalignment between 3 and < 3 number percentages --- src/report/metrics.js | 7 +++---- test/report/metrics/metrics.spec.mjs | 10 +++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/report/metrics.js b/src/report/metrics.js index c6414c3b4..0342fb78f 100644 --- a/src/report/metrics.js +++ b/src/report/metrics.js @@ -3,7 +3,7 @@ const chalk = require("chalk"); const utl = require("./utl"); const DECIMAL_BASE = 10; -const METRIC_WIDTH = 4; +const METRIC_WIDTH = 5; const COMPONENT_HEADER = "name"; function getHeader(pMaxNameWidth) { @@ -11,7 +11,7 @@ function getHeader(pMaxNameWidth) { METRIC_WIDTH + 1 )} ${"Ca".padStart(METRIC_WIDTH + 1)} ${"Ce".padStart( METRIC_WIDTH + 1 - )} ${"I (%)".padEnd(METRIC_WIDTH + 1)}`; + )} ${"I (%)".padStart(METRIC_WIDTH + 1)}`; } function getDemarcationLine(pMaxNameWidth) { @@ -19,7 +19,7 @@ function getDemarcationLine(pMaxNameWidth) { METRIC_WIDTH + 1 )} ${"-".repeat(METRIC_WIDTH + 1)} ${"-".repeat( METRIC_WIDTH + 1 - )} ${"-".repeat(METRIC_WIDTH + 1)}`; + )} ${"-".repeat(METRIC_WIDTH + 1)}`; } function getMetricsTable(pMetrics, pMaxNameWidth) { @@ -39,7 +39,6 @@ function getMetricsTable(pMetrics, pMaxNameWidth) { .toString(DECIMAL_BASE) .padStart(METRIC_WIDTH)} ${utl .formatPercentage(instability) - .toString(DECIMAL_BASE) .padStart(METRIC_WIDTH)}` ); } diff --git a/test/report/metrics/metrics.spec.mjs b/test/report/metrics/metrics.spec.mjs index 87f6ff193..65cfa1fc3 100644 --- a/test/report/metrics/metrics.spec.mjs +++ b/test/report/metrics/metrics.spec.mjs @@ -26,7 +26,7 @@ describe("[I] report/metrics", () => { }); expect(lResult.exitCode).to.equal(0); - expect(lResult.output).to.contain("src 1 1 1 50%"); + expect(lResult.output).to.contain("src 1 1 1 50%"); }); it("does not emit folder metrics when asked to hide them", () => { @@ -47,7 +47,7 @@ describe("[I] report/metrics", () => { ); expect(lResult.exitCode).to.equal(0); - expect(lResult.output).to.not.contain("src 1 1 1 50%"); + expect(lResult.output).to.not.contain("src 1 1 1 50%"); }); it("emits module metrics (sorted by instability by default)", () => { @@ -77,7 +77,7 @@ describe("[I] report/metrics", () => { expect(lResult.exitCode).to.equal(0); expect(lResult.output).to.contain( - `src/mies.js 1 1 1 50%${EOL}src/aap.js 1 1 3 25%${EOL}src/noot.js` + `src/mies.js 1 1 1 50%${EOL}src/aap.js 1 1 3 25%${EOL}src/noot.js` ); }); @@ -111,7 +111,7 @@ describe("[I] report/metrics", () => { expect(lResult.exitCode).to.equal(0); expect(lResult.output).to.contain( - `src/aap.js 1 1 3 25%${EOL}src/mies.js 1 1 1 50%${EOL}src/noot.js` + `src/aap.js 1 1 3 25%${EOL}src/mies.js 1 1 1 50%${EOL}src/noot.js` ); }); @@ -145,7 +145,7 @@ describe("[I] report/metrics", () => { expect(lResult.exitCode).to.equal(0); expect(lResult.output).to.not.contain( - `src/mies.js 1 1 1 50${EOL}src/aap.js 1 1 3 25%${EOL}src/noot.js` + `src/mies.js 1 1 1 50%${EOL}src/aap.js 1 1 3 25%${EOL}src/noot.js` ); });