Skip to content

Commit

Permalink
fix: clear core.summary mock
Browse files Browse the repository at this point in the history
  • Loading branch information
brenoepics committed Sep 29, 2024
1 parent 54642e3 commit d2ee0f6
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 23 deletions.
16 changes: 2 additions & 14 deletions __tests__/comments.test.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -20,11 +19,6 @@ describe("deleteOldComments", () => {

beforeEach(() => {
vi.clearAllMocks();
Object.defineProperty(core, "summary", {
value: { addRaw: vi.fn(), write: vi.fn() },
writable: true,
configurable: true
});
});


Expand Down Expand Up @@ -88,20 +82,15 @@ 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
});
});

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({
Expand All @@ -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!"
);
Expand Down
1 change: 0 additions & 1 deletion __tests__/package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
9 changes: 2 additions & 7 deletions __tests__/parser.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
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";
const mockFileContent = '{"output":[],"codeHealthOutput":[],"reportOutput":{}}';

beforeEach(() => {
vi.clearAllMocks();
Object.defineProperty(core, "summary", {
value: { addRaw: vi.fn(), write: vi.fn() },
writable: true,
configurable: true
});
});


Expand Down
1 change: 0 additions & 1 deletion __tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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} };
Expand Down

0 comments on commit d2ee0f6

Please sign in to comment.