Fix lint and jest issues

This commit is contained in:
Joshua Brooks
2026-05-20 20:18:29 +00:00
parent b9bf592b98
commit 5a912e8b4a
9 changed files with 56 additions and 61 deletions

View File

@@ -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", () => {

View File

@@ -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();
}

View File

@@ -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);

View File

@@ -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}`

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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<string, string>();
(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";

View File

@@ -1,7 +1,7 @@
export default {
clearMocks: true,
moduleFileExtensions: ['js', 'ts'],
roots: ['<rootDir>'],
roots: ['<rootDir>/__tests__'],
testEnvironment: 'node',
testMatch: ['**/*.test.ts'],
transform: {