From 8a55f839aa4b4578e47bdc8a52828637cbb9a454 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Tue, 19 Mar 2024 09:28:12 +0100 Subject: [PATCH] Add test case for process exit Co-authored-by: Bethany --- __tests__/restoreImpl.test.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/__tests__/restoreImpl.test.ts b/__tests__/restoreImpl.test.ts index 8bab894..16f5f72 100644 --- a/__tests__/restoreImpl.test.ts +++ b/__tests__/restoreImpl.test.ts @@ -449,3 +449,19 @@ test("restore with lookup-only set", async () => { ); expect(failedMock).toHaveBeenCalledTimes(0); }); + +test("restore failure with earlyExit should call process exit", async () => { + testUtils.setInput(Inputs.Path, "node_modules"); + const failedMock = jest.spyOn(core, "setFailed"); + const restoreCacheMock = jest.spyOn(cache, "restoreCache"); + const processExitMock = jest.spyOn(process, "exit").mockImplementation(); + + // call restoreImpl with `earlyExit` set to true + await restoreImpl(new StateProvider(), true); + + expect(restoreCacheMock).toHaveBeenCalledTimes(0); + expect(failedMock).toHaveBeenCalledWith( + "Input required and not supplied: key" + ); + expect(processExitMock).toHaveBeenCalledWith(1); +});