import { readdirSync } from "node:fs"; import { describe, expect, it } from "vitest"; import { MIGRATIONS_DIR } from "../src/index.ts"; describe("migrations", () => { it("迁移文件按 NNNN_name.ts 命名且导出 up/down", async () => { const files = readdirSync(MIGRATIONS_DIR).filter((f) => f.endsWith(".ts")); expect(files.length).toBeGreaterThan(0); for (const f of files) { expect(f).toMatch(/^\d{4}_[a-z0-9_]+\.ts$/); const mod = await import(`${MIGRATIONS_DIR}/${f}`); expect(typeof mod.up).toBe("function"); expect(typeof mod.down).toBe("function"); } }); });