From 770b3a815148a17b4774bbbd435eb918cc824418 Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Mon, 19 Dec 2022 04:19:49 +0000 Subject: [PATCH 1/2] Added stateprovider mock implementations --- __tests__/stateProvider.test.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/__tests__/stateProvider.test.ts b/__tests__/stateProvider.test.ts index 315086c..1018a3a 100644 --- a/__tests__/stateProvider.test.ts +++ b/__tests__/stateProvider.test.ts @@ -25,16 +25,15 @@ afterEach(() => { }); test("StateProvider saves states", async () => { + let states = new Map(); const getStateMock = jest .spyOn(core, "getState") - .mockImplementation(name => - jest.requireActual("@actions/core").getState(name) - ); + .mockImplementation(key => states.get(key) || ""); const saveStateMock = jest .spyOn(core, "saveState") .mockImplementation((key, value) => { - return jest.requireActual("@actions/core").saveState(key, value); + states.set(key, value); }); const setOutputMock = jest @@ -48,9 +47,11 @@ test("StateProvider saves states", async () => { const stateProvider: IStateProvider = new StateProvider(); stateProvider.setState("stateKey", "stateValue"); stateProvider.setState(State.CacheMatchedKey, cacheMatchedKey); - stateProvider.getState("stateKey"); - stateProvider.getCacheState(); + let stateValue = stateProvider.getState("stateKey"); + let cacheStateValue = stateProvider.getCacheState(); + expect(stateValue).toBe("stateValue"); + expect(cacheStateValue).toBe(cacheMatchedKey); expect(getStateMock).toHaveBeenCalledTimes(2); expect(saveStateMock).toHaveBeenCalledTimes(2); expect(setOutputMock).toHaveBeenCalledTimes(0); From 3f0eaf49566f95459aacfc07b8840a1f1c2aaae2 Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Mon, 19 Dec 2022 04:23:16 +0000 Subject: [PATCH 2/2] Linting errors fixed --- __tests__/stateProvider.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/__tests__/stateProvider.test.ts b/__tests__/stateProvider.test.ts index 1018a3a..255b5fb 100644 --- a/__tests__/stateProvider.test.ts +++ b/__tests__/stateProvider.test.ts @@ -25,7 +25,7 @@ afterEach(() => { }); test("StateProvider saves states", async () => { - let states = new Map(); + const states = new Map(); const getStateMock = jest .spyOn(core, "getState") .mockImplementation(key => states.get(key) || ""); @@ -47,8 +47,8 @@ test("StateProvider saves states", async () => { const stateProvider: IStateProvider = new StateProvider(); stateProvider.setState("stateKey", "stateValue"); stateProvider.setState(State.CacheMatchedKey, cacheMatchedKey); - let stateValue = stateProvider.getState("stateKey"); - let cacheStateValue = stateProvider.getCacheState(); + const stateValue = stateProvider.getState("stateKey"); + const cacheStateValue = stateProvider.getCacheState(); expect(stateValue).toBe("stateValue"); expect(cacheStateValue).toBe(cacheMatchedKey);