Skip to content

Commit edee81d

Browse files
committed
fix: ts configs
fix: try to make unit tests work fix: actually make unit tests work feat: add unit tests for default assets fix: tsconfig issues again
1 parent 131041b commit edee81d

15 files changed

+84
-33
lines changed

fission/manifest.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type ManifestFileType = Record<"robots"|"private"|"fields", { filename: string, hash: string }[]>

fission/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
"fmt:fix": "bunx --bun biome format src --write",
2222
"style": "bun run fmt && bun run lint",
2323
"style:fix": "bun run fmt:fix && bun run lint:fix",
24-
"assetpack": "git lfs pull && tar -xf public/assetpack.zip -C public/",
25-
"assetpack:update": "cd public && zip -FS -r assetpack.zip Downloadables",
24+
"assetpack": "git lfs pull && (rm -rf public/Downloadables;tar -xf public/assetpack.zip -C public/)",
25+
"assetpack:update": "bun update_manifest.ts && cd public && zip -FS -r assetpack.zip Downloadables",
2626
"playwright:install": "bun x playwright install",
2727
"electron:start": "electron-forge start",
2828
"electron:package": "electron-forge package",

fission/src/mirabuf/DefaultAssetLoader.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import { type MirabufCacheInfo, MiraType } from "@/mirabuf/MirabufLoader.ts"
2-
import type { ManifestFileType } from "../../update_manifest.ts"
2+
import type { ManifestFileType } from "../../manifest.d.ts"
33

44
export type DefaultAssetInfo = Required<Pick<MirabufCacheInfo, "hash" | "remotePath" | "miraType" | "name">>
55

