Skip to content

Commit 5a912e8

Browse files
committed
Fix lint and jest issues
1 parent b9bf592 commit 5a912e8

9 files changed

Lines changed: 56 additions & 61 deletions

‎__tests__/actionUtils.test.ts‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { jest, test, expect, beforeEach, afterAll } from "@jest/globals";
1+
import { afterAll, beforeEach, expect, jest, test } from "@jest/globals";
22

33
// Mock @actions/core
44
jest.unstable_mockModule("@actions/core", () => ({
@@ -53,13 +53,10 @@ beforeEach(() => {
5353
(core.getInput as jest.Mock).mockImplementation(
5454
(name: string, options?: { required?: boolean }) => {
5555
const val =
56-
process.env[
57-
`INPUT_${name.replace(/ /g, "_").toUpperCase()}`
58-
] || "";
56+
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] ||
57+
"";
5958
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}`);
6360
}
6461
return val.trim();
6562
}
@@ -103,7 +100,9 @@ test("isExactKeyMatch with different keys returns false", () => {
103100
});
104101

105102
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+
);
107106
});
108107

109108
test("isExactKeyMatch with same key returns true", () => {

‎__tests__/restore.test.ts‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { jest, test, expect, beforeEach, afterEach } from "@jest/globals";
1+
import { afterEach, beforeEach, expect, jest, test } from "@jest/globals";
22

33
// Mock @actions/core
44
jest.unstable_mockModule("@actions/core", () => ({
@@ -50,13 +50,10 @@ beforeEach(() => {
5050
(core.getInput as jest.Mock).mockImplementation(
5151
(name: string, options?: { required?: boolean }) => {
5252
const val =
53-
process.env[
54-
`INPUT_${name.replace(/ /g, "_").toUpperCase()}`
55-
] || "";
53+
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] ||
54+
"";
5655
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}`);
6057
}
6158
return val.trim();
6259
}

‎__tests__/restoreImpl.test.ts‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { jest, test, expect, beforeEach, afterEach } from "@jest/globals";
1+
import { afterEach, beforeEach, expect, jest, test } from "@jest/globals";
22

33
// Mock @actions/core
44
jest.unstable_mockModule("@actions/core", () => ({
@@ -51,13 +51,10 @@ beforeEach(() => {
5151
(core.getInput as jest.Mock).mockImplementation(
5252
(name: string, options?: { required?: boolean }) => {
5353
const val =
54-
process.env[
55-
`INPUT_${name.replace(/ /g, "_").toUpperCase()}`
56-
] || "";
54+
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] ||
55+
"";
5756
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}`);
6158
}
6259
return val.trim();
6360
}
@@ -182,7 +179,9 @@ test("restore with large key should fail", async () => {
182179
enableCrossOsArchive: false
183180
});
184181
(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+
)
186185
);
187186
await restoreImpl(new StateProvider());
188187
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
@@ -336,7 +335,10 @@ test("restore with lookup-only set", async () => {
336335

337336
test("restore failure with earlyExit should call process exit", async () => {
338337
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);
340342

341343
await restoreImpl(new StateProvider(), true);
342344

‎__tests__/restoreOnly.test.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { jest, test, expect, beforeEach, afterEach } from "@jest/globals";
1+
import { afterEach, beforeEach, expect, jest, test } from "@jest/globals";
22

33
// Mock @actions/core
44
jest.unstable_mockModule("@actions/core", () => ({
@@ -50,13 +50,10 @@ beforeEach(() => {
5050
(core.getInput as jest.Mock).mockImplementation(
5151
(name: string, options?: { required?: boolean }) => {
5252
const val =
53-
process.env[
54-
`INPUT_${name.replace(/ /g, "_").toUpperCase()}`
55-
] || "";
53+
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] ||
54+
"";
5655
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}`);
6057
}
6158
return val.trim();
6259
}
@@ -167,7 +164,10 @@ test("restore with cache found for restore key", async () => {
167164
expect(cache.restoreCache).toHaveBeenCalledTimes(1);
168165
expect(core.setOutput).toHaveBeenCalledWith("cache-primary-key", key);
169166
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+
);
171171
expect(core.setOutput).toHaveBeenCalledTimes(3);
172172
expect(core.info).toHaveBeenCalledWith(
173173
`Cache restored from key: ${restoreKey}`

‎__tests__/save.test.ts‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { jest, test, expect, beforeEach, afterEach } from "@jest/globals";
1+
import { afterEach, beforeEach, expect, jest, test } from "@jest/globals";
22

33
// Mock @actions/core
44
jest.unstable_mockModule("@actions/core", () => ({
@@ -50,13 +50,10 @@ beforeEach(() => {
5050
(core.getInput as jest.Mock).mockImplementation(
5151
(name: string, options?: { required?: boolean }) => {
5252
const val =
53-
process.env[
54-
`INPUT_${name.replace(/ /g, "_").toUpperCase()}`
55-
] || "";
53+
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] ||
54+
"";
5655
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}`);
6057
}
6158
return val.trim();
6259
}

‎__tests__/saveImpl.test.ts‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { jest, test, expect, beforeEach, afterEach } from "@jest/globals";
1+
import { afterEach, beforeEach, expect, jest, test } from "@jest/globals";
22

33
// Mock @actions/core
44
jest.unstable_mockModule("@actions/core", () => ({
@@ -51,13 +51,10 @@ beforeEach(() => {
5151
(core.getInput as jest.Mock).mockImplementation(
5252
(name: string, options?: { required?: boolean }) => {
5353
const val =
54-
process.env[
55-
`INPUT_${name.replace(/ /g, "_").toUpperCase()}`
56-
] || "";
54+
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] ||
55+
"";
5756
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}`);
6158
}
6259
return val.trim();
6360
}

‎__tests__/saveOnly.test.ts‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { jest, test, expect, beforeEach, afterEach } from "@jest/globals";
1+
import { afterEach, beforeEach, expect, jest, test } from "@jest/globals";
22

33
// Mock @actions/core
44
jest.unstable_mockModule("@actions/core", () => ({
@@ -50,13 +50,10 @@ beforeEach(() => {
5050
(core.getInput as jest.Mock).mockImplementation(
5151
(name: string, options?: { required?: boolean }) => {
5252
const val =
53-
process.env[
54-
`INPUT_${name.replace(/ /g, "_").toUpperCase()}`
55-
] || "";
53+
process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] ||
54+
"";
5655
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}`);
6057
}
6158
return val.trim();
6259
}

‎__tests__/stateProvider.test.ts‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
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";
24

35
// Mock @actions/core
46
jest.unstable_mockModule("@actions/core", () => ({
@@ -28,8 +30,8 @@ jest.unstable_mockModule("@actions/core", () => ({
2830

2931
const core = await import("@actions/core");
3032
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");
3335

3436
beforeEach(() => {
3537
jest.clearAllMocks();
@@ -43,10 +45,14 @@ afterEach(() => {
4345

4446
test("StateProvider saves states", async () => {
4547
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+
);
5056

5157
const cacheMatchedKey = "node-cache";
5258

‎jest.config.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export default {
22
clearMocks: true,
33
moduleFileExtensions: ['js', 'ts'],
4-
roots: ['<rootDir>'],
4+
roots: ['<rootDir>/__tests__'],
55
testEnvironment: 'node',
66
testMatch: ['**/*.test.ts'],
77
transform: {

0 commit comments

Comments
 (0)
Sponsor
SponsoredKunjungi sekarang
Promo