diff --git a/src/report/generateFileCoverageHtml.test.ts b/src/report/generateFileCoverageHtml.test.ts index ef7758c..4e363db 100644 --- a/src/report/generateFileCoverageHtml.test.ts +++ b/src/report/generateFileCoverageHtml.test.ts @@ -11,6 +11,7 @@ import { createMockReportNumbers, } from "../types/JsonSummaryMockFactory"; import { generateFileCoverageHtml } from "./generateFileCoverageHtml"; +import { icons } from "../icons"; const workspacePath = process.cwd(); describe("generateFileCoverageHtml()", () => { @@ -30,9 +31,11 @@ describe("generateFileCoverageHtml()", () => { const html = generateFileCoverageHtml({ jsonSummary, + jsonSummaryCompare: undefined, jsonFinal: {}, fileCoverageMode: FileCoverageMode.All, pullChanges: [], + commitSHA: "test-sha", }); const firstTableLine = getTableLine(1, html); @@ -50,9 +53,11 @@ describe("generateFileCoverageHtml()", () => { const html = generateFileCoverageHtml({ jsonSummary, + jsonSummaryCompare: undefined, jsonFinal: {}, fileCoverageMode: FileCoverageMode.All, pullChanges: [relativeChangedFilePath], + commitSHA: "test-sha", }); expect(getTableLine(1, html)).toContain("Changed Files"); @@ -69,9 +74,11 @@ describe("generateFileCoverageHtml()", () => { const html = generateFileCoverageHtml({ jsonSummary, + jsonSummaryCompare: undefined, jsonFinal: {}, fileCoverageMode: FileCoverageMode.All, pullChanges: [changedFileName], + commitSHA: "test-sha", }); expect(html).not.toContain("Unchanged Files"); @@ -84,9 +91,11 @@ describe("generateFileCoverageHtml()", () => { const html = generateFileCoverageHtml({ jsonSummary, + jsonSummaryCompare: undefined, jsonFinal: {}, fileCoverageMode: FileCoverageMode.Changes, pullChanges: [], + commitSHA: "test-sha", }); expect(html).toContain("No changed files found."); @@ -104,9 +113,11 @@ describe("generateFileCoverageHtml()", () => { const html = generateFileCoverageHtml({ jsonSummary, + jsonSummaryCompare: undefined, jsonFinal: {}, fileCoverageMode: FileCoverageMode.All, pullChanges: [], + commitSHA: "test-sha", }); const tableLine = getTableLine(2, html); @@ -132,9 +143,11 @@ describe("generateFileCoverageHtml()", () => { const html = generateFileCoverageHtml({ jsonSummary, + jsonSummaryCompare: undefined, jsonFinal, fileCoverageMode: FileCoverageMode.All, pullChanges: [], + commitSHA: "test-sha", }); const tableLine = getTableLine(2, html); @@ -159,8 +172,10 @@ describe("generateFileCoverageHtml()", () => { const html = generateFileCoverageHtml({ jsonSummary, jsonFinal, + jsonSummaryCompare: undefined, fileCoverageMode: FileCoverageMode.All, pullChanges: [], + commitSHA: "test-sha", }); const tableLine = getTableLine(2, html); @@ -187,9 +202,11 @@ describe("generateFileCoverageHtml()", () => { const html = generateFileCoverageHtml({ jsonSummary, + jsonSummaryCompare: undefined, jsonFinal, fileCoverageMode: FileCoverageMode.All, pullChanges: [], + commitSHA: "test-sha", }); const tableLine = getTableLine(2, html); @@ -197,4 +214,34 @@ describe("generateFileCoverageHtml()", () => { expect(tableLine).toContain("#L2"); expect(tableLine).toContain("#L5-L6"); }); + + it("renders an equal sign for files without changes to covergage", () => { + const jsonSummary: JsonSummary = createMockJsonSummary({ + "file1.ts": createMockCoverageReport(), + }); + + const jsonSummaryCompare: JsonSummary = createMockJsonSummary({ + "file1.ts": createMockCoverageReport(), + }); + 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.equal); + const equalSignCount = (html.match(new RegExp(icons.equal, "g")) || []) + .length; + expect(equalSignCount).toBe(4); + }); }); diff --git a/src/report/generateFileCoverageHtml.ts b/src/report/generateFileCoverageHtml.ts index 0c23a29..c0551e3 100644 --- a/src/report/generateFileCoverageHtml.ts +++ b/src/report/generateFileCoverageHtml.ts @@ -2,15 +2,17 @@ import * as path from "node:path"; import { oneLine } from "common-tags"; import { FileCoverageMode } from "../inputs/FileCoverageMode"; import type { JsonFinal } from "../types/JsonFinal"; -import type { JsonSummary } from "../types/JsonSummary"; +import type { CoverageReport, JsonSummary } from "../types/JsonSummary"; import { generateBlobFileUrl } from "./generateFileUrl"; import { type LineRange, getUncoveredLinesFromStatements, } from "./getUncoveredLinesFromStatements"; +import { icons } from "../icons"; type FileCoverageInputs = { jsonSummary: JsonSummary; + jsonSummaryCompare: JsonSummary | undefined; jsonFinal: JsonFinal; fileCoverageMode: FileCoverageMode; pullChanges: string[]; @@ -20,6 +22,7 @@ type FileCoverageInputs = { const workspacePath = process.cwd(); const generateFileCoverageHtml = ({ jsonSummary, + jsonSummaryCompare, jsonFinal, fileCoverageMode, pullChanges, @@ -29,6 +32,9 @@ const generateFileCoverageHtml = ({ const formatFileLine = (filePath: string) => { const coverageSummary = jsonSummary[filePath]; + const coverageSummaryCompare = jsonSummaryCompare + ? jsonSummaryCompare[filePath] + : undefined; const lineCoverage = jsonFinal[filePath]; // LineCoverage might be empty if coverage-final.json was not provided. @@ -41,10 +47,10 @@ const generateFileCoverageHtml = ({ return `