diff --git a/__tests__/commentTemplate.test.ts b/__tests__/commentTemplate.test.ts deleted file mode 100644 index 7f0f8cd..0000000 --- a/__tests__/commentTemplate.test.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { getCommentTemplate, watermark } from "../src/templates/commentTemplate.js"; -import { VMDAnalysis } from "../src/types.js"; -import { describe, expect, it } from "vitest"; - -process.env.GITHUB_REPOSITORY = "brenoepics/vmd-action"; - -describe("getCommentTemplate", () => { - const analysisOutput: VMDAnalysis = { - output: [], - codeHealthOutput: [], - reportOutput: {}, - codeHealth: { - errors: 0, - warnings: 0, - linesCount: 100, - filesCount: 1, - points: 100 - } - }; - - it("should return the correct comment template with artifact", () => { - const artifactId = 1; - const result = getCommentTemplate(analysisOutput, artifactId); - expect(result).toContain(watermark); - expect(result).toContain("Vue Mess Detector Analysis Results"); - expect(result).toContain("Download Full Analysis Details"); - }); - - it("should return the correct comment template without artifact", () => { - const artifactId = undefined; - const result = getCommentTemplate(analysisOutput, artifactId); - expect(result).toContain(watermark); - expect(result).toContain("Vue Mess Detector Analysis Results"); - expect(result).not.toContain("Download Full Analysis Details"); - }); - - it("should return the correct comment template with relative mode", () => { - const artifactId = 1; - const result = getCommentTemplate(analysisOutput, artifactId, true); - expect(result).toContain(watermark); - expect(result).toContain("Vue Mess Detector Analysis Results"); - expect(result).toContain("New Errors"); - expect(result).toContain("New Warnings"); - }); -}); diff --git a/__tests__/parser.test.ts b/__tests__/parser.test.ts deleted file mode 100644 index 8d01ad0..0000000 --- a/__tests__/parser.test.ts +++ /dev/null @@ -1,117 +0,0 @@ -import { parseAnalysisOutput, compareAnalysisResults } from "../src/helpers/parser.js"; -import fs from "node:fs"; -import { VMDAnalysis } from "../src/types.js"; -import { describe, expect, it, vi, beforeEach, Mock } from "vitest"; -import * as core from "@actions/core"; - -vi.mock("node:fs"); -vi.spyOn(core, "setFailed"); - -describe("parseAnalysisOutput", () => { - const resultPath = "vmd-analysis.json"; - const mockFileContent = '{"output":[],"codeHealthOutput":[],"reportOutput":{}}'; - - beforeEach(() => { - vi.clearAllMocks(); - }); - - - it("should parse analysis output successfully", () => { - (fs.readFileSync as Mock).mockReturnValue(mockFileContent); - - const result = parseAnalysisOutput(resultPath); - - expect(result).toEqual({ - output: [], - codeHealthOutput: [], - reportOutput: {} - }); - expect(core.setFailed).not.toHaveBeenCalled(); - }); - - it("should handle error when parsing analysis output", () => { - (fs.readFileSync as Mock).mockImplementation(() => { - throw new Error("Read failed"); - }); - - const result = parseAnalysisOutput(resultPath); - - expect(result).toBeUndefined(); - expect(core.setFailed).toHaveBeenCalledWith("Failed to parse analysis output: Read failed"); - }); -}); - -describe("compareAnalysisResults", () => { - const oldAnalysis: VMDAnalysis = { - output: [], - codeHealthOutput: [], - reportOutput: { - "file1": [{ id: "1", description: "desc1", message: "msg1" }], - "file2": [{ id: "2", description: "desc2", message: "msg2" }] - }, - codeHealth: { - errors: 1, - warnings: 2, - linesCount: 100, - filesCount: 2, - points: 95 - } - }; - - const prBranchAnalysis: VMDAnalysis = { - output: [], - codeHealthOutput: [], - reportOutput: { - "file1": [{ id: "1", description: "desc1", message: "msg1" }], - "file2": [{ id: "3", description: "desc3", message: "msg3" }] - }, - codeHealth: { - errors: 2, - warnings: 3, - linesCount: 150, - filesCount: 3, - points: 90 - } - }; - - it("should return new issues introduced by the pull request branch", () => { - const result = compareAnalysisResults(oldAnalysis, prBranchAnalysis); - - expect(result).toEqual({ - output: [], - codeHealthOutput: [], - reportOutput: { - "file2": [{ id: "3", description: "desc3", message: "msg3" }] - }, - codeHealth: { - errors: 1, - warnings: 1, - linesCount: 50, - filesCount: 1, - points: 95 - } - }); - }); - - it("should return empty new issues if codeHealth is undefined", () => { - const prBranchAnalysisWithoutCodeHealth: VMDAnalysis = { - ...prBranchAnalysis, - codeHealth: undefined - }; - - const result = compareAnalysisResults(oldAnalysis, prBranchAnalysisWithoutCodeHealth); - - expect(result).toEqual({ - output: [], - codeHealthOutput: [], - reportOutput: {}, - codeHealth: { - errors: 0, - warnings: 0, - linesCount: 0, - filesCount: 0, - points: 0 - } - }); - }); -}); diff --git a/__tests__/reportTemplate.test.ts b/__tests__/reportTemplate.test.ts deleted file mode 100644 index fae9b6c..0000000 --- a/__tests__/reportTemplate.test.ts +++ /dev/null @@ -1,88 +0,0 @@ -import { getReportTemplate, renderReport, renderReportsByKey } from "../src/templates/reportTemplate.js"; -import { VMDAnalysis, ReportOutput } from "../src/types.js"; -import { describe, expect, it } from "vitest"; - -describe("getReportTemplate", () => { - const analysisOutput: VMDAnalysis = { - output: [], - codeHealthOutput: [], - reportOutput: { - "file1.ts": [ - { id: "1", description: "desc1", message: "msg1" }, - { id: "2", description: "desc2", message: "msg2" } - ], - "file2.ts": [ - { id: "3", description: "desc3", message: "msg3" } - ] - }, - codeHealth: { - errors: 0, - warnings: 0, - linesCount: 100, - filesCount: 1, - points: 100 - } - }; - - it("should return the correct report template", () => { - const result = getReportTemplate(analysisOutput); - expect(result).toContain("VMD Report"); - expect(result).toContain("file1.ts"); - expect(result).toContain("file2.ts"); - }); - - it("should return an empty string if report is empty", () => { - const emptyAnalysisOutput: VMDAnalysis = { - ...analysisOutput, - reportOutput: {} - }; - const result = getReportTemplate(emptyAnalysisOutput); - expect(result).toBe(""); - }); -}); - -describe("renderReport", () => { - const analysisOutput: { [key: string]: ReportOutput[] | undefined } = { - "file1.ts": [ - { id: "1", description: "desc1", message: "msg1" }, - { id: "2", description: "desc2", message: "msg2" } - ], - "file2.ts": [ - { id: "3", description: "desc3", message: "msg3" } - ] - }; - - it("should return the correct rendered report", () => { - const result = renderReport(analysisOutput); - expect(result).toContain("file1.ts"); - expect(result).toContain("file2.ts"); - expect(result).toContain("1: msg1"); - expect(result).toContain("2: msg2"); - expect(result).toContain("3: msg3"); - }); - - it("should return an empty string if analysis is empty", () => { - const emptyAnalysisOutput: { [key: string]: ReportOutput[] | undefined } = {}; - const result = renderReport(emptyAnalysisOutput); - expect(result).toBe(""); - }); -}); - -describe("renderReportsByKey", () => { - const reportOutput: ReportOutput[] = [ - { id: "1", description: "desc1", message: "msg1" }, - { id: "2", description: "desc2", message: "msg2" } - ]; - - it("should return the correct rendered reports by key", () => { - const result = renderReportsByKey("file1.ts", reportOutput); - expect(result).toContain("file1.ts"); - expect(result).toContain("1: msg1"); - expect(result).toContain("2: msg2"); - }); - - it("should handle relative paths correctly", () => { - const result = renderReportsByKey("/absolute/path/to/file1.ts", reportOutput); - expect(result).toContain("file1.ts"); - }); -});