11import { clone } from '@zenstackhq/common-helpers' ;
2- import { ZenStackClient } from '@zenstackhq/orm' ;
2+ import { ZenStackClient , type ClientContract } from '@zenstackhq/orm' ;
33import { PostgresDialect } from '@zenstackhq/orm/dialects/postgres' ;
44import { PolicyPlugin } from '@zenstackhq/plugin-policy' ;
55import { TEST_PG_URL } from '@zenstackhq/testtools' ;
66import { Database } from 'bun:sqlite' ;
7- import { describe , expect , it } from 'bun:test' ;
7+ import { afterEach , describe , expect , it } from 'bun:test' ;
88import type { Dialect } from 'kysely' ;
99import { BunSqliteDialect } from 'kysely-bun-sqlite' ;
1010import { Client , Pool } from 'pg' ;
@@ -13,8 +13,14 @@ import { schema } from './schemas/schema';
1313describe ( 'Bun e2e tests' , ( ) => {
1414 const provider = ( process . env [ 'TEST_DB_PROVIDER' ] ?? 'sqlite' ) as 'sqlite' | 'postgresql' ;
1515
16+ let db : ClientContract < typeof schema > | undefined ;
17+
18+ afterEach ( async ( ) => {
19+ await db ?. $disconnect ( ) ;
20+ } ) ;
21+
1622 it ( 'works with simple CRUD' , async ( ) => {
17- const db = await createClient ( provider , 'bun-e2e-crud' ) ;
23+ db = await createClient ( provider , 'bun-e2e-crud' ) ;
1824
1925 const user = await db . user . create ( {
2026 data : {
@@ -44,7 +50,7 @@ describe('Bun e2e tests', () => {
4450 } ) ;
4551
4652 it ( 'enforces policies' , async ( ) => {
47- const db = await createClient ( provider , 'bun-e2e-policies' ) ;
53+ db = await createClient ( provider , 'bun-e2e-policies' ) ;
4854 const authDb = db . $use ( new PolicyPlugin ( ) ) ;
4955
5056 // create a user
0 commit comments