mirror of
https://github.com/actions/cache.git
synced 2026-05-21 12:48:18 +01:00
Fix lint and jest issues
This commit is contained in:
@@ -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
|
// Mock @actions/core
|
||||||
jest.unstable_mockModule("@actions/core", () => ({
|
jest.unstable_mockModule("@actions/core", () => ({
|
||||||
@@ -53,13 +53,10 @@ beforeEach(() => {
|
|||||||
(core.getInput as jest.Mock).mockImplementation(
|
(core.getInput as jest.Mock).mockImplementation(
|
||||||
(name: string, options?: { required?: boolean }) => {
|
(name: string, options?: { required?: boolean }) => {
|
||||||
const val =
|
const val =
|
||||||
process.env[
|
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] ||
|
||||||
`INPUT_${name.replace(/ /g, "_").toUpperCase()}`
|
"";
|
||||||
] || "";
|
|
||||||
if (options && options.required && !val) {
|
if (options && options.required && !val) {
|
||||||
throw new Error(
|
throw new Error(`Input required and not supplied: ${name}`);
|
||||||
`Input required and not supplied: ${name}`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return val.trim();
|
return val.trim();
|
||||||
}
|
}
|
||||||
@@ -103,7 +100,9 @@ test("isExactKeyMatch with different keys returns false", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("isExactKeyMatch with different key accents 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", () => {
|
test("isExactKeyMatch with same key returns true", () => {
|
||||||
|
|||||||
@@ -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
|
// Mock @actions/core
|
||||||
jest.unstable_mockModule("@actions/core", () => ({
|
jest.unstable_mockModule("@actions/core", () => ({
|
||||||
@@ -50,13 +50,10 @@ beforeEach(() => {
|
|||||||
(core.getInput as jest.Mock).mockImplementation(
|
(core.getInput as jest.Mock).mockImplementation(
|
||||||
(name: string, options?: { required?: boolean }) => {
|
(name: string, options?: { required?: boolean }) => {
|
||||||
const val =
|
const val =
|
||||||
process.env[
|
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] ||
|
||||||
`INPUT_${name.replace(/ /g, "_").toUpperCase()}`
|
"";
|
||||||
] || "";
|
|
||||||
if (options && options.required && !val) {
|
if (options && options.required && !val) {
|
||||||
throw new Error(
|
throw new Error(`Input required and not supplied: ${name}`);
|
||||||
`Input required and not supplied: ${name}`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return val.trim();
|
return val.trim();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
// Mock @actions/core
|
||||||
jest.unstable_mockModule("@actions/core", () => ({
|
jest.unstable_mockModule("@actions/core", () => ({
|
||||||
@@ -51,13 +51,10 @@ beforeEach(() => {
|
|||||||
(core.getInput as jest.Mock).mockImplementation(
|
(core.getInput as jest.Mock).mockImplementation(
|
||||||
(name: string, options?: { required?: boolean }) => {
|
(name: string, options?: { required?: boolean }) => {
|
||||||
const val =
|
const val =
|
||||||
process.env[
|
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] ||
|
||||||
`INPUT_${name.replace(/ /g, "_").toUpperCase()}`
|
"";
|
||||||
] || "";
|
|
||||||
if (options && options.required && !val) {
|
if (options && options.required && !val) {
|
||||||
throw new Error(
|
throw new Error(`Input required and not supplied: ${name}`);
|
||||||
`Input required and not supplied: ${name}`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return val.trim();
|
return val.trim();
|
||||||
}
|
}
|
||||||
@@ -182,7 +179,9 @@ test("restore with large key should fail", async () => {
|
|||||||
enableCrossOsArchive: false
|
enableCrossOsArchive: false
|
||||||
});
|
});
|
||||||
(cache.restoreCache as jest.Mock).mockRejectedValue(
|
(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());
|
await restoreImpl(new StateProvider());
|
||||||
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
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 () => {
|
test("restore failure with earlyExit should call process exit", async () => {
|
||||||
testUtils.setInput(Inputs.Path, "node_modules");
|
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);
|
await restoreImpl(new StateProvider(), true);
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
// Mock @actions/core
|
||||||
jest.unstable_mockModule("@actions/core", () => ({
|
jest.unstable_mockModule("@actions/core", () => ({
|
||||||
@@ -50,13 +50,10 @@ beforeEach(() => {
|
|||||||
(core.getInput as jest.Mock).mockImplementation(
|
(core.getInput as jest.Mock).mockImplementation(
|
||||||
(name: string, options?: { required?: boolean }) => {
|
(name: string, options?: { required?: boolean }) => {
|
||||||
const val =
|
const val =
|
||||||
process.env[
|
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] ||
|
||||||
`INPUT_${name.replace(/ /g, "_").toUpperCase()}`
|
"";
|
||||||
] || "";
|
|
||||||
if (options && options.required && !val) {
|
if (options && options.required && !val) {
|
||||||
throw new Error(
|
throw new Error(`Input required and not supplied: ${name}`);
|
||||||
`Input required and not supplied: ${name}`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return val.trim();
|
return val.trim();
|
||||||
}
|
}
|
||||||
@@ -167,7 +164,10 @@ test("restore with cache found for restore key", async () => {
|
|||||||
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
|
||||||
expect(core.setOutput).toHaveBeenCalledWith("cache-primary-key", key);
|
expect(core.setOutput).toHaveBeenCalledWith("cache-primary-key", key);
|
||||||
expect(core.setOutput).toHaveBeenCalledWith("cache-hit", "false");
|
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.setOutput).toHaveBeenCalledTimes(3);
|
||||||
expect(core.info).toHaveBeenCalledWith(
|
expect(core.info).toHaveBeenCalledWith(
|
||||||
`Cache restored from key: ${restoreKey}`
|
`Cache restored from key: ${restoreKey}`
|
||||||
|
|||||||
@@ -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
|
// Mock @actions/core
|
||||||
jest.unstable_mockModule("@actions/core", () => ({
|
jest.unstable_mockModule("@actions/core", () => ({
|
||||||
@@ -50,13 +50,10 @@ beforeEach(() => {
|
|||||||
(core.getInput as jest.Mock).mockImplementation(
|
(core.getInput as jest.Mock).mockImplementation(
|
||||||
(name: string, options?: { required?: boolean }) => {
|
(name: string, options?: { required?: boolean }) => {
|
||||||
const val =
|
const val =
|
||||||
process.env[
|
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] ||
|
||||||
`INPUT_${name.replace(/ /g, "_").toUpperCase()}`
|
"";
|
||||||
] || "";
|
|
||||||
if (options && options.required && !val) {
|
if (options && options.required && !val) {
|
||||||
throw new Error(
|
throw new Error(`Input required and not supplied: ${name}`);
|
||||||
`Input required and not supplied: ${name}`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return val.trim();
|
return val.trim();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
// Mock @actions/core
|
||||||
jest.unstable_mockModule("@actions/core", () => ({
|
jest.unstable_mockModule("@actions/core", () => ({
|
||||||
@@ -51,13 +51,10 @@ beforeEach(() => {
|
|||||||
(core.getInput as jest.Mock).mockImplementation(
|
(core.getInput as jest.Mock).mockImplementation(
|
||||||
(name: string, options?: { required?: boolean }) => {
|
(name: string, options?: { required?: boolean }) => {
|
||||||
const val =
|
const val =
|
||||||
process.env[
|
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] ||
|
||||||
`INPUT_${name.replace(/ /g, "_").toUpperCase()}`
|
"";
|
||||||
] || "";
|
|
||||||
if (options && options.required && !val) {
|
if (options && options.required && !val) {
|
||||||
throw new Error(
|
throw new Error(`Input required and not supplied: ${name}`);
|
||||||
`Input required and not supplied: ${name}`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return val.trim();
|
return val.trim();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
// Mock @actions/core
|
||||||
jest.unstable_mockModule("@actions/core", () => ({
|
jest.unstable_mockModule("@actions/core", () => ({
|
||||||
@@ -50,13 +50,10 @@ beforeEach(() => {
|
|||||||
(core.getInput as jest.Mock).mockImplementation(
|
(core.getInput as jest.Mock).mockImplementation(
|
||||||
(name: string, options?: { required?: boolean }) => {
|
(name: string, options?: { required?: boolean }) => {
|
||||||
const val =
|
const val =
|
||||||
process.env[
|
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] ||
|
||||||
`INPUT_${name.replace(/ /g, "_").toUpperCase()}`
|
"";
|
||||||
] || "";
|
|
||||||
if (options && options.required && !val) {
|
if (options && options.required && !val) {
|
||||||
throw new Error(
|
throw new Error(`Input required and not supplied: ${name}`);
|
||||||
`Input required and not supplied: ${name}`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return val.trim();
|
return val.trim();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
// Mock @actions/core
|
||||||
jest.unstable_mockModule("@actions/core", () => ({
|
jest.unstable_mockModule("@actions/core", () => ({
|
||||||
@@ -28,8 +30,8 @@ jest.unstable_mockModule("@actions/core", () => ({
|
|||||||
|
|
||||||
const core = await import("@actions/core");
|
const core = await import("@actions/core");
|
||||||
const { Events, RefKey, State } = await import("../src/constants");
|
const { Events, RefKey, State } = await import("../src/constants");
|
||||||
const { NullStateProvider, StateProvider } = await import("../src/stateProvider");
|
const { NullStateProvider, StateProvider } =
|
||||||
import type { IStateProvider } from "../src/stateProvider";
|
await import("../src/stateProvider");
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
@@ -43,10 +45,14 @@ afterEach(() => {
|
|||||||
|
|
||||||
test("StateProvider saves states", async () => {
|
test("StateProvider saves states", async () => {
|
||||||
const states = new Map<string, string>();
|
const states = new Map<string, string>();
|
||||||
(core.getState as jest.Mock).mockImplementation((key: string) => states.get(key) || "");
|
(core.getState as jest.Mock).mockImplementation(
|
||||||
(core.saveState as jest.Mock).mockImplementation((key: string, value: string) => {
|
(key: string) => states.get(key) || ""
|
||||||
states.set(key, value);
|
);
|
||||||
});
|
(core.saveState as jest.Mock).mockImplementation(
|
||||||
|
(key: string, value: string) => {
|
||||||
|
states.set(key, value);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const cacheMatchedKey = "node-cache";
|
const cacheMatchedKey = "node-cache";
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
export default {
|
export default {
|
||||||
clearMocks: true,
|
clearMocks: true,
|
||||||
moduleFileExtensions: ['js', 'ts'],
|
moduleFileExtensions: ['js', 'ts'],
|
||||||
roots: ['<rootDir>'],
|
roots: ['<rootDir>/__tests__'],
|
||||||
testEnvironment: 'node',
|
testEnvironment: 'node',
|
||||||
testMatch: ['**/*.test.ts'],
|
testMatch: ['**/*.test.ts'],
|
||||||
transform: {
|
transform: {
|
||||||
|
|||||||
Reference in New Issue
Block a user