Loading __tests__/actionUtils.test.ts +37 Changes for __tests__/actionUtils.test.ts: 37 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -2,9 +2,16 @@ import * as core from "@actions/core"; import { Events, Outputs, RefKey, State } from "../src/constants"; import * as actionUtils from "../src/utils/actionUtils"; import * as testUtils from "../src/utils/testUtils"; jest.mock("@actions/core"); beforeAll(() => { jest.spyOn(core, "getInput").mockImplementation((name, options) => { return jest.requireActual("@actions/core").getInput(name, options); }); }); afterEach(() => { delete process.env[Events.Key]; delete process.env[RefKey]; Loading Loading @@ -157,3 +164,33 @@ test("isValidEvent returns true for event that has a ref", () => { expect(isValidEvent).toBe(true); }); test("getInputAsArray returns empty array if not required and missing", () => { expect(actionUtils.getInputAsArray("foo")).toEqual([]); }); test("getInputAsArray throws error if required and missing", () => { expect(() => actionUtils.getInputAsArray("foo", { required: true }) ).toThrowError(); }); test("getInputAsArray handles single line correctly", () => { testUtils.setInput("foo", "bar"); expect(actionUtils.getInputAsArray("foo")).toEqual(["bar"]); }); test("getInputAsArray handles multiple lines correctly", () => { testUtils.setInput("foo", "bar\nbaz"); expect(actionUtils.getInputAsArray("foo")).toEqual(["bar", "baz"]); }); test("getInputAsArray handles different new lines correctly", () => { testUtils.setInput("foo", "bar\r\nbaz"); expect(actionUtils.getInputAsArray("foo")).toEqual(["bar", "baz"]); }); test("getInputAsArray handles empty lines correctly", () => { testUtils.setInput("foo", "\n\nbar\n\nbaz\n\n"); expect(actionUtils.getInputAsArray("foo")).toEqual(["bar", "baz"]); }); __tests__/restore.test.ts +7 Changes for __tests__/restore.test.ts: 7 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -20,6 +20,13 @@ beforeAll(() => { const actualUtils = jest.requireActual("../src/utils/actionUtils"); return actualUtils.isValidEvent(); }); jest.spyOn(actionUtils, "getInputAsArray").mockImplementation( (name, options) => { const actualUtils = jest.requireActual("../src/utils/actionUtils"); return actualUtils.getInputAsArray(name, options); } ); }); beforeEach(() => { Loading __tests__/save.test.ts +8 Changes for __tests__/save.test.ts: 8 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -19,6 +19,14 @@ beforeAll(() => { return jest.requireActual("../src/utils/actionUtils").getCacheState(); }); jest.spyOn(actionUtils, "getInputAsArray").mockImplementation( (name, options) => { return jest .requireActual("../src/utils/actionUtils") .getInputAsArray(name, options); } ); jest.spyOn(actionUtils, "isExactKeyMatch").mockImplementation( (key, cacheResult) => { return jest Loading dist/restore/index.js +13 −9 Changes for dist/restore/index.js: 13 added lines, 9 removed lines. Original line number Diff line number Diff line Loading @@ -5306,7 +5306,7 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = void 0; exports.getInputAsArray = exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = void 0; const core = __importStar(__webpack_require__(470)); const constants_1 = __webpack_require__(694); function isExactKeyMatch(key, cacheKey) { Loading Loading @@ -5350,6 +5350,14 @@ function isValidEvent() { return constants_1.RefKey in process.env && Boolean(process.env[constants_1.RefKey]); } exports.isValidEvent = isValidEvent; function getInputAsArray(name, options) { return core .getInput(name, options) .split("\n") .map(s => s.trim()) .filter(x => x !== ""); } exports.getInputAsArray = getInputAsArray; /***/ }), Loading Loading @@ -6835,14 +6843,10 @@ function run() { } const primaryKey = core.getInput(constants_1.Inputs.Key, { required: true }); core.saveState(constants_1.State.CachePrimaryKey, primaryKey); const restoreKeys = core .getInput(constants_1.Inputs.RestoreKeys) .split("\n") .filter(x => x !== ""); const cachePaths = core .getInput(constants_1.Inputs.Path, { required: true }) .split("\n") .filter(x => x !== ""); const restoreKeys = utils.getInputAsArray(constants_1.Inputs.RestoreKeys); const cachePaths = utils.getInputAsArray(constants_1.Inputs.Path, { required: true }); try { const cacheKey = yield cache.restoreCache(cachePaths, primaryKey, restoreKeys); if (!cacheKey) { Loading dist/save/index.js +12 −5 Changes for dist/save/index.js: 12 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -5306,7 +5306,7 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = void 0; exports.getInputAsArray = exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = void 0; const core = __importStar(__webpack_require__(470)); const constants_1 = __webpack_require__(694); function isExactKeyMatch(key, cacheKey) { Loading Loading @@ -5350,6 +5350,14 @@ function isValidEvent() { return constants_1.RefKey in process.env && Boolean(process.env[constants_1.RefKey]); } exports.isValidEvent = isValidEvent; function getInputAsArray(name, options) { return core .getInput(name, options) .split("\n") .map(s => s.trim()) .filter(x => x !== ""); } exports.getInputAsArray = getInputAsArray; /***/ }), Loading Loading @@ -6600,10 +6608,9 @@ function run() { core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`); return; } const cachePaths = core .getInput(constants_1.Inputs.Path, { required: true }) .split("\n") .filter(x => x !== ""); const cachePaths = utils.getInputAsArray(constants_1.Inputs.Path, { required: true }); try { yield cache.saveCache(cachePaths, primaryKey); } Loading Loading
__tests__/actionUtils.test.ts +37 Changes for __tests__/actionUtils.test.ts: 37 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -2,9 +2,16 @@ import * as core from "@actions/core"; import { Events, Outputs, RefKey, State } from "../src/constants"; import * as actionUtils from "../src/utils/actionUtils"; import * as testUtils from "../src/utils/testUtils"; jest.mock("@actions/core"); beforeAll(() => { jest.spyOn(core, "getInput").mockImplementation((name, options) => { return jest.requireActual("@actions/core").getInput(name, options); }); }); afterEach(() => { delete process.env[Events.Key]; delete process.env[RefKey]; Loading Loading @@ -157,3 +164,33 @@ test("isValidEvent returns true for event that has a ref", () => { expect(isValidEvent).toBe(true); }); test("getInputAsArray returns empty array if not required and missing", () => { expect(actionUtils.getInputAsArray("foo")).toEqual([]); }); test("getInputAsArray throws error if required and missing", () => { expect(() => actionUtils.getInputAsArray("foo", { required: true }) ).toThrowError(); }); test("getInputAsArray handles single line correctly", () => { testUtils.setInput("foo", "bar"); expect(actionUtils.getInputAsArray("foo")).toEqual(["bar"]); }); test("getInputAsArray handles multiple lines correctly", () => { testUtils.setInput("foo", "bar\nbaz"); expect(actionUtils.getInputAsArray("foo")).toEqual(["bar", "baz"]); }); test("getInputAsArray handles different new lines correctly", () => { testUtils.setInput("foo", "bar\r\nbaz"); expect(actionUtils.getInputAsArray("foo")).toEqual(["bar", "baz"]); }); test("getInputAsArray handles empty lines correctly", () => { testUtils.setInput("foo", "\n\nbar\n\nbaz\n\n"); expect(actionUtils.getInputAsArray("foo")).toEqual(["bar", "baz"]); });
__tests__/restore.test.ts +7 Changes for __tests__/restore.test.ts: 7 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -20,6 +20,13 @@ beforeAll(() => { const actualUtils = jest.requireActual("../src/utils/actionUtils"); return actualUtils.isValidEvent(); }); jest.spyOn(actionUtils, "getInputAsArray").mockImplementation( (name, options) => { const actualUtils = jest.requireActual("../src/utils/actionUtils"); return actualUtils.getInputAsArray(name, options); } ); }); beforeEach(() => { Loading
__tests__/save.test.ts +8 Changes for __tests__/save.test.ts: 8 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -19,6 +19,14 @@ beforeAll(() => { return jest.requireActual("../src/utils/actionUtils").getCacheState(); }); jest.spyOn(actionUtils, "getInputAsArray").mockImplementation( (name, options) => { return jest .requireActual("../src/utils/actionUtils") .getInputAsArray(name, options); } ); jest.spyOn(actionUtils, "isExactKeyMatch").mockImplementation( (key, cacheResult) => { return jest Loading
dist/restore/index.js +13 −9 Changes for dist/restore/index.js: 13 added lines, 9 removed lines. Original line number Diff line number Diff line Loading @@ -5306,7 +5306,7 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = void 0; exports.getInputAsArray = exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = void 0; const core = __importStar(__webpack_require__(470)); const constants_1 = __webpack_require__(694); function isExactKeyMatch(key, cacheKey) { Loading Loading @@ -5350,6 +5350,14 @@ function isValidEvent() { return constants_1.RefKey in process.env && Boolean(process.env[constants_1.RefKey]); } exports.isValidEvent = isValidEvent; function getInputAsArray(name, options) { return core .getInput(name, options) .split("\n") .map(s => s.trim()) .filter(x => x !== ""); } exports.getInputAsArray = getInputAsArray; /***/ }), Loading Loading @@ -6835,14 +6843,10 @@ function run() { } const primaryKey = core.getInput(constants_1.Inputs.Key, { required: true }); core.saveState(constants_1.State.CachePrimaryKey, primaryKey); const restoreKeys = core .getInput(constants_1.Inputs.RestoreKeys) .split("\n") .filter(x => x !== ""); const cachePaths = core .getInput(constants_1.Inputs.Path, { required: true }) .split("\n") .filter(x => x !== ""); const restoreKeys = utils.getInputAsArray(constants_1.Inputs.RestoreKeys); const cachePaths = utils.getInputAsArray(constants_1.Inputs.Path, { required: true }); try { const cacheKey = yield cache.restoreCache(cachePaths, primaryKey, restoreKeys); if (!cacheKey) { Loading
dist/save/index.js +12 −5 Changes for dist/save/index.js: 12 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -5306,7 +5306,7 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = void 0; exports.getInputAsArray = exports.isValidEvent = exports.logWarning = exports.getCacheState = exports.setOutputAndState = exports.setCacheHitOutput = exports.setCacheState = exports.isExactKeyMatch = void 0; const core = __importStar(__webpack_require__(470)); const constants_1 = __webpack_require__(694); function isExactKeyMatch(key, cacheKey) { Loading Loading @@ -5350,6 +5350,14 @@ function isValidEvent() { return constants_1.RefKey in process.env && Boolean(process.env[constants_1.RefKey]); } exports.isValidEvent = isValidEvent; function getInputAsArray(name, options) { return core .getInput(name, options) .split("\n") .map(s => s.trim()) .filter(x => x !== ""); } exports.getInputAsArray = getInputAsArray; /***/ }), Loading Loading @@ -6600,10 +6608,9 @@ function run() { core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`); return; } const cachePaths = core .getInput(constants_1.Inputs.Path, { required: true }) .split("\n") .filter(x => x !== ""); const cachePaths = utils.getInputAsArray(constants_1.Inputs.Path, { required: true }); try { yield cache.saveCache(cachePaths, primaryKey); } Loading