diff --git a/src/index.ts b/src/index.ts index dada21a..26aedf6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,7 +16,6 @@ import { generateSummaryTableHtml } from "./report/generateSummaryTableHtml.js"; import type { JsonSummary } from "./types/JsonSummary.js"; import { writeSummaryToCommit } from "./writeSummaryToComment.js"; import { writeSummaryToPR } from "./writeSummaryToPR.js"; -import { aw } from "vitest/dist/chunks/reporters.C_zwCd4j.js"; type GitHubSummary = typeof core.summary; @@ -61,6 +60,7 @@ const run = async () => { const jsonFinal = await parseVitestJsonFinal(options.jsonFinalPath); const fileTable = generateFileCoverageHtml({ jsonSummary, + jsonSummaryCompare, jsonFinal, fileCoverageMode: options.fileCoverageMode, pullChanges, diff --git a/src/inputs/options.ts b/src/inputs/options.ts index 125b96d..12948f2 100644 --- a/src/inputs/options.ts +++ b/src/inputs/options.ts @@ -8,7 +8,6 @@ import { getPullRequestNumber } from "./getPullRequestNumber"; import { getViteConfigPath } from "./getViteConfigPath"; import { parseCoverageThresholds } from "./parseCoverageThresholds"; import { getCommentOn, type CommentOn } from "./getCommentOn"; -import { report } from "node:process"; type Options = { fileCoverageMode: FileCoverageMode; diff --git a/src/report/generateFileCoverageHtml.test.ts b/src/report/generateFileCoverageHtml.test.ts index 4e363db..fce7ef4 100644 --- a/src/report/generateFileCoverageHtml.test.ts +++ b/src/report/generateFileCoverageHtml.test.ts @@ -244,4 +244,72 @@ describe("generateFileCoverageHtml()", () => { .length; expect(equalSignCount).toBe(4); }); + + it("renders a plus sign and the increased percentage for files with increased coverage", () => { + const jsonSummary: JsonSummary = createMockJsonSummary({ + "file1.ts": createMockCoverageReport({ + branches: createMockReportNumbers({ pct: 70 }), + }), + }); + + const jsonSummaryCompare: JsonSummary = createMockJsonSummary({ + "file1.ts": createMockCoverageReport({ + branches: createMockReportNumbers({ pct: 60 }), + }), + }); + const jsonFinal: JsonFinal = { + ...createJsonFinalEntry("src/exampleFile.ts", [ + { line: 1, covered: true }, + ]), + }; + + const html = generateFileCoverageHtml({ + jsonSummary, + jsonSummaryCompare, + jsonFinal, + fileCoverageMode: FileCoverageMode.All, + pullChanges: [], + commitSHA: "test-sha", + }); + + expect(html).toContain("file1.ts"); + expect(html).toContain(`${icons.increase} +10.00%`); + const equalSignCount = (html.match(new RegExp(icons.increase, "g")) || []) + .length; + expect(equalSignCount).toBe(1); + }); + + it("renders a minus sign and the decreased percentage for files with decreased coverage", () => { + const jsonSummary: JsonSummary = createMockJsonSummary({ + "file1.ts": createMockCoverageReport({ + branches: createMockReportNumbers({ pct: 70 }), + }), + }); + + const jsonSummaryCompare: JsonSummary = createMockJsonSummary({ + "file1.ts": createMockCoverageReport({ + branches: createMockReportNumbers({ pct: 80 }), + }), + }); + const jsonFinal: JsonFinal = { + ...createJsonFinalEntry("src/exampleFile.ts", [ + { line: 1, covered: true }, + ]), + }; + + const html = generateFileCoverageHtml({ + jsonSummary, + jsonSummaryCompare, + jsonFinal, + fileCoverageMode: FileCoverageMode.All, + pullChanges: [], + commitSHA: "test-sha", + }); + + expect(html).toContain("file1.ts"); + expect(html).toContain(`${icons.decrease} -10.00%`); + const equalSignCount = (html.match(new RegExp(icons.decrease, "g")) || []) + .length; + expect(equalSignCount).toBe(1); + }); }); diff --git a/src/report/generateFileCoverageHtml.ts b/src/report/generateFileCoverageHtml.ts index c0551e3..a45e5a8 100644 --- a/src/report/generateFileCoverageHtml.ts +++ b/src/report/generateFileCoverageHtml.ts @@ -9,6 +9,7 @@ import { getUncoveredLinesFromStatements, } from "./getUncoveredLinesFromStatements"; import { icons } from "../icons"; +import { getCompareString } from "./getCompareString"; type FileCoverageInputs = { jsonSummary: JsonSummary; @@ -47,10 +48,10 @@ const generateFileCoverageHtml = ({ return `