// eslint-disable-next-line import/no-extraneous-dependencies import tmp, { DirResult } from "tmp"; import { createConnection, getConnection } from "typeorm"; export default function withDatabase(): void { let tempDir: DirResult; beforeAll(async () => { tempDir = tmp.dirSync({ unsafeCleanup: true }); await createConnection({ type: "sqlite", database: `${tempDir.name}/database.sqlite`, entities: ["src/domains/**/*.entity.ts"], migrations: ["src/migration/**/*.ts"], }); }); beforeEach(async () => { await getConnection().runMigrations(); }); afterEach(async () => { await getConnection().dropDatabase(); }); afterAll(() => { tempDir.removeCallback(); }); }