From 5a912e8b4af820fa082a0e75cfd2c782f8fbfe0e Mon Sep 17 00:00:00 2001 From: Joshua Brooks Date: Wed, 20 May 2026 20:18:29 +0000 Subject: [PATCH] Fix lint and jest issues --- __tests__/actionUtils.test.ts | 15 +++++++-------- __tests__/restore.test.ts | 11 ++++------- __tests__/restoreImpl.test.ts | 20 +++++++++++--------- __tests__/restoreOnly.test.ts | 16 ++++++++-------- __tests__/save.test.ts | 11 ++++------- __tests__/saveImpl.test.ts | 11 ++++------- __tests__/saveOnly.test.ts | 11 ++++------- __tests__/stateProvider.test.ts | 20 +++++++++++++------- jest.config.ts | 2 +- 9 files changed, 56 insertions(+), 61 deletions(-) diff --git a/__tests__/actionUtils.test.ts b/__tests__/actionUtils.test.ts index 2edcff1..d4eb482 100644 --- a/__tests__/actionUtils.test.ts +++ b/__tests__/actionUtils.test.ts @@ -1,4 +1,4 @@ -import { jest, test, expect, beforeEach, afterAll } from "@jest/globals"; +import { afterAll, beforeEach, expect, jest, test } from "@jest/globals"; // Mock @actions/core jest.unstable_mockModule("@actions/core", () => ({ @@ -53,13 +53,10 @@ beforeEach(() => { (core.getInput as jest.Mock).mockImplementation( (name: string, options?: { required?: boolean }) => { const val = - process.env[ - `INPUT_${name.replace(/ /g, "_").toUpperCase()}` - ] || ""; + process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] || + ""; if (options && options.required && !val) { - throw new Error( - `Input required and not supplied: ${name}` - ); + throw new Error(`Input required and not supplied: ${name}`); } return val.trim(); } @@ -103,7 +100,9 @@ test("isExactKeyMatch with different keys returns false", () => { }); test("isExactKeyMatch with different key accents returns false", () => { - expect(actionUtils.isExactKeyMatch("linux-áccent", "linux-accent")).toBe(false); + expect(actionUtils.isExactKeyMatch("linux-áccent", "linux-accent")).toBe( + false + ); }); test("isExactKeyMatch with same key returns true", () => { diff --git a/__tests__/restore.test.ts b/__tests__/restore.test.ts index 7c1cb46..1757d88 100644 --- a/__tests__/restore.test.ts +++ b/__tests__/restore.test.ts @@ -1,4 +1,4 @@ -import { jest, test, expect, beforeEach, afterEach } from "@jest/globals"; +import { afterEach, beforeEach, expect, jest, test } from "@jest/globals"; // Mock @actions/core jest.unstable_mockModule("@actions/core", () => ({ @@ -50,13 +50,10 @@ beforeEach(() => { (core.getInput as jest.Mock).mockImplementation( (name: string, options?: { required?: boolean }) => { const val = - process.env[ - `INPUT_${name.replace(/ /g, "_").toUpperCase()}` - ] || ""; + process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] || + ""; if (options && options.required && !val) { - throw new Error( - `Input required and not supplied: ${name}` - ); + throw new Error(`Input required and not supplied: ${name}`); } return val.trim(); } diff --git a/__tests__/restoreImpl.test.ts b/__tests__/restoreImpl.test.ts index 241d20d..f8c6fac 100644 --- a/__tests__/restoreImpl.test.ts +++ b/__tests__/restoreImpl.test.ts @@ -1,4 +1,4 @@ -import { jest, test, expect, beforeEach, afterEach } from "@jest/globals"; +import { afterEach, beforeEach, expect, jest, test } from "@jest/globals"; // Mock @actions/core jest.unstable_mockModule("@actions/core", () => ({ @@ -51,13 +51,10 @@ beforeEach(() => { (core.getInput as jest.Mock).mockImplementation( (name: string, options?: { required?: boolean }) => { const val = - process.env[ - `INPUT_${name.replace(/ /g, "_").toUpperCase()}` - ] || ""; + process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] || + ""; if (options && options.required && !val) { - throw new Error( - `Input required and not supplied: ${name}` - ); + throw new Error(`Input required and not supplied: ${name}`); } return val.trim(); } @@ -182,7 +179,9 @@ test("restore with large key should fail", async () => { enableCrossOsArchive: false }); (cache.restoreCache as jest.Mock).mockRejectedValue( - new Error(`Key Validation Error: ${key} cannot be larger than 512 characters.`) + new Error( + `Key Validation Error: ${key} cannot be larger than 512 characters.` + ) ); await restoreImpl(new StateProvider()); expect(cache.restoreCache).toHaveBeenCalledTimes(1); @@ -336,7 +335,10 @@ test("restore with lookup-only set", async () => { test("restore failure with earlyExit should call process exit", async () => { testUtils.setInput(Inputs.Path, "node_modules"); - const processExitMock = jest.spyOn(process, "exit").mockImplementation((() => {}) as any); + const processExitMock = jest + .spyOn(process, "exit") + // eslint-disable-next-line @typescript-eslint/no-explicit-any + .mockImplementation((() => {}) as any); await restoreImpl(new StateProvider(), true); diff --git a/__tests__/restoreOnly.test.ts b/__tests__/restoreOnly.test.ts index c3ff684..dfc9fdf 100644 --- a/__tests__/restoreOnly.test.ts +++ b/__tests__/restoreOnly.test.ts @@ -1,4 +1,4 @@ -import { jest, test, expect, beforeEach, afterEach } from "@jest/globals"; +import { afterEach, beforeEach, expect, jest, test } from "@jest/globals"; // Mock @actions/core jest.unstable_mockModule("@actions/core", () => ({ @@ -50,13 +50,10 @@ beforeEach(() => { (core.getInput as jest.Mock).mockImplementation( (name: string, options?: { required?: boolean }) => { const val = - process.env[ - `INPUT_${name.replace(/ /g, "_").toUpperCase()}` - ] || ""; + process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] || + ""; if (options && options.required && !val) { - throw new Error( - `Input required and not supplied: ${name}` - ); + throw new Error(`Input required and not supplied: ${name}`); } return val.trim(); } @@ -167,7 +164,10 @@ test("restore with cache found for restore key", async () => { expect(cache.restoreCache).toHaveBeenCalledTimes(1); expect(core.setOutput).toHaveBeenCalledWith("cache-primary-key", key); expect(core.setOutput).toHaveBeenCalledWith("cache-hit", "false"); - expect(core.setOutput).toHaveBeenCalledWith("cache-matched-key", restoreKey); + expect(core.setOutput).toHaveBeenCalledWith( + "cache-matched-key", + restoreKey + ); expect(core.setOutput).toHaveBeenCalledTimes(3); expect(core.info).toHaveBeenCalledWith( `Cache restored from key: ${restoreKey}` diff --git a/__tests__/save.test.ts b/__tests__/save.test.ts index 329b707..13e0ef8 100644 --- a/__tests__/save.test.ts +++ b/__tests__/save.test.ts @@ -1,4 +1,4 @@ -import { jest, test, expect, beforeEach, afterEach } from "@jest/globals"; +import { afterEach, beforeEach, expect, jest, test } from "@jest/globals"; // Mock @actions/core jest.unstable_mockModule("@actions/core", () => ({ @@ -50,13 +50,10 @@ beforeEach(() => { (core.getInput as jest.Mock).mockImplementation( (name: string, options?: { required?: boolean }) => { const val = - process.env[ - `INPUT_${name.replace(/ /g, "_").toUpperCase()}` - ] || ""; + process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] || + ""; if (options && options.required && !val) { - throw new Error( - `Input required and not supplied: ${name}` - ); + throw new Error(`Input required and not supplied: ${name}`); } return val.trim(); } diff --git a/__tests__/saveImpl.test.ts b/__tests__/saveImpl.test.ts index 21fd06f..c777077 100644 --- a/__tests__/saveImpl.test.ts +++ b/__tests__/saveImpl.test.ts @@ -1,4 +1,4 @@ -import { jest, test, expect, beforeEach, afterEach } from "@jest/globals"; +import { afterEach, beforeEach, expect, jest, test } from "@jest/globals"; // Mock @actions/core jest.unstable_mockModule("@actions/core", () => ({ @@ -51,13 +51,10 @@ beforeEach(() => { (core.getInput as jest.Mock).mockImplementation( (name: string, options?: { required?: boolean }) => { const val = - process.env[ - `INPUT_${name.replace(/ /g, "_").toUpperCase()}` - ] || ""; + process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] || + ""; if (options && options.required && !val) { - throw new Error( - `Input required and not supplied: ${name}` - ); + throw new Error(`Input required and not supplied: ${name}`); } return val.trim(); } diff --git a/__tests__/saveOnly.test.ts b/__tests__/saveOnly.test.ts index 50735ae..69c5af4 100644 --- a/__tests__/saveOnly.test.ts +++ b/__tests__/saveOnly.test.ts @@ -1,4 +1,4 @@ -import { jest, test, expect, beforeEach, afterEach } from "@jest/globals"; +import { afterEach, beforeEach, expect, jest, test } from "@jest/globals"; // Mock @actions/core jest.unstable_mockModule("@actions/core", () => ({ @@ -50,13 +50,10 @@ beforeEach(() => { (core.getInput as jest.Mock).mockImplementation( (name: string, options?: { required?: boolean }) => { const val = - process.env[ - `INPUT_${name.replace(/ /g, "_").toUpperCase()}` - ] || ""; + process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] || + ""; if (options && options.required && !val) { - throw new Error( - `Input required and not supplied: ${name}` - ); + throw new Error(`Input required and not supplied: ${name}`); } return val.trim(); } diff --git a/__tests__/stateProvider.test.ts b/__tests__/stateProvider.test.ts index 38a6a06..9403ad2 100644 --- a/__tests__/stateProvider.test.ts +++ b/__tests__/stateProvider.test.ts @@ -1,4 +1,6 @@ -import { jest, test, expect, beforeEach, afterEach } from "@jest/globals"; +import { afterEach, beforeEach, expect, jest, test } from "@jest/globals"; + +import type { IStateProvider } from "../src/stateProvider"; // Mock @actions/core jest.unstable_mockModule("@actions/core", () => ({ @@ -28,8 +30,8 @@ jest.unstable_mockModule("@actions/core", () => ({ const core = await import("@actions/core"); const { Events, RefKey, State } = await import("../src/constants"); -const { NullStateProvider, StateProvider } = await import("../src/stateProvider"); -import type { IStateProvider } from "../src/stateProvider"; +const { NullStateProvider, StateProvider } = + await import("../src/stateProvider"); beforeEach(() => { jest.clearAllMocks(); @@ -43,10 +45,14 @@ afterEach(() => { test("StateProvider saves states", async () => { const states = new Map(); - (core.getState as jest.Mock).mockImplementation((key: string) => states.get(key) || ""); - (core.saveState as jest.Mock).mockImplementation((key: string, value: string) => { - states.set(key, value); - }); + (core.getState as jest.Mock).mockImplementation( + (key: string) => states.get(key) || "" + ); + (core.saveState as jest.Mock).mockImplementation( + (key: string, value: string) => { + states.set(key, value); + } + ); const cacheMatchedKey = "node-cache"; diff --git a/jest.config.ts b/jest.config.ts index 76786d4..678dd02 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -1,7 +1,7 @@ export default { clearMocks: true, moduleFileExtensions: ['js', 'ts'], - roots: [''], + roots: ['/__tests__'], testEnvironment: 'node', testMatch: ['**/*.test.ts'], transform: {