Skip to content

Conversation

@PatrickDinh
Copy link
Collaborator

No description provided.

}
```
- In each test suite, create new database at the beginning and drop it at the end
```typescript
Copy link

@cuzzlor cuzzlor Dec 8, 2023

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?

Suggested change
```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 {
Copy link

@cuzzlor cuzzlor Dec 8, 2023

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.

Copy link
Collaborator Author

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:

  • AsyncDisposable requires the resource to be declared with using. I can't find any resources on how to fit using into Jest setup and teardown.

Do you know a way to address it?

Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants