From 6e2615b78c29969a943ccfaf886c958f06012699 Mon Sep 17 00:00:00 2001 From: cade Date: Wed, 1 Jul 2026 11:53:55 +0800 Subject: [PATCH] Fixed type errors in test/ --- .../stubs/providers/InMemory.FsProvider.ts | 2 +- .../providers/stub.InteractionProvider.ts | 2 +- .../EcosystemSchema/EcosystemSchema.spec.ts | 5 +-- .../tests/utils/utils.ArrayUtils.ts.spec.ts | 34 +++++++++---------- .../utils/utils.DependencyUtils.ts.spec.ts | 4 +-- test/vitest/utils/ObjectTestUtils.ts | 2 +- 6 files changed, 25 insertions(+), 24 deletions(-) diff --git a/test/vitest/stubs/providers/InMemory.FsProvider.ts b/test/vitest/stubs/providers/InMemory.FsProvider.ts index 80ac858ad..ee2279ca7 100644 --- a/test/vitest/stubs/providers/InMemory.FsProvider.ts +++ b/test/vitest/stubs/providers/InMemory.FsProvider.ts @@ -2,7 +2,7 @@ import FsProvider from '../../../../src/providers/generic/file/FsProvider'; import StatInterface from '../../../../src/providers/generic/file/StatInterface'; import * as path from 'path'; -type FileType = {name: string, type: "FILE" | "DIR", nodes: FileType[] | undefined, content: string | undefined, mtime: Date}; +type FileType = {name: string, type: "FILE" | "DIR", nodes: FileType[] | undefined, content: string | Buffer | undefined, mtime: Date}; /** diff --git a/test/vitest/stubs/providers/stub.InteractionProvider.ts b/test/vitest/stubs/providers/stub.InteractionProvider.ts index 59fae23e3..19f559f8c 100644 --- a/test/vitest/stubs/providers/stub.InteractionProvider.ts +++ b/test/vitest/stubs/providers/stub.InteractionProvider.ts @@ -25,7 +25,7 @@ export default class StubInteractionProvider extends InteractionProvider { throw new Error("Stub access must be mocked or spied"); } - async getEnvironmentVariables(): Promise { + async getEnvironmentVariables(): Promise> { throw new Error("Stub access must be mocked or spied"); } diff --git a/test/vitest/tests/unit/EcosystemSchema/EcosystemSchema.spec.ts b/test/vitest/tests/unit/EcosystemSchema/EcosystemSchema.spec.ts index 8b3a701da..d2a46d1b8 100644 --- a/test/vitest/tests/unit/EcosystemSchema/EcosystemSchema.spec.ts +++ b/test/vitest/tests/unit/EcosystemSchema/EcosystemSchema.spec.ts @@ -6,7 +6,7 @@ vi.mock('../../../../../src/assets/data/ecosystemJsonSchema.json', () => ({ get default() { return mockJsonSchema; } })); -import type {ThunderstoreEcosystem} from '../../../../../src/assets/data/ecosystemTypes'; +import type {R2Modman, ThunderstoreEcosystem} from '../../../../../src/assets/data/ecosystemTypes'; import {VersionedThunderstoreEcosystem, updateEcosystemReactives, updateLatestEcosystemSchema} from '../../../../../src/r2mm/ecosystem/EcosystemSchema'; import {EcosystemModloaderPackages, EcosystemSupportedGames} from '../../../../../src/model/schema/ThunderstoreSchema'; import {MODLOADER_PACKAGES, MOD_LOADER_VARIANTS, updateModLoaderExports} from '../../../../../src/r2mm/installing/profile_installers/ModLoaderVariantRecord'; @@ -245,13 +245,14 @@ describe('EcosystemSchema', () => { }); test('populates games from cache into reactives when fetch fails with existing cache', async () => { + const r2Field = [{ meta: { iconUrl: null } }] as R2Modman[]; await writeCacheFile({ games: { 'test-cached-game': { distributions: [], label: 'Test Cached Game', meta: { displayName: 'Test Cached Game', iconUrl: null }, - r2modman: [{ meta: { iconUrl: null } }], + r2modman: r2Field, uuid: 'test-uuid', }, }, diff --git a/test/vitest/tests/utils/utils.ArrayUtils.ts.spec.ts b/test/vitest/tests/utils/utils.ArrayUtils.ts.spec.ts index ec137d2e4..11a5e6bb1 100644 --- a/test/vitest/tests/utils/utils.ArrayUtils.ts.spec.ts +++ b/test/vitest/tests/utils/utils.ArrayUtils.ts.spec.ts @@ -29,40 +29,40 @@ describe("ArrayUtils.chunk", () => { const actual1 = chunk([1, 2, 3, 4], 1); expect(Array.isArray(actual1)).toBeTruthy(); expect(actual1.length).toStrictEqual(4); - expect(actual1[0][0]).toStrictEqual(1); - expect(actual1[1][0]).toStrictEqual(2); - expect(actual1[2][0]).toStrictEqual(3); - expect(actual1[3][0]).toStrictEqual(4); + expect(actual1[0]![0]).toStrictEqual(1); + expect(actual1[1]![0]).toStrictEqual(2); + expect(actual1[2]![0]).toStrictEqual(3); + expect(actual1[3]![0]).toStrictEqual(4); const actual2 = chunk(["a", "b", "c", "d"], 2); expect(Array.isArray(actual2)).toBeTruthy(); expect(actual2.length).toStrictEqual(2); - expect(actual2[0][0]).toStrictEqual("a"); - expect(actual2[0][1]).toStrictEqual("b"); - expect(actual2[1][0]).toStrictEqual("c"); - expect(actual2[1][1]).toStrictEqual("d"); + expect(actual2[0]![0]).toStrictEqual("a"); + expect(actual2[0]![1]).toStrictEqual("b"); + expect(actual2[1]![0]).toStrictEqual("c"); + expect(actual2[1]![1]).toStrictEqual("d"); const actual3 = chunk([{x: 1}, {x: "a"}, {x: () => null}, {x: []}], 4); expect(Array.isArray(actual3)).toBeTruthy(); expect(actual3.length).toStrictEqual(1); - expect(actual3[0][0]["x"]).toStrictEqual(1); - expect(actual3[0][1]["x"]).toStrictEqual("a"); - expect(typeof actual3[0][2]["x"]).toStrictEqual("function"); - expect(Array.isArray(actual3[0][3]["x"])).toBeTruthy(); + expect(actual3[0]![0]!["x"]).toStrictEqual(1); + expect(actual3[0]![1]!["x"]).toStrictEqual("a"); + expect(typeof actual3[0]![2]!["x"]).toStrictEqual("function"); + expect(Array.isArray(actual3[0]![3]!["x"])).toBeTruthy(); }); test("Chunks arrays with orphans", () => { const actual1 = chunk([1, 2, 3], 2); expect(Array.isArray(actual1)).toBeTruthy(); expect(actual1.length).toStrictEqual(2); - expect(actual1[0].length).toStrictEqual(2); - expect(actual1[1].length).toStrictEqual(1); + expect(actual1[0]!.length).toStrictEqual(2); + expect(actual1[1]!.length).toStrictEqual(1); const actual2 = chunk([1, 2, 3, "a", "b", "c", 4, 5], 3); expect(Array.isArray(actual2)).toBeTruthy(); expect(actual2.length).toStrictEqual(3); - expect(actual2[0].length).toStrictEqual(3); - expect(actual2[1].length).toStrictEqual(3); - expect(actual2[2].length).toStrictEqual(2); + expect(actual2[0]!.length).toStrictEqual(3); + expect(actual2[1]!.length).toStrictEqual(3); + expect(actual2[2]!.length).toStrictEqual(2); }); }); diff --git a/test/vitest/tests/utils/utils.DependencyUtils.ts.spec.ts b/test/vitest/tests/utils/utils.DependencyUtils.ts.spec.ts index a8180c665..bdb7322ac 100644 --- a/test/vitest/tests/utils/utils.DependencyUtils.ts.spec.ts +++ b/test/vitest/tests/utils/utils.DependencyUtils.ts.spec.ts @@ -82,10 +82,10 @@ function addMockPackage(modData: { // Use original, unsorted arguments to return the first version passed in. const version = new ThunderstoreVersion(); - const versionStr = modData.versions[0].version; + const versionStr = modData.versions[0]!.version; version.setVersionNumber(new VersionNumber(versionStr)); version.setName(`${data.full_name}-${versionStr}`); - version.setDependencies(modData.versions[0].dependencies || []); + version.setDependencies(modData.versions[0]!.dependencies || []); firstCombo.setVersion(version); return firstCombo; diff --git a/test/vitest/utils/ObjectTestUtils.ts b/test/vitest/utils/ObjectTestUtils.ts index 6707632ff..63d9347fe 100644 --- a/test/vitest/utils/ObjectTestUtils.ts +++ b/test/vitest/utils/ObjectTestUtils.ts @@ -2,7 +2,7 @@ export default class ObjectTestUtils { public static lazyClone(copy: T): T { const obj: any = {}; - Object.keys(copy).forEach((key: any) => { + Object.keys(copy as object).forEach((key: any) => { obj[key] = (copy as any)[key]; }); return obj as unknown as T;