From 2850cd8f451daa5817e6df237afc7e12599e542f Mon Sep 17 00:00:00 2001 From: Dave Hadka Date: Tue, 29 Sep 2020 10:23:21 -0500 Subject: [PATCH] Fix test --- __tests__/restore.test.ts | 31 +++++++++++++------------------ __tests__/save.test.ts | 22 ++++++++++------------ 2 files changed, 23 insertions(+), 30 deletions(-) diff --git a/__tests__/restore.test.ts b/__tests__/restore.test.ts index cef03a5..f0fde2d 100644 --- a/__tests__/restore.test.ts +++ b/__tests__/restore.test.ts @@ -32,6 +32,8 @@ beforeAll(() => { beforeEach(() => { process.env[Events.Key] = Events.Push; process.env[RefKey] = "refs/heads/feature-branch"; + + jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false); }); afterEach(() => { @@ -54,27 +56,20 @@ test("restore with invalid event outputs warning", async () => { }); test("restore on GHES should no-op", async () => { - try { - process.env["GITHUB_SERVER_URL"] = "http://example.com"; + jest.spyOn(actionUtils, "isGhes").mockImplementation(() => true); - const infoMock = jest.spyOn(core, "info"); - const restoreCacheMock = jest.spyOn(cache, "restoreCache"); - const setCacheHitOutputMock = jest.spyOn( - actionUtils, - "setCacheHitOutput" - ); + const infoMock = jest.spyOn(core, "info"); + const restoreCacheMock = jest.spyOn(cache, "restoreCache"); + const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput"); - await run(); + await run(); - expect(restoreCacheMock).toHaveBeenCalledTimes(0); - expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1); - expect(setCacheHitOutputMock).toHaveBeenCalledWith(false); - expect(infoMock).toHaveBeenCalledWith( - "Cache action is not supported on GHES" - ); - } finally { - process.env["GITHUB_SERVER_URL"] = undefined; - } + expect(restoreCacheMock).toHaveBeenCalledTimes(0); + expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1); + expect(setCacheHitOutputMock).toHaveBeenCalledWith(false); + expect(infoMock).toHaveBeenCalledWith( + "Cache action is not supported on GHES" + ); }); test("restore with no path should fail", async () => { diff --git a/__tests__/save.test.ts b/__tests__/save.test.ts index 6086cf3..301344a 100644 --- a/__tests__/save.test.ts +++ b/__tests__/save.test.ts @@ -44,6 +44,8 @@ beforeAll(() => { beforeEach(() => { process.env[Events.Key] = Events.Push; process.env[RefKey] = "refs/heads/feature-branch"; + + jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false); }); afterEach(() => { @@ -92,21 +94,17 @@ test("save with no primary key in state outputs warning", async () => { }); test("save on GHES should no-op", async () => { - try { - process.env["GITHUB_SERVER_URL"] = "http://example.com"; + jest.spyOn(actionUtils, "isGhes").mockImplementation(() => true); - const infoMock = jest.spyOn(core, "info"); - const saveCacheMock = jest.spyOn(cache, "saveCache"); + const infoMock = jest.spyOn(core, "info"); + const saveCacheMock = jest.spyOn(cache, "saveCache"); - await run(); + await run(); - expect(saveCacheMock).toHaveBeenCalledTimes(0); - expect(infoMock).toHaveBeenCalledWith( - "Cache action is not supported on GHES" - ); - } finally { - process.env["GITHUB_SERVER_URL"] = undefined; - } + expect(saveCacheMock).toHaveBeenCalledTimes(0); + expect(infoMock).toHaveBeenCalledWith( + "Cache action is not supported on GHES" + ); }); test("save with exact match returns early", async () => {