-
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
7e9fe2d
commit 011dccb
Showing
3 changed files
with
43 additions
and
27 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
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 |
---|---|---|
@@ -1,52 +1,65 @@ | ||
import { | ||
CompiledQuery, | ||
DatabaseConnection, | ||
DummyDriver, | ||
Kysely, | ||
PostgresAdapter, | ||
PostgresIntrospector, | ||
PostgresQueryCompiler, | ||
QueryResult, | ||
RootOperationNode, | ||
sql, | ||
} from '../../..' | ||
import { expect } from './test-setup' | ||
|
||
describe('async dispose', function () { | ||
it.only('should call destroy ', async () => { | ||
const steps: string[] = []; | ||
it('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') | ||
} | ||
{ | ||
await using db = new Kysely({ | ||
dialect: { | ||
createAdapter: () => new PostgresAdapter(), | ||
createDriver: () => | ||
new (class extends DummyDriver { | ||
async acquireConnection() { | ||
return new (class implements DatabaseConnection { | ||
async executeQuery<R>(): Promise<QueryResult<R>> { | ||
steps.push('executed') | ||
return { rows: [] } | ||
} | ||
streamQuery<R>(): AsyncIterableIterator<QueryResult<R>> { | ||
throw new Error('Method not implemented.') | ||
} | ||
})() | ||
} | ||
async destroy(): Promise<void> { | ||
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 | ||
} | ||
createIntrospector: (db) => new PostgresIntrospector(db), | ||
createQueryCompiler: () => | ||
new (class extends PostgresQueryCompiler { | ||
compileQuery(node: RootOperationNode): CompiledQuery<unknown> { | ||
const compiled = super.compileQuery(node) | ||
steps.push('compiled') | ||
return compiled | ||
} | ||
})(), | ||
}, | ||
}) | ||
}, | ||
}) | ||
|
||
sql`select 1`.compile(db); | ||
await sql`select 1`.execute(db) | ||
} | ||
|
||
await runScope() | ||
|
||
steps.push('after runScope') | ||
|
||
expect(steps).to.length.to.be.greaterThan(1) | ||
expect(steps).to.deep.equal([ | ||
'compiled', | ||
'destroyed', | ||
'after runScope', | ||
'compiled', | ||
'executed', | ||
'destroyed', | ||
'after runScope', | ||
]) | ||
}) | ||
}) |
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