diff --git a/__tests__/commandHandler.test.ts b/__tests__/commandHandler.test.ts index 6b9714ed..7d43d6d2 100644 --- a/__tests__/commandHandler.test.ts +++ b/__tests__/commandHandler.test.ts @@ -3,20 +3,14 @@ import { join } from "path"; import nock from "nock"; import * as core from "@actions/core"; -jest.mock("@actions/core", () => { - return { - debug: jest.fn(), - setFailed: jest.fn(), - setOutput: jest.fn(), - }; -}); - import { context } from "@actions/github"; import { CommandHandler } from "../src/commandHandler"; describe("commandHandler", () => { beforeEach(() => { + jest.spyOn(core, "setOutput"); + context.action = "run1"; context.actor = "test-user"; context.eventName = "issue_comment"; @@ -25,6 +19,10 @@ describe("commandHandler", () => { context.workflow = "Issue comments"; }); + afterEach(() => { + delete process.exitCode; + }); + describe("process", () => { it("should return false when incorrect action", async () => { context.payload = require(join(__dirname, "payloads", "edited.json")); @@ -39,6 +37,7 @@ describe("commandHandler", () => { ); await expect(commandHandler.process()).resolves.toBe(false); + expect(process.exitCode).toBeUndefined(); }); it("should return false when no slash command in comment", async () => { @@ -54,6 +53,7 @@ describe("commandHandler", () => { ); await expect(commandHandler.process()).resolves.toBe(false); + expect(process.exitCode).toBeUndefined(); }); it("should return false when incorrect slash command", async () => { @@ -69,11 +69,10 @@ describe("commandHandler", () => { ); await expect(commandHandler.process()).resolves.toBe(false); + expect(process.exitCode).toBeUndefined(); }); it("should return false when correct slash command but incorrect repo access", async () => { - const mockedSetOutput = core.setOutput as jest.Mock; - context.payload = require(join(__dirname, "payloads", "created.json")); const commandHandler = new CommandHandler( @@ -90,6 +89,7 @@ describe("commandHandler", () => { .reply(200, { permission: "read" }); await expect(commandHandler.process()).resolves.toBe(false); + expect(process.exitCode).toBe(core.ExitCode.Failure); expect(scoped.isDone()).toBe(true); }); @@ -115,6 +115,7 @@ describe("commandHandler", () => { .reply(201); await expect(commandHandler.process()).resolves.toBe(true); + expect(process.exitCode).toBeUndefined(); expect(permissionScope.isDone()).toBe(true); expect(reactionScope.isDone()).toBe(false); @@ -141,6 +142,7 @@ describe("commandHandler", () => { .reply(201); await expect(commandHandler.process()).resolves.toBe(true); + expect(process.exitCode).toBeUndefined(); expect(permissionScope.isDone()).toBe(true); expect(reactionScope.isDone()).toBe(true); @@ -165,6 +167,7 @@ describe("commandHandler", () => { .reply(200, { permission: "write" }); await expect(commandHandler.process()).resolves.toBe(true); + expect(process.exitCode).toBeUndefined(); expect(scoped.isDone()).toBe(true); @@ -187,6 +190,7 @@ describe("commandHandler", () => { ); expect(commandHandler.shouldRunForAction()).toBe(true); + expect(process.exitCode).toBeUndefined(); }); it("returns 'true' when action is 'edited' and allowEdits is 'true'", () => { @@ -202,6 +206,7 @@ describe("commandHandler", () => { ); expect(commandHandler.shouldRunForAction()).toBe(true); + expect(process.exitCode).toBeUndefined(); }); it("returns 'false' when action is 'edited' and allowEdits is 'false'", () => { @@ -217,6 +222,7 @@ describe("commandHandler", () => { ); expect(commandHandler.shouldRunForAction()).toBe(false); + expect(process.exitCode).toBeUndefined(); }); it("returns 'false' when action is 'deleted'", () => { @@ -232,6 +238,7 @@ describe("commandHandler", () => { ); expect(commandHandler.shouldRunForAction()).toBe(false); + expect(process.exitCode).toBeUndefined(); }); it("returns 'false' when action is unknown", () => { @@ -247,6 +254,7 @@ describe("commandHandler", () => { ); expect(commandHandler.shouldRunForAction()).toBe(false); + expect(process.exitCode).toBeUndefined(); }); }); @@ -271,6 +279,7 @@ describe("commandHandler", () => { expect(scoped.isDone()).toBe(true); expect(result).toBe("admin"); + expect(process.exitCode).toBeUndefined(); }); }); @@ -290,6 +299,7 @@ describe("commandHandler", () => { ); await expect(commandHandler.createReaction(123)).resolves.toBe(false); + expect(process.exitCode).toBeUndefined(); }); it("creates reaction if enabled", async () => { @@ -307,6 +317,7 @@ describe("commandHandler", () => { .reply(201); await expect(commandHandler.createReaction(123)).resolves.toBe(true); + expect(process.exitCode).toBeUndefined(); expect(scoped.isDone()).toBe(true); }); diff --git a/src/commandHandler.ts b/src/commandHandler.ts index 9f5ab6e4..4e01a5ac 100644 --- a/src/commandHandler.ts +++ b/src/commandHandler.ts @@ -46,7 +46,7 @@ export class CommandHandler { const commandResults = this.command.checkComment(comment.body); if (!commandResults) { - setFailed("Comment didn't contain a valid slash command"); + debug("Comment didn't contain a valid slash command"); return false; } @@ -89,7 +89,7 @@ export class CommandHandler { return true; } - setFailed("Comment was edited and allow edits is disabled, no action to take"); + debug("Comment was edited and allow edits is disabled, no action to take"); return false; }