Conversation
| } | ||
| ``` | ||
| - In each test suite, create new database at the beginning and drop it at the end | ||
| ```typescript |
There was a problem hiding this comment.
Would this be more reflective of real life and easier to understand at a glance to assign both the DataSource + dispose rather than just assigning the dispose function?
| ```typescript | |
| ```ts | |
| describe('example suite which uses isolated DB instance', () => { | |
| let dispose: AsyncDisposable | |
| let ds: DataSource | |
| beforeAll(async () => { | |
| const prepared = await testDbManager.prepareTestDatabaseSource() | |
| disposable = prepared.disposable | |
| dataSource = prepared.dataSource | |
| }) | |
| afterAll(async () => { | |
| await dataSource.[Symbol.asyncDispose]() | |
| await dispose.[Symbol.asyncDispose]() | |
| }) | |
| }) |
| log: noop, | ||
| } | ||
|
|
||
| export class TestDatabaseManager { |
There was a problem hiding this comment.
There are some new types in Typescript 5.2 for Disposable and AsyncDisposable which might be worth using?
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html#libdts-changes
The TestDatabaseManager could implement AsyncDisposable to await its list of cleanup tasks.. This hopefully may make things easier in the future, e.g. if the runtimes handle this on our behalf we might need less before and after.
There was a problem hiding this comment.
Hi @cuzzlor, thanks for the suggestion, today I learnt about AsyncDisposable interface.
I tried to implement it in this library but faced an issue:
AsyncDisposablerequires the resource to be declared withusing. I can't find any resources on how to fitusinginto Jest setup and teardown.
Do you know a way to address it?
There was a problem hiding this comment.
Can you just create it in the test setup and call async dispose in the test teardown without using a using ?
Feel free to ignore my suggestions, I was thinking it might be useful to explore the layout of the new disposable features and align towards if it's not too clunky.
No description provided.