diff --git a/__tests__/comments.test.ts b/__tests__/comments.test.ts index 481e576..42eada4 100644 --- a/__tests__/comments.test.ts +++ b/__tests__/comments.test.ts @@ -1,13 +1,12 @@ import * as github from "@actions/github"; -import * as core from "@actions/core"; import { GitHub } from "@actions/github/lib/utils.js"; import { commentOnPullRequest, deleteOldComments } from "../src/github/comments.js"; import { watermark } from "../src/templates/commentTemplate.js"; import { beforeEach, describe, expect, it, Mock, vi } from "vitest"; +import * as core from "@actions/core"; vi.mock("@actions/github"); vi.mock("@actions/core"); - describe("deleteOldComments", () => { const mockOctokit = { rest: { @@ -20,11 +19,6 @@ describe("deleteOldComments", () => { beforeEach(() => { vi.clearAllMocks(); - Object.defineProperty(core, "summary", { - value: { addRaw: vi.fn(), write: vi.fn() }, - writable: true, - configurable: true - }); }); @@ -88,13 +82,7 @@ describe("commentOnPullRequest", () => { beforeEach(() => { vi.clearAllMocks(); (github.getOctokit as Mock).mockReturnValue(mockOctokit); - (core.getInput as Mock).mockReturnValue("token"); github.context.payload = { pull_request: { number: 1 } }; - Object.defineProperty(core, "summary", { - value: { addRaw: vi.fn(), write: vi.fn() }, - writable: true, - configurable: true - }); Object.defineProperty(github.context, "repo", { value: { owner: "owner", repo: "repo" }, writable: true @@ -102,6 +90,7 @@ describe("commentOnPullRequest", () => { }); it("should create a comment on pull request", async () => { + (core.getInput as Mock).mockReturnValue("token"); await commentOnPullRequest("Test comment"); expect(mockOctokit.rest.issues.createComment).toHaveBeenCalledWith({ @@ -122,7 +111,6 @@ describe("commentOnPullRequest", () => { it("should throw an error if github-token is missing", async () => { (core.getInput as Mock).mockReturnValue(""); - await expect(commentOnPullRequest("Test comment")).rejects.toThrow( "Could not add a comment to pull request because github-token is missing!" ); diff --git a/__tests__/package.test.ts b/__tests__/package.test.ts index 5e9c8c5..648c9e8 100644 --- a/__tests__/package.test.ts +++ b/__tests__/package.test.ts @@ -4,7 +4,6 @@ import fs from "node:fs"; import path from "node:path"; import { describe, expect, it, Mock, vi, beforeEach } from "vitest"; -vi.mock("@actions/core"); vi.mock("execa"); vi.mock("node:fs"); vi.mock("node:path"); diff --git a/__tests__/parser.test.ts b/__tests__/parser.test.ts index 1d529f6..8d01ad0 100644 --- a/__tests__/parser.test.ts +++ b/__tests__/parser.test.ts @@ -1,11 +1,11 @@ import { parseAnalysisOutput, compareAnalysisResults } from "../src/helpers/parser.js"; -import * as core from "@actions/core"; 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("@actions/core"); vi.mock("node:fs"); +vi.spyOn(core, "setFailed"); describe("parseAnalysisOutput", () => { const resultPath = "vmd-analysis.json"; @@ -13,11 +13,6 @@ describe("parseAnalysisOutput", () => { beforeEach(() => { vi.clearAllMocks(); - Object.defineProperty(core, "summary", { - value: { addRaw: vi.fn(), write: vi.fn() }, - writable: true, - configurable: true - }); }); diff --git a/__tests__/utils.test.ts b/__tests__/utils.test.ts index dfd8e25..7b551a5 100644 --- a/__tests__/utils.test.ts +++ b/__tests__/utils.test.ts @@ -6,7 +6,6 @@ import { describe, expect, it, Mock, vi } from "vitest"; vi.mock("@actions/core"); vi.mock("@actions/github"); - describe("isPullRequest", () => { it("should return true if the context is a pull request", () => { github.context.payload = { pull_request: {number: 1} };