-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4a6ae8c
commit 640135c
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
]) | ||
}) | ||
}) |