66
class DefaultAssetLoader {
77
private static _assets: DefaultAssetInfo[] = []
8-
8+
private static _hasLoaded = false
99
static {
10-
setTimeout(() => this.refresh(), 1000)
10+
setTimeout(() => {
11+
if (!this._hasLoaded) this.refresh().catch(console.error)
12+
}, 1000)
1113
}
1214

13-
private static async refresh() {
15+
public static async refresh() {
16+
this._hasLoaded = true
1417
this._assets = []
1518

1619
const isElectron = window.electronAPI != null

fission/src/mirabuf/MirabufLoader.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,7 @@ class MirabufCachingService {
222222

223223
if (expectedHash != null && cached?.hash != null && cached?.hash != expectedHash) {
224224
globalAddToast("warning", "Hash Mismatch", `Try downloading again`)
225-
console.log(expectedHash, cached?.hash)
226-
console.log(expectedHash == cached?.hash)
225+
console.warn("mismatched hashes", expectedHash, cached?.hash)
227226
// await this.remove(cached.hash)
228227
}
229228

fission/src/test/bootstrap/AppMount.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ describe("React Mounting", async () => {
5353
test("App fully mounts through main.tsx", async ({ annotate, skip }) => {
5454
skip(server.browser == "firefox", "WebGL bug in Github Actions on Firefox")
5555

56+
// biome-ignore lint/nursery/noTsIgnore: ts-expect-error doesn't work here for some reason
57+
// @ts-ignore funky dynamic import
5658
await import("@/main.tsx")
5759

5860
expect(window.convertAuthToken).toBeDefined()
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { assert, beforeAll, beforeEach, describe, expect, test, vi } from "vitest"
2+
import DefaultAssetLoader from "@/mirabuf/DefaultAssetLoader.ts"
3+
import MirabufLoader from "@/mirabuf/MirabufLoader.ts"
4+
import MirabufCachingService, { MiraType } from "@/mirabuf/MirabufLoader.ts"
5+
6+
describe("Default Asset Tests", () => {
7+
beforeAll(async () => {
8+
await DefaultAssetLoader.refresh()
9+
vi.spyOn(console, "log").mockImplementation(() => {})
10+
})
11+
beforeEach(async () => {
12+
await MirabufLoader.removeAll()
13+
})
14+
15+
test("Manifest loaded", () => {
16+
expect(DefaultAssetLoader.fields.length).toBeGreaterThan(1)
17+
expect(DefaultAssetLoader.robots.length).toBeGreaterThan(1)
18+
})
19+
20+
test("Manifest hashes match assets (fields)", async () => {
21+
for (const asset of DefaultAssetLoader.fields) {
22+
const info = await MirabufCachingService.cacheRemote(asset.remotePath, asset.miraType)
23+
assert.exists(info)
24+
expect(asset.hash, `Hashes for "${info.name}" do not match`).toBe(info.hash)
25+
expect(asset.miraType).toBe(MiraType.FIELD)
26+
await MirabufCachingService.remove(info.hash)
27+
}
28+
expect(MirabufCachingService.getAll()).toHaveLength(0)
29+
})
30+
test("Manifest hashes match assets (robots)", async () => {
31+
for (const asset of DefaultAssetLoader.robots) {
32+
const info = await MirabufCachingService.cacheRemote(asset.remotePath, asset.miraType)
33+
assert.exists(info)
34+
expect(asset.hash, `Hashes for "${info.name}" do not match`).toBe(info.hash)
35+
expect(asset.miraType).toBe(MiraType.ROBOT)
36+
await MirabufCachingService.remove(info.hash)
37+
}
38+
expect(MirabufCachingService.getAll()).toHaveLength(0)
39+
})
40+
})

fission/src/test/mirabuf/FieldMiraEditor.test.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { assert, describe, expect, test, vi } from "vitest"
22
import MirabufCachingService, { MiraType } from "@/mirabuf/MirabufLoader.ts"
33
import { createMirabuf } from "@/mirabuf/MirabufSceneObject.ts"
4+
import { mirabuf } from "@/proto/mirabuf"
45
import {
56
type Alliance,
67
defaultRobotSpawnLocation,
78
type ScoringZonePreferences,
89
} from "@/systems/preferences/PreferenceTypes.ts"
910
import FieldMiraEditor from "../../mirabuf/FieldMiraEditor.ts"
10-
import { mirabuf } from "../../proto/mirabuf"
1111

1212
function mockParts(): mirabuf.IParts {
1313
return { userData: { data: {} } }
@@ -148,17 +148,18 @@ describe("Devtool Scoring Zones Caching Tests", () => {
148148

149149
describe("Asset tests", () => {
150150
test("FRC Field 2018_v13 has spawn locations", async () => {
151-
const file = await MirabufCachingService.cacheRemote("/api/mira/fields/FRC Field 2018_v13.mira", MiraType.FIELD)
152-
.then(x => MirabufCachingService.get(x!.hash))
153-
.catch(e => {
154-
console.error("Could not get mirabuf file", e)
155-
return undefined
156-
})
151+
const cacheInfo = await MirabufCachingService.cacheRemote(
152+
"/api/mira/fields/FRC Field 2018_v13.mira",
153+
MiraType.FIELD
154+
)
155+
assert.exists(cacheInfo)
156+
const file = await MirabufCachingService.get(cacheInfo.hash)
157157
assert.exists(file)
158158

159159
const mirabuf = await createMirabuf(file)
160160
assert.exists(mirabuf)
161161
assert.exists(mirabuf.fieldPreferences)
162+
console.log(mirabuf.fieldPreferences)
162163
expect(mirabuf.fieldPreferences.spawnLocations.hasConfiguredLocations).toBe(true)
163164
expect(mirabuf.fieldPreferences.spawnLocations.red["1"]).not.toStrictEqual(defaultRobotSpawnLocation())
164165
expect(mirabuf.fieldPreferences.spawnLocations.default).not.toStrictEqual(defaultRobotSpawnLocation())

fission/src/test/mirabuf/MirabufLoader.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ describe("MirabufLoader", () => {
146146
expect(info).toBeDefined()
147147
expect(info?.miraType).toBe(MiraType.FIELD)
148148
expect(info?.name).toBe("FRC Field 2023 v7")
149+
expect(info?.hash).toBe("96b0d75cf3fde2c90a9b63e2497170e37b3e40")
149150
const assembly = await MirabufLoader.get(info!.hash)
150151
expect(assembly).toBeDefined()
151152
expect(assembly?.info?.name).toBe(info!.name)

fission/src/ui/modals/MainMenuModal.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ const MainMenuModal: React.FC<ModalImplProps<void, MainMenuCustomProps>> = ({ mo
4646
Promise.all([
4747
MirabufCachingService.cacheRemote("/api/mira/fields/FRC Field 2023_v7.mira", MiraType.FIELD),
4848
MirabufCachingService.cacheRemote("/api/mira/robots/Dozer_v9.mira", MiraType.ROBOT),
49-
]).then(([cachedField, cachedRobot]) => {
49+
]).then(async ([cachedField, cachedRobot]) => {
5050
if (cachedField && cachedRobot) {
51-
spawnCachedMira(cachedField, MiraType.FIELD)
52-
spawnCachedMira(cachedRobot, MiraType.ROBOT)
51+
await spawnCachedMira(cachedField)
52+
await spawnCachedMira(cachedRobot)
5353
}
5454
})
5555
}}

fission/src/util/TypeConversions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type Jolt from "@azaleacolburn/jolt-physics"
22
import type { RgbaColor } from "react-colorful"
33
import * as THREE from "three"
4-
import type { mirabuf } from "../proto/mirabuf"
4+
import type { mirabuf } from "@/proto/mirabuf"
55
import JOLT from "./loading/JoltSyncLoader"
66

77
export function convertThreeToJoltQuat(a: THREE.Euler | THREE.Quaternion | undefined) {

0 commit comments

Comments
 (0)