Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix(report): improves instability alignment in metrics reporter #707

Merged
merged 1 commit into from Dec 24, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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