GeezerVison is showing github.com — Fix lint and jest issues · actions/cache@5a912e8
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: __tests__/actionUtils.test.ts +7-8Lines changed: 7 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import { jest, test, expect, beforeEach, afterAll } from "@jest/globals"; | | 1 | +import { afterAll, beforeEach, expect, jest, test } from "@jest/globals"; | 2 | 2 |
| 3 | 3 | // Mock @actions/core | 4 | 4 | jest.unstable_mockModule("@actions/core", () => ({ | @@ -53,13 +53,10 @@ beforeEach(() => { | 53 | 53 | (core.getInput as jest.Mock).mockImplementation( | 54 | 54 | (name: string, options?: { required?: boolean }) => { | 55 | 55 | const val = | 56 | | - process.env[ | 57 | | - `INPUT_${name.replace(/ /g, "_").toUpperCase()}` | 58 | | - ] || ""; | | 56 | + process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] || | | 57 | + ""; | 59 | 58 | if (options && options.required && !val) { | 60 | | - throw new Error( | 61 | | - `Input required and not supplied: ${name}` | 62 | | - ); | | 59 | + throw new Error(`Input required and not supplied: ${name}`); | 63 | 60 | } | 64 | 61 | return val.trim(); | 65 | 62 | } | @@ -103,7 +100,9 @@ test("isExactKeyMatch with different keys returns false", () => { | 103 | 100 | }); | 104 | 101 |
| 105 | 102 | test("isExactKeyMatch with different key accents returns false", () => { | 106 | | - expect(actionUtils.isExactKeyMatch("linux-áccent", "linux-accent")).toBe(false); | | 103 | + expect(actionUtils.isExactKeyMatch("linux-áccent", "linux-accent")).toBe( | | 104 | + false | | 105 | + ); | 107 | 106 | }); | 108 | 107 |
| 109 | 108 | test("isExactKeyMatch with same key returns true", () => { | |
Collapse file Copy file name to clipboardExpand all lines: __tests__/restore.test.ts +4-7Lines changed: 4 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import { jest, test, expect, beforeEach, afterEach } from "@jest/globals"; | | 1 | +import { afterEach, beforeEach, expect, jest, test } from "@jest/globals"; | 2 | 2 |
| 3 | 3 | // Mock @actions/core | 4 | 4 | jest.unstable_mockModule("@actions/core", () => ({ | @@ -50,13 +50,10 @@ beforeEach(() => { | 50 | 50 | (core.getInput as jest.Mock).mockImplementation( | 51 | 51 | (name: string, options?: { required?: boolean }) => { | 52 | 52 | const val = | 53 | | - process.env[ | 54 | | - `INPUT_${name.replace(/ /g, "_").toUpperCase()}` | 55 | | - ] || ""; | | 53 | + process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] || | | 54 | + ""; | 56 | 55 | if (options && options.required && !val) { | 57 | | - throw new Error( | 58 | | - `Input required and not supplied: ${name}` | 59 | | - ); | | 56 | + throw new Error(`Input required and not supplied: ${name}`); | 60 | 57 | } | 61 | 58 | return val.trim(); | 62 | 59 | } | |
Collapse file Copy file name to clipboardExpand all lines: __tests__/restoreImpl.test.ts +11-9Lines changed: 11 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import { jest, test, expect, beforeEach, afterEach } from "@jest/globals"; | | 1 | +import { afterEach, beforeEach, expect, jest, test } from "@jest/globals"; | 2 | 2 |
| 3 | 3 | // Mock @actions/core | 4 | 4 | jest.unstable_mockModule("@actions/core", () => ({ | @@ -51,13 +51,10 @@ beforeEach(() => { | 51 | 51 | (core.getInput as jest.Mock).mockImplementation( | 52 | 52 | (name: string, options?: { required?: boolean }) => { | 53 | 53 | const val = | 54 | | - process.env[ | 55 | | - `INPUT_${name.replace(/ /g, "_").toUpperCase()}` | 56 | | - ] || ""; | | 54 | + process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] || | | 55 | + ""; | 57 | 56 | if (options && options.required && !val) { | 58 | | - throw new Error( | 59 | | - `Input required and not supplied: ${name}` | 60 | | - ); | | 57 | + throw new Error(`Input required and not supplied: ${name}`); | 61 | 58 | } | 62 | 59 | return val.trim(); | 63 | 60 | } | @@ -182,7 +179,9 @@ test("restore with large key should fail", async () => { | 182 | 179 | enableCrossOsArchive: false | 183 | 180 | }); | 184 | 181 | (cache.restoreCache as jest.Mock).mockRejectedValue( | 185 | | - new Error(`Key Validation Error: ${key} cannot be larger than 512 characters.`) | | 182 | + new Error( | | 183 | + `Key Validation Error: ${key} cannot be larger than 512 characters.` | | 184 | + ) | 186 | 185 | ); | 187 | 186 | await restoreImpl(new StateProvider()); | 188 | 187 | expect(cache.restoreCache).toHaveBeenCalledTimes(1); | @@ -336,7 +335,10 @@ test("restore with lookup-only set", async () => { | 336 | 335 |
| 337 | 336 | test("restore failure with earlyExit should call process exit", async () => { | 338 | 337 | testUtils.setInput(Inputs.Path, "node_modules"); | 339 | | - const processExitMock = jest.spyOn(process, "exit").mockImplementation((() => {}) as any); | | 338 | + const processExitMock = jest | | 339 | + .spyOn(process, "exit") | | 340 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any | | 341 | + .mockImplementation((() => {}) as any); | 340 | 342 |
| 341 | 343 | await restoreImpl(new StateProvider(), true); | 342 | 344 |
| |
Collapse file Copy file name to clipboardExpand all lines: __tests__/restoreOnly.test.ts +8-8Lines changed: 8 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import { jest, test, expect, beforeEach, afterEach } from "@jest/globals"; | | 1 | +import { afterEach, beforeEach, expect, jest, test } from "@jest/globals"; | 2 | 2 |
| 3 | 3 | // Mock @actions/core | 4 | 4 | jest.unstable_mockModule("@actions/core", () => ({ | @@ -50,13 +50,10 @@ beforeEach(() => { | 50 | 50 | (core.getInput as jest.Mock).mockImplementation( | 51 | 51 | (name: string, options?: { required?: boolean }) => { | 52 | 52 | const val = | 53 | | - process.env[ | 54 | | - `INPUT_${name.replace(/ /g, "_").toUpperCase()}` | 55 | | - ] || ""; | | 53 | + process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] || | | 54 | + ""; | 56 | 55 | if (options && options.required && !val) { | 57 | | - throw new Error( | 58 | | - `Input required and not supplied: ${name}` | 59 | | - ); | | 56 | + throw new Error(`Input required and not supplied: ${name}`); | 60 | 57 | } | 61 | 58 | return val.trim(); | 62 | 59 | } | @@ -167,7 +164,10 @@ test("restore with cache found for restore key", async () => { | 167 | 164 | expect(cache.restoreCache).toHaveBeenCalledTimes(1); | 168 | 165 | expect(core.setOutput).toHaveBeenCalledWith("cache-primary-key", key); | 169 | 166 | expect(core.setOutput).toHaveBeenCalledWith("cache-hit", "false"); | 170 | | - expect(core.setOutput).toHaveBeenCalledWith("cache-matched-key", restoreKey); | | 167 | + expect(core.setOutput).toHaveBeenCalledWith( | | 168 | + "cache-matched-key", | | 169 | + restoreKey | | 170 | + ); | 171 | 171 | expect(core.setOutput).toHaveBeenCalledTimes(3); | 172 | 172 | expect(core.info).toHaveBeenCalledWith( | 173 | 173 | `Cache restored from key: ${restoreKey}` | |
Collapse file Copy file name to clipboardExpand all lines: __tests__/save.test.ts +4-7Lines changed: 4 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import { jest, test, expect, beforeEach, afterEach } from "@jest/globals"; | | 1 | +import { afterEach, beforeEach, expect, jest, test } from "@jest/globals"; | 2 | 2 |
| 3 | 3 | // Mock @actions/core | 4 | 4 | jest.unstable_mockModule("@actions/core", () => ({ | @@ -50,13 +50,10 @@ beforeEach(() => { | 50 | 50 | (core.getInput as jest.Mock).mockImplementation( | 51 | 51 | (name: string, options?: { required?: boolean }) => { | 52 | 52 | const val = | 53 | | - process.env[ | 54 | | - `INPUT_${name.replace(/ /g, "_").toUpperCase()}` | 55 | | - ] || ""; | | 53 | + process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] || | | 54 | + ""; | 56 | 55 | if (options && options.required && !val) { | 57 | | - throw new Error( | 58 | | - `Input required and not supplied: ${name}` | 59 | | - ); | | 56 | + throw new Error(`Input required and not supplied: ${name}`); | 60 | 57 | } | 61 | 58 | return val.trim(); | 62 | 59 | } | |
Collapse file Copy file name to clipboardExpand all lines: __tests__/saveImpl.test.ts +4-7Lines changed: 4 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import { jest, test, expect, beforeEach, afterEach } from "@jest/globals"; | | 1 | +import { afterEach, beforeEach, expect, jest, test } from "@jest/globals"; | 2 | 2 |
| 3 | 3 | // Mock @actions/core | 4 | 4 | jest.unstable_mockModule("@actions/core", () => ({ | @@ -51,13 +51,10 @@ beforeEach(() => { | 51 | 51 | (core.getInput as jest.Mock).mockImplementation( | 52 | 52 | (name: string, options?: { required?: boolean }) => { | 53 | 53 | const val = | 54 | | - process.env[ | 55 | | - `INPUT_${name.replace(/ /g, "_").toUpperCase()}` | 56 | | - ] || ""; | | 54 | + process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] || | | 55 | + ""; | 57 | 56 | if (options && options.required && !val) { | 58 | | - throw new Error( | 59 | | - `Input required and not supplied: ${name}` | 60 | | - ); | | 57 | + throw new Error(`Input required and not supplied: ${name}`); | 61 | 58 | } | 62 | 59 | return val.trim(); | 63 | 60 | } | |
Collapse file Copy file name to clipboardExpand all lines: __tests__/saveOnly.test.ts +4-7Lines changed: 4 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import { jest, test, expect, beforeEach, afterEach } from "@jest/globals"; | | 1 | +import { afterEach, beforeEach, expect, jest, test } from "@jest/globals"; | 2 | 2 |
| 3 | 3 | // Mock @actions/core | 4 | 4 | jest.unstable_mockModule("@actions/core", () => ({ | @@ -50,13 +50,10 @@ beforeEach(() => { | 50 | 50 | (core.getInput as jest.Mock).mockImplementation( | 51 | 51 | (name: string, options?: { required?: boolean }) => { | 52 | 52 | const val = | 53 | | - process.env[ | 54 | | - `INPUT_${name.replace(/ /g, "_").toUpperCase()}` | 55 | | - ] || ""; | | 53 | + process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] || | | 54 | + ""; | 56 | 55 | if (options && options.required && !val) { | 57 | | - throw new Error( | 58 | | - `Input required and not supplied: ${name}` | 59 | | - ); | | 56 | + throw new Error(`Input required and not supplied: ${name}`); | 60 | 57 | } | 61 | 58 | return val.trim(); | 62 | 59 | } | |
Collapse file Copy file name to clipboardExpand all lines: __tests__/stateProvider.test.ts +13-7Lines changed: 13 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import { jest, test, expect, beforeEach, afterEach } from "@jest/globals"; | | 1 | +import { afterEach, beforeEach, expect, jest, test } from "@jest/globals"; | | 2 | + | | 3 | +import type { IStateProvider } from "../src/stateProvider"; | 2 | 4 |
| 3 | 5 | // Mock @actions/core | 4 | 6 | jest.unstable_mockModule("@actions/core", () => ({ | @@ -28,8 +30,8 @@ jest.unstable_mockModule("@actions/core", () => ({ | 28 | 30 |
| 29 | 31 | const core = await import("@actions/core"); | 30 | 32 | const { Events, RefKey, State } = await import("../src/constants"); | 31 | | -const { NullStateProvider, StateProvider } = await import("../src/stateProvider"); | 32 | | -import type { IStateProvider } from "../src/stateProvider"; | | 33 | +const { NullStateProvider, StateProvider } = | | 34 | + await import("../src/stateProvider"); | 33 | 35 |
| 34 | 36 | beforeEach(() => { | 35 | 37 | jest.clearAllMocks(); | @@ -43,10 +45,14 @@ afterEach(() => { | 43 | 45 |
| 44 | 46 | test("StateProvider saves states", async () => { | 45 | 47 | const states = new Map<string, string>(); | 46 | | - (core.getState as jest.Mock).mockImplementation((key: string) => states.get(key) || ""); | 47 | | - (core.saveState as jest.Mock).mockImplementation((key: string, value: string) => { | 48 | | - states.set(key, value); | 49 | | - }); | | 48 | + (core.getState as jest.Mock).mockImplementation( | | 49 | + (key: string) => states.get(key) || "" | | 50 | + ); | | 51 | + (core.saveState as jest.Mock).mockImplementation( | | 52 | + (key: string, value: string) => { | | 53 | + states.set(key, value); | | 54 | + } | | 55 | + ); | 50 | 56 |
| 51 | 57 | const cacheMatchedKey = "node-cache"; | 52 | 58 |
| |
Collapse file Copy file name to clipboardExpand all lines: jest.config.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | export default { | 2 | 2 | clearMocks: true, | 3 | 3 | moduleFileExtensions: ['js', 'ts'], | 4 | | - roots: ['<rootDir>'], | | 4 | + roots: ['<rootDir>/__tests__'], | 5 | 5 | testEnvironment: 'node', | 6 | 6 | testMatch: ['**/*.test.ts'], | 7 | 7 | transform: { | |
|