import { existsSync } from "node:fs"; import { join } from "node:path"; import { describe, expect, it } from "vitest"; import { DEFAULT_PACKS_ROOT, listPacks, loadPack } from "../src/index.ts"; describe("資料包讀取", () => { it("拒絕不合法的名稱(避免讀到資料包目錄以外的檔案)", async () => { await expect(loadPack("../secrets")).rejects.toThrow("不合法"); await expect(loadPack("a/b")).rejects.toThrow("不合法"); }); const name = "68000-before-2022-11-26"; it.skipIf(!existsSync(join(DEFAULT_PACKS_ROOT, name, "manifest.json")))("讀取並驗證已建置的資料包", async () => { expect(await listPacks()).toContain(name); const pack = await loadPack(name); expect(pack.villages.length).toBeGreaterThan(500); expect(pack.towns).toHaveLength(13); expect(pack.cells.length).toBe(pack.villages.length * 30); expect(pack.towns.reduce((s, t) => s + t.villages.length, 0)).toBe(pack.villages.length); }); });