Commit 80f77776 authored by Joshua Brooks's avatar Joshua Brooks
Browse files

Update packages, migrate to ESM

parent 27d5ce7f
Loading
Loading
Loading
Loading
+85 −74
Changes for __tests__/actionUtils.test.ts: 85 added lines, 74 removed lines.
Original line number Diff line number Diff line
import * as cache from "@actions/cache";
import * as core from "@actions/core";

import { Events, RefKey } from "../src/constants";
import * as actionUtils from "../src/utils/actionUtils";
import * as testUtils from "../src/utils/testUtils";
import { jest, test, expect, beforeEach, afterAll } from "@jest/globals";

// Mock @actions/core
jest.unstable_mockModule("@actions/core", () => ({
    getInput: jest.fn((name: string, options?: { required?: boolean }) => {
        const val =
            process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] || "";
        if (options && options.required && !val) {
            throw new Error(`Input required and not supplied: ${name}`);
        }
        return val.trim();
    }),
    setOutput: jest.fn(),
    setFailed: jest.fn(),
    info: jest.fn(),
    warning: jest.fn(),
    debug: jest.fn(),
    error: jest.fn(),
    saveState: jest.fn(),
    getState: jest.fn(() => ""),
    isDebug: jest.fn(() => false),
    exportVariable: jest.fn(),
    addPath: jest.fn(),
    group: jest.fn((name: string, fn: () => Promise<unknown>) => fn()),
    startGroup: jest.fn(),
    endGroup: jest.fn()
}));

// Mock @actions/cache
jest.unstable_mockModule("@actions/cache", () => ({
    restoreCache: jest.fn(),
    saveCache: jest.fn(),
    isFeatureAvailable: jest.fn(() => true),
    ReserveCacheError: class ReserveCacheError extends Error {
        constructor(message: string) {
            super(message);
            this.name = "ReserveCacheError";
        }
    }
}));

jest.mock("@actions/core");
jest.mock("@actions/cache");
const core = await import("@actions/core");
const cache = await import("@actions/cache");
const { Events, RefKey } = await import("../src/constants");
const actionUtils = await import("../src/utils/actionUtils");
const testUtils = await import("../src/utils/testUtils");

let pristineEnv: NodeJS.ProcessEnv;

beforeAll(() => {
    pristineEnv = process.env;
    jest.spyOn(core, "getInput").mockImplementation((name, options) => {
        return jest.requireActual("@actions/core").getInput(name, options);
    });
});

beforeEach(() => {
    jest.resetModules();
    process.env = pristineEnv;
    pristineEnv = { ...process.env };
    jest.clearAllMocks();
    (core.getInput as jest.Mock).mockImplementation(
        (name: string, options?: { required?: boolean }) => {
            const val =
                process.env[
                    `INPUT_${name.replace(/ /g, "_").toUpperCase()}`
                ] || "";
            if (options && options.required && !val) {
                throw new Error(
                    `Input required and not supplied: ${name}`
                );
            }
            return val.trim();
        }
    );
    delete process.env[Events.Key];
    delete process.env[RefKey];
});
@@ -47,74 +91,44 @@ test("isGhes returns false when server url is github.com", () => {
});

test("isExactKeyMatch with undefined cache key returns false", () => {
    const key = "linux-rust";
    const cacheKey = undefined;

    expect(actionUtils.isExactKeyMatch(key, cacheKey)).toBe(false);
    expect(actionUtils.isExactKeyMatch("linux-rust", undefined)).toBe(false);
});

test("isExactKeyMatch with empty cache key returns false", () => {
    const key = "linux-rust";
    const cacheKey = "";

    expect(actionUtils.isExactKeyMatch(key, cacheKey)).toBe(false);
    expect(actionUtils.isExactKeyMatch("linux-rust", "")).toBe(false);
});

test("isExactKeyMatch with different keys returns false", () => {
    const key = "linux-rust";
    const cacheKey = "linux-";

    expect(actionUtils.isExactKeyMatch(key, cacheKey)).toBe(false);
    expect(actionUtils.isExactKeyMatch("linux-rust", "linux-")).toBe(false);
});

test("isExactKeyMatch with different key accents returns false", () => {
    const key = "linux-áccent";
    const cacheKey = "linux-accent";

    expect(actionUtils.isExactKeyMatch(key, cacheKey)).toBe(false);
    expect(actionUtils.isExactKeyMatch("linux-áccent", "linux-accent")).toBe(false);
});

