Skip to content

Commit

Permalink
bugfix(report): improves instability alignment in metrics reporter (#707
Browse files Browse the repository at this point in the history
)

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
  • Loading branch information
sverweij committed Dec 24, 2022
1 parent 26295d7 commit fc0404c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
7 changes: 3 additions & 4 deletions src/report/metrics.js
Expand Up @@ -3,23 +3,23 @@ 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) {
return `${COMPONENT_HEADER.padEnd(pMaxNameWidth)} ${"N".padStart(
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) {
return `${"-".repeat(pMaxNameWidth)} ${"-".repeat(
METRIC_WIDTH + 1
)} ${"-".repeat(METRIC_WIDTH + 1)} ${"-".repeat(
METRIC_WIDTH + 1
)} ${"-".repeat(METRIC_WIDTH + 1)}`;
)} ${"-".repeat(METRIC_WIDTH + 1)}`;
}

function getMetricsTable(pMetrics, pMaxNameWidth) {
Expand All @@ -39,7 +39,6 @@ function getMetricsTable(pMetrics, pMaxNameWidth) {
.toString(DECIMAL_BASE)
.padStart(METRIC_WIDTH)} ${utl
.formatPercentage(instability)
.toString(DECIMAL_BASE)
.padStart(METRIC_WIDTH)}`
);
}
Expand Down
10 changes: 5 additions & 5 deletions test/report/metrics/metrics.spec.mjs
Expand Up @@ -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", () => {
Expand All @@ -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)", () => {
Expand Down Expand Up @@ -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`
);
});

Expand Down Expand Up @@ -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`
);
});

Expand Down Expand Up @@ -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`
);
});

Expand Down

0 comments on commit fc0404c

Please sign in to comment.