|
| 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 | +}) |
0 commit comments