-
Notifications
You must be signed in to change notification settings - Fork 0
Add Jest test database manager #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.