test("isExactKeyMatch with same key returns true", () => {
    const key = "linux-rust";
    const cacheKey = "linux-rust";

    expect(actionUtils.isExactKeyMatch(key, cacheKey)).toBe(true);
    expect(actionUtils.isExactKeyMatch("linux-rust", "linux-rust")).toBe(true);
});

test("isExactKeyMatch with same key and different casing returns true", () => {
    const key = "linux-rust";
    const cacheKey = "LINUX-RUST";

    expect(actionUtils.isExactKeyMatch(key, cacheKey)).toBe(true);
    expect(actionUtils.isExactKeyMatch("linux-rust", "LINUX-RUST")).toBe(true);
});

test("logWarning logs a message with a warning prefix", () => {
    const message = "A warning occurred.";

    const infoMock = jest.spyOn(core, "info");

    actionUtils.logWarning(message);

    expect(infoMock).toHaveBeenCalledWith(`[warning]${message}`);
    expect(core.info).toHaveBeenCalledWith(`[warning]${message}`);
});

test("isValidEvent returns false for event that does not have a branch or tag", () => {
    const event = "foo";
    process.env[Events.Key] = event;

    const isValidEvent = actionUtils.isValidEvent();

    expect(isValidEvent).toBe(false);
    process.env[Events.Key] = "foo";
    expect(actionUtils.isValidEvent()).toBe(false);
});

test("isValidEvent returns true for event that has a ref", () => {
    const event = Events.Push;
    process.env[Events.Key] = event;
    process.env[Events.Key] = Events.Push;
    process.env[RefKey] = "ref/heads/feature";

    const isValidEvent = actionUtils.isValidEvent();

    expect(isValidEvent).toBe(true);
    expect(actionUtils.isValidEvent()).toBe(true);
});

test("getInputAsArray returns empty array if not required and missing", () => {
@@ -124,7 +138,7 @@ test("getInputAsArray returns empty array if not required and missing", () => {
test("getInputAsArray throws error if required and missing", () => {
    expect(() =>
        actionUtils.getInputAsArray("foo", { required: true })
    ).toThrowError();
    ).toThrow();
});

test("getInputAsArray handles single line correctly", () => {
@@ -180,7 +194,7 @@ test("getInputAsInt returns undefined if input is invalid or NaN", () => {
test("getInputAsInt throws if required and value missing", () => {
    expect(() =>
        actionUtils.getInputAsInt("undefined", { required: true })
    ).toThrowError();
    ).toThrow();
});

test("getInputAsBool returns false if input not set", () => {
@@ -200,68 +214,65 @@ test("getInputAsBool returns false if input is invalid or NaN", () => {
test("getInputAsBool throws if required and value missing", () => {
    expect(() =>
        actionUtils.getInputAsBool("undefined2", { required: true })
    ).toThrowError();
    ).toThrow();
});

test("isCacheFeatureAvailable for ac enabled", () => {
    jest.spyOn(cache, "isFeatureAvailable").mockImplementation(() => true);

    (cache.isFeatureAvailable as jest.Mock).mockReturnValue(true);
    expect(actionUtils.isCacheFeatureAvailable()).toBe(true);
});

test("isCacheFeatureAvailable for ac disabled on GHES", () => {
    jest.spyOn(cache, "isFeatureAvailable").mockImplementation(() => false);
    (cache.isFeatureAvailable as jest.Mock).mockReturnValue(false);

    const message = `Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.
Otherwise please upgrade to GHES version >= 3.5 and If you are also using Github Connect, please unretire the actions/cache namespace before upgrade (see https://docs.github.com/en/[email protected]/admin/github-actions/managing-access-to-actions-from-githubcom/enabling-automatic-access-to-githubcom-actions-using-github-connect#automatic-retirement-of-namespaces-for-actions-accessed-on-githubcom)`;
    const infoMock = jest.spyOn(core, "info");

    try {
        process.env["GITHUB_SERVER_URL"] = "http://example.com";
        expect(actionUtils.isCacheFeatureAvailable()).toBe(false);
        expect(infoMock).toHaveBeenCalledWith(`[warning]${message}`);
        expect(core.info).toHaveBeenCalledWith(`[warning]${message}`);
    } finally {
        delete process.env["GITHUB_SERVER_URL"];
    }
});

test("isCacheFeatureAvailable for ac disabled on dotcom", () => {
    jest.spyOn(cache, "isFeatureAvailable").mockImplementation(() => false);
    (cache.isFeatureAvailable as jest.Mock).mockReturnValue(false);

    const message =
        "An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions.";
    const infoMock = jest.spyOn(core, "info");

    try {
        process.env["GITHUB_SERVER_URL"] = "http://github.com";
        expect(actionUtils.isCacheFeatureAvailable()).toBe(false);
        expect(infoMock).toHaveBeenCalledWith(`[warning]${message}`);
        expect(core.info).toHaveBeenCalledWith(`[warning]${message}`);
    } finally {
        delete process.env["GITHUB_SERVER_URL"];
    }
});

test("isGhes returns false when the GITHUB_SERVER_URL environment variable is not defined", async () => {
test("isGhes returns false when the GITHUB_SERVER_URL environment variable is not defined", () => {
    delete process.env["GITHUB_SERVER_URL"];
    expect(actionUtils.isGhes()).toBeFalsy();
});

test("isGhes returns false when the GITHUB_SERVER_URL environment variable is set to github.com", async () => {
test("isGhes returns false when the GITHUB_SERVER_URL environment variable is set to github.com", () => {
    process.env["GITHUB_SERVER_URL"] = "https://github.com";
    expect(actionUtils.isGhes()).toBeFalsy();
});

test("isGhes returns false when the GITHUB_SERVER_URL environment variable is set to a GitHub Enterprise Cloud-style URL", async () => {
test("isGhes returns false when the GITHUB_SERVER_URL environment variable is set to a GitHub Enterprise Cloud-style URL", () => {
    process.env["GITHUB_SERVER_URL"] = "https://contoso.ghe.com";
    expect(actionUtils.isGhes()).toBeFalsy();
});

test("isGhes returns false when the GITHUB_SERVER_URL environment variable has a .localhost suffix", async () => {
test("isGhes returns false when the GITHUB_SERVER_URL environment variable has a .localhost suffix", () => {
    process.env["GITHUB_SERVER_URL"] = "https://mock-github.localhost";
    expect(actionUtils.isGhes()).toBeFalsy();
});

test("isGhes returns true when the GITHUB_SERVER_URL environment variable is set to some other URL", async () => {
test("isGhes returns true when the GITHUB_SERVER_URL environment variable is set to some other URL", () => {
    process.env["GITHUB_SERVER_URL"] = "https://src.onpremise.fabrikam.com";
    expect(actionUtils.isGhes()).toBeTruthy();
});
+112 −196
Changes for __tests__/restore.test.ts: 112 added lines, 196 removed lines.
Original line number Diff line number Diff line
import * as cache from "@actions/cache";
import * as core from "@actions/core";

import { Events, RefKey } from "../src/constants";
import { restoreRun } from "../src/restoreImpl";
import * as actionUtils from "../src/utils/actionUtils";
import * as testUtils from "../src/utils/testUtils";

jest.mock("../src/utils/actionUtils");

beforeAll(() => {
    jest.spyOn(actionUtils, "isExactKeyMatch").mockImplementation(
        (key, cacheResult) => {
            const actualUtils = jest.requireActual("../src/utils/actionUtils");
            return actualUtils.isExactKeyMatch(key, cacheResult);
import { jest, test, expect, beforeEach, afterEach } from "@jest/globals";

// Mock @actions/core
jest.unstable_mockModule("@actions/core", () => ({
    getInput: jest.fn((name: string, options?: { required?: boolean }) => {
        const val =
            process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] || "";
        if (options && options.required && !val) {
            throw new Error(`Input required and not supplied: ${name}`);
        }
    );
        return val.trim();
    }),
    setOutput: jest.fn(),
    setFailed: jest.fn(),
    info: jest.fn(),
    warning: jest.fn(),
    debug: jest.fn(),
    error: jest.fn(),
    saveState: jest.fn(),
    getState: jest.fn(() => ""),
    isDebug: jest.fn(() => false),
    exportVariable: jest.fn(),
    addPath: jest.fn(),
    group: jest.fn((name: string, fn: () => Promise<unknown>) => fn()),
    startGroup: jest.fn(),
    endGroup: jest.fn()
}));

// Mock @actions/cache
jest.unstable_mockModule("@actions/cache", () => ({
    restoreCache: jest.fn(),
    saveCache: jest.fn(),
    isFeatureAvailable: jest.fn(() => true),
    ReserveCacheError: class ReserveCacheError extends Error {
        constructor(message: string) {
            super(message);
            this.name = "ReserveCacheError";
        }
    }
}));

    jest.spyOn(actionUtils, "isValidEvent").mockImplementation(() => {
        const actualUtils = jest.requireActual("../src/utils/actionUtils");
        return actualUtils.isValidEvent();
    });
const core = await import("@actions/core");
const cache = await import("@actions/cache");
const { Events, RefKey } = await import("../src/constants");
const { restoreRun } = await import("../src/restoreImpl");
const testUtils = await import("../src/utils/testUtils");

    jest.spyOn(actionUtils, "getInputAsArray").mockImplementation(
        (name, options) => {
            const actualUtils = jest.requireActual("../src/utils/actionUtils");
            return actualUtils.getInputAsArray(name, options);
        }
beforeEach(() => {
    jest.clearAllMocks();
    (core.getInput as jest.Mock).mockImplementation(
        (name: string, options?: { required?: boolean }) => {
            const val =
                process.env[
                    `INPUT_${name.replace(/ /g, "_").toUpperCase()}`
                ] || "";
            if (options && options.required && !val) {
                throw new Error(
                    `Input required and not supplied: ${name}`
                );

    jest.spyOn(actionUtils, "getInputAsBool").mockImplementation(
        (name, options) => {
            const actualUtils = jest.requireActual("../src/utils/actionUtils");
            return actualUtils.getInputAsBool(name, options);
            }
            return val.trim();
        }
    );
});

beforeEach(() => {
    jest.restoreAllMocks();
    (cache.isFeatureAvailable as jest.Mock).mockReturnValue(true);
    process.env[Events.Key] = Events.Push;
    process.env[RefKey] = "refs/heads/feature-branch";

    jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false);
    jest.spyOn(actionUtils, "isCacheFeatureAvailable").mockImplementation(
        () => true
    );
});

afterEach(() => {
@@ -62,19 +81,12 @@ test("restore with no cache found", async () => {
        enableCrossOsArchive: false
    });

    const infoMock = jest.spyOn(core, "info");
    const failedMock = jest.spyOn(core, "setFailed");
    const stateMock = jest.spyOn(core, "saveState");
    const restoreCacheMock = jest
        .spyOn(cache, "restoreCache")
        .mockImplementationOnce(() => {
            return Promise.resolve(undefined);
        });
    (cache.restoreCache as jest.Mock).mockResolvedValue(undefined);

    await restoreRun();

    expect(restoreCacheMock).toHaveBeenCalledTimes(1);
    expect(restoreCacheMock).toHaveBeenCalledWith(
    expect(cache.restoreCache).toHaveBeenCalledTimes(1);
    expect(cache.restoreCache).toHaveBeenCalledWith(
        [path],
        key,
        [],
@@ -84,12 +96,10 @@ test("restore with no cache found", async () => {
        false
    );

    expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
    expect(stateMock).toHaveBeenCalledTimes(1);

    expect(failedMock).toHaveBeenCalledTimes(0);

    expect(infoMock).toHaveBeenCalledWith(
    expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
    expect(core.saveState).toHaveBeenCalledTimes(1);
    expect(core.setFailed).toHaveBeenCalledTimes(0);
    expect(core.info).toHaveBeenCalledWith(
        `Cache not found for input keys: ${key}`
    );
});
@@ -105,19 +115,12 @@ test("restore with restore keys and no cache found", async () => {
        enableCrossOsArchive: false
    });

    const infoMock = jest.spyOn(core, "info");
    const failedMock = jest.spyOn(core, "setFailed");
    const stateMock = jest.spyOn(core, "saveState");
    const restoreCacheMock = jest
        .spyOn(cache, "restoreCache")
        .mockImplementationOnce(() => {
            return Promise.resolve(undefined);
        });
    (cache.restoreCache as jest.Mock).mockResolvedValue(undefined);

    await restoreRun();

    expect(restoreCacheMock).toHaveBeenCalledTimes(1);
    expect(restoreCacheMock).toHaveBeenCalledWith(
    expect(cache.restoreCache).toHaveBeenCalledTimes(1);
    expect(cache.restoreCache).toHaveBeenCalledWith(
        [path],
        key,
        [restoreKey],
@@ -127,12 +130,10 @@ test("restore with restore keys and no cache found", async () => {
        false
    );

    expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
    expect(stateMock).toHaveBeenCalledTimes(1);

    expect(failedMock).toHaveBeenCalledTimes(0);

    expect(infoMock).toHaveBeenCalledWith(
    expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
    expect(core.saveState).toHaveBeenCalledTimes(1);
    expect(core.setFailed).toHaveBeenCalledTimes(0);
    expect(core.info).toHaveBeenCalledWith(
        `Cache not found for input keys: ${key}, ${restoreKey}`
    );
});
@@ -146,20 +147,12 @@ test("restore with cache found for key", async () => {
        enableCrossOsArchive: false
    });

    const infoMock = jest.spyOn(core, "info");
    const failedMock = jest.spyOn(core, "setFailed");
    const stateMock = jest.spyOn(core, "saveState");
    const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
    const restoreCacheMock = jest
        .spyOn(cache, "restoreCache")
        .mockImplementationOnce(() => {
            return Promise.resolve(key);
        });
    (cache.restoreCache as jest.Mock).mockResolvedValue(key);

    await restoreRun();

    expect(restoreCacheMock).toHaveBeenCalledTimes(1);
    expect(restoreCacheMock).toHaveBeenCalledWith(
    expect(cache.restoreCache).toHaveBeenCalledTimes(1);
    expect(cache.restoreCache).toHaveBeenCalledWith(
        [path],
        key,
        [],
@@ -169,15 +162,13 @@ test("restore with cache found for key", async () => {
        false
    );

    expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
    expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", key);
    expect(stateMock).toHaveBeenCalledTimes(2);

    expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
    expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "true");

    expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
    expect(failedMock).toHaveBeenCalledTimes(0);
    expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
    expect(core.saveState).toHaveBeenCalledWith("CACHE_RESULT", key);
    expect(core.saveState).toHaveBeenCalledTimes(2);
    expect(core.setOutput).toHaveBeenCalledTimes(1);
    expect(core.setOutput).toHaveBeenCalledWith("cache-hit", "true");
    expect(core.info).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
    expect(core.setFailed).toHaveBeenCalledTimes(0);
});

test("restore with cache found for restore key", async () => {
@@ -191,39 +182,20 @@ test("restore with cache found for restore key", async () => {
        enableCrossOsArchive: false
    });

    const infoMock = jest.spyOn(core, "info");
    const failedMock = jest.spyOn(core, "setFailed");
    const stateMock = jest.spyOn(core, "saveState");
    const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
    const restoreCacheMock = jest
        .spyOn(cache, "restoreCache")
        .mockImplementationOnce(() => {
            return Promise.resolve(restoreKey);
        });
    (cache.restoreCache as jest.Mock).mockResolvedValue(restoreKey);

    await restoreRun();

    expect(restoreCacheMock).toHaveBeenCalledTimes(1);
    expect(restoreCacheMock).toHaveBeenCalledWith(
        [path],
        key,
        [restoreKey],
        {
            lookupOnly: false
        },
        false
    );

    expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
    expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", restoreKey);
    expect(stateMock).toHaveBeenCalledTimes(2);

    expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
    expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "false");
    expect(infoMock).toHaveBeenCalledWith(
    expect(cache.restoreCache).toHaveBeenCalledTimes(1);
    expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
    expect(core.saveState).toHaveBeenCalledWith("CACHE_RESULT", restoreKey);
    expect(core.saveState).toHaveBeenCalledTimes(2);
    expect(core.setOutput).toHaveBeenCalledTimes(1);
    expect(core.setOutput).toHaveBeenCalledWith("cache-hit", "false");
    expect(core.info).toHaveBeenCalledWith(
        `Cache restored from key: ${restoreKey}`
    );
    expect(failedMock).toHaveBeenCalledTimes(0);
    expect(core.setFailed).toHaveBeenCalledTimes(0);
});

test("Fail restore when fail on cache miss is enabled and primary + restore keys not found", async () => {
@@ -237,35 +209,17 @@ test("Fail restore when fail on cache miss is enabled and primary + restore keys
        failOnCacheMiss: true
    });

    const failedMock = jest.spyOn(core, "setFailed");
    const stateMock = jest.spyOn(core, "saveState");
    const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
    const restoreCacheMock = jest
        .spyOn(cache, "restoreCache")
        .mockImplementationOnce(() => {
            return Promise.resolve(undefined);
        });
    (cache.restoreCache as jest.Mock).mockResolvedValue(undefined);

    await restoreRun();

    expect(restoreCacheMock).toHaveBeenCalledTimes(1);
    expect(restoreCacheMock).toHaveBeenCalledWith(
        [path],
        key,
        [restoreKey],
        {
            lookupOnly: false
        },
        false
    );

    expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
    expect(setCacheHitOutputMock).toHaveBeenCalledTimes(0);

    expect(failedMock).toHaveBeenCalledWith(
    expect(cache.restoreCache).toHaveBeenCalledTimes(1);
    expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
    expect(core.setOutput).toHaveBeenCalledTimes(0);
    expect(core.setFailed).toHaveBeenCalledWith(
        `Failed to restore cache entry. Exiting as fail-on-cache-miss is set. Input key: ${key}`
    );
    expect(failedMock).toHaveBeenCalledTimes(1);
    expect(core.setFailed).toHaveBeenCalledTimes(1);
});

test("restore when fail on cache miss is enabled and primary key doesn't match restored key", async () => {
@@ -279,40 +233,20 @@ test("restore when fail on cache miss is enabled and primary key doesn't match r
        failOnCacheMiss: true
    });

    const infoMock = jest.spyOn(core, "info");
    const failedMock = jest.spyOn(core, "setFailed");
    const stateMock = jest.spyOn(core, "saveState");
    const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
    const restoreCacheMock = jest
        .spyOn(cache, "restoreCache")
        .mockImplementationOnce(() => {
            return Promise.resolve(restoreKey);
        });
    (cache.restoreCache as jest.Mock).mockResolvedValue(restoreKey);

    await restoreRun();

    expect(restoreCacheMock).toHaveBeenCalledTimes(1);
    expect(restoreCacheMock).toHaveBeenCalledWith(
        [path],
        key,
        [restoreKey],
        {
            lookupOnly: false
        },
        false
    );

    expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
    expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", restoreKey);
    expect(stateMock).toHaveBeenCalledTimes(2);

    expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
    expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "false");

    expect(infoMock).toHaveBeenCalledWith(
    expect(cache.restoreCache).toHaveBeenCalledTimes(1);
    expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
    expect(core.saveState).toHaveBeenCalledWith("CACHE_RESULT", restoreKey);
    expect(core.saveState).toHaveBeenCalledTimes(2);
    expect(core.setOutput).toHaveBeenCalledTimes(1);
    expect(core.setOutput).toHaveBeenCalledWith("cache-hit", "false");
    expect(core.info).toHaveBeenCalledWith(
        `Cache restored from key: ${restoreKey}`
    );
    expect(failedMock).toHaveBeenCalledTimes(0);
    expect(core.setFailed).toHaveBeenCalledTimes(0);
});

test("restore with fail on cache miss disabled and no cache found", async () => {
@@ -326,33 +260,15 @@ test("restore with fail on cache miss disabled and no cache found", async () =>
        failOnCacheMiss: false
    });

    const infoMock = jest.spyOn(core, "info");
    const failedMock = jest.spyOn(core, "setFailed");
    const stateMock = jest.spyOn(core, "saveState");
    const restoreCacheMock = jest
        .spyOn(cache, "restoreCache")
        .mockImplementationOnce(() => {
            return Promise.resolve(undefined);
        });
    (cache.restoreCache as jest.Mock).mockResolvedValue(undefined);

    await restoreRun();

    expect(restoreCacheMock).toHaveBeenCalledTimes(1);
    expect(restoreCacheMock).toHaveBeenCalledWith(
        [path],
        key,
        [restoreKey],
        {
            lookupOnly: false
        },
        false
    );

    expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
    expect(stateMock).toHaveBeenCalledTimes(1);

    expect(infoMock).toHaveBeenCalledWith(
    expect(cache.restoreCache).toHaveBeenCalledTimes(1);
    expect(core.saveState).toHaveBeenCalledWith("CACHE_KEY", key);
    expect(core.saveState).toHaveBeenCalledTimes(1);
    expect(core.info).toHaveBeenCalledWith(
        `Cache not found for input keys: ${key}, ${restoreKey}`
    );
    expect(failedMock).toHaveBeenCalledTimes(0);
    expect(core.setFailed).toHaveBeenCalledTimes(0);
});
+137 −255

File changed.

Preview size limit exceeded, changes collapsed.

+86 −132

File changed.

Preview size limit exceeded, changes collapsed.

+65 −78

File changed.

Preview size limit exceeded, changes collapsed.

Loading