-
-
Notifications
You must be signed in to change notification settings - Fork 251
Implement AsyncDisposable to support TS 5.2's using
#1080
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
Conversation
✅ Deploy Preview for testcontainers-node ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
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.
Pull Request Overview
This PR adds support for TypeScript 5.2's using keyword, implementing automatic resource disposal for test containers. The changes modernize resource management by replacing manual await container.stop() calls with automatic disposal when containers go out of scope.
- Updates container and network classes to implement
AsyncDisposableinterface - Modifies test files to use
await usingfor automatic resource cleanup - Enhances helper functions to return disposable objects
Reviewed Changes
Copilot reviewed 73 out of 73 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/testcontainers/src/test-container.ts | Extends StartedTestContainer interface with AsyncDisposable |
| packages/testcontainers/src/generic-container/started-generic-container.ts | Implements Symbol.asyncDispose for containers |
| packages/testcontainers/src/network/network.ts | Implements AsyncDisposable for networks |
| packages/testcontainers/src/utils/test-helper.ts | Updates helper to return disposable event stream |
| Test files across all modules | Replace manual cleanup with await using declarations |
usingAsyncDisposable to support TS 5.2's using
| async [Symbol.asyncDispose]() { | ||
| await this.startedTestContainer[Symbol.asyncDispose](); | ||
| } |
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.
@cristianrgreco Shouldn't this call this.stop?
| async [Symbol.asyncDispose]() { | |
| await this.startedTestContainer[Symbol.asyncDispose](); | |
| } | |
| async [Symbol.asyncDispose]() { | |
| await this.stop(); | |
| } |
Feature info here: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html#using-declarations-and-explicit-resource-management
Before:
After:
Same for
NetworkandDockerComposeEnvironment.