Skip to content

Commit

Permalink
add test.
Browse files Browse the repository at this point in the history
  • Loading branch information
igalklebanov committed Oct 19, 2024
1 parent 4a6ae8c commit 640135c
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions test/node/src/async-dispose.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import {
CompiledQuery,
DummyDriver,
Kysely,
PostgresAdapter,
PostgresIntrospector,
PostgresQueryCompiler,
RootOperationNode,
sql,
} from '../../..'
import { expect } from './test-setup'

describe('async dispose', function () {
it.only('should call destroy ', async () => {
const steps: string[] = [];

async function runScope() {
await using db = new Kysely({
dialect: {
createAdapter: () => new PostgresAdapter(),
createDriver: () => new (class SpiedOnDummyDriver extends DummyDriver {
async destroy(): Promise<void> {
await new Promise((resolve) => setTimeout(resolve, 100))
steps.push('destroyed')
}
})(),
createIntrospector: (db) => new PostgresIntrospector(db),
createQueryCompiler: () => new (class SpiedOnPostgresQueryCompiler extends PostgresQueryCompiler {
compileQuery(node: RootOperationNode): CompiledQuery<unknown> {
const compiled = super.compileQuery(node)
steps.push('compiled')
return compiled
}
})(),
},
})

sql`select 1`.compile(db);
}

await runScope()

steps.push('after runScope')

expect(steps).to.length.to.be.greaterThan(1)
expect(steps).to.deep.equal([
'compiled',
'destroyed',
'after runScope',
])
})
})

0 comments on commit 640135c

Please sign in to comment.