diff options
author | 2023-07-21 20:13:04 -0300 | |
---|---|---|
committer | 2023-07-21 16:13:04 -0700 | |
commit | c4f062dbf4666413a028000a360dfe3ea222546f (patch) | |
tree | 5dcbb68690b1083dab028f1f5560f22370de6d7f | |
parent | 7ac94e5b4cc0caee38bcd4b82385a45b0e1a3bff (diff) | |
download | bun-c4f062dbf4666413a028000a360dfe3ea222546f.tar.gz bun-c4f062dbf4666413a028000a360dfe3ea222546f.tar.zst bun-c4f062dbf4666413a028000a360dfe3ea222546f.zip |
clean tables before testing (#3721)
* clean tables before testing
* typo
-rw-r--r-- | test/js/third_party/prisma/prisma.test.ts | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/test/js/third_party/prisma/prisma.test.ts b/test/js/third_party/prisma/prisma.test.ts index 417339ebc..d4e4b9cca 100644 --- a/test/js/third_party/prisma/prisma.test.ts +++ b/test/js/third_party/prisma/prisma.test.ts @@ -2,7 +2,7 @@ import { test as bunTest, expect, describe } from "bun:test"; import { generateClient } from "./helper.ts"; import type { PrismaClient } from "./prisma/types.d.ts"; -function* TestIDGenerator() { +function* TestIDGenerator(): Generator<number> { let i = 0; while (true) { yield i++; @@ -10,6 +10,12 @@ function* TestIDGenerator() { } const test_id = TestIDGenerator(); +async function cleanTestId(prisma: PrismaClient, testId: number) { + try { + await prisma.post.deleteMany({ where: { testId } }); + await prisma.user.deleteMany({ where: { testId } }); + } catch {} +} ["sqlite", "postgres" /*"mssql", "mongodb"*/].forEach(async type => { let Client: typeof PrismaClient; @@ -26,8 +32,10 @@ const test_id = TestIDGenerator(); label, async () => { const prisma = new Client(); + const currentTestId = test_id.next().value; + await cleanTestId(prisma, currentTestId); try { - await callback(prisma, test_id.next().value); + await callback(prisma, currentTestId); } finally { await prisma.$disconnect(); } |