stateinputprovider with pending test cases fix

This commit is contained in:
Sankalp Kotewar 2023-01-02 07:29:20 +00:00 committed by GitHub
parent 365406cb70
commit 5b7eeecaeb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 53 additions and 28 deletions

View file

@ -11,12 +11,8 @@ jest.mock("@actions/cache");
jest.mock("../src/utils/actionUtils");
beforeAll(() => {
jest.spyOn(core, "getInput").mockImplementation((name, options) => {
return jest.requireActual("@actions/core").getInput(name, options);
});
jest.spyOn(core, "setOutput").mockImplementation((key, value) => {
return jest.requireActual("@actions/core").getInput(key, value);
jest.spyOn(core, "getInput").mockImplementation(name => {
return testUtils.getInput(name);
});
jest.spyOn(actionUtils, "getInputAsArray").mockImplementation(

View file

@ -58,11 +58,17 @@ test("StateProvider saves states", async () => {
});
test("NullStateProvider saves outputs", async () => {
const states = new Map<string, string>();
const getInputMock = jest
.spyOn(core, "getInput")
.mockImplementation(key => states.get(key) || "");
const getStateMock = jest
.spyOn(core, "getState")
.mockImplementation(name =>
jest.requireActual("@actions/core").getState(name)
);
.mockImplementation(key => {
return jest.requireActual("@actions/core").getState(key);
});
const setOutputMock = jest
.spyOn(core, "setOutput")
@ -73,7 +79,7 @@ test("NullStateProvider saves outputs", async () => {
const saveStateMock = jest
.spyOn(core, "saveState")
.mockImplementation((key, value) => {
return jest.requireActual("@actions/core").saveState(key, value);
states.set(key, value);
});
const cacheMatchedKey = "node-cache";
@ -84,6 +90,7 @@ test("NullStateProvider saves outputs", async () => {
nullStateProvider.getCacheState();
expect(getStateMock).toHaveBeenCalledTimes(0);
expect(getInputMock).toHaveBeenCalledTimes(2);
expect(setOutputMock).toHaveBeenCalledTimes(2);
expect(saveStateMock).toHaveBeenCalledTimes(0);
});