Skip to content

Conversation

@cristianrgreco
Copy link
Collaborator

@cristianrgreco cristianrgreco commented Jul 17, 2025

Feature info here: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html#using-declarations-and-explicit-resource-management

Before:

const container = await new GenericContainer(/* ... */).start();
/* ... */
await container.stop();

After:

await using container = await new GenericContainer(/* ... */).start();
/* ... */

Same for Network and DockerComposeEnvironment.

@netlify
Copy link

netlify bot commented Jul 17, 2025

Deploy Preview for testcontainers-node ready!

Name Link
🔨 Latest commit 93f8550
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-node/deploys/687a3fef1b84850008773df1
😎 Deploy Preview https://deploy-preview-1080--testcontainers-node.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@cristianrgreco cristianrgreco requested a review from Copilot July 17, 2025 21:07
Copy link

Copilot AI left a 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 AsyncDisposable interface
  • Modifies test files to use await using for 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

@cristianrgreco cristianrgreco changed the title Add support for TS 5.2 using Implement AsyncDisposable to support TS 5.2's using Jul 18, 2025
@cristianrgreco cristianrgreco marked this pull request as ready for review July 18, 2025 12:40
@cristianrgreco cristianrgreco added enhancement New feature or request minor Backward compatible functionality labels Jul 18, 2025
@cristianrgreco cristianrgreco merged commit a8cec38 into main Jul 18, 2025
316 checks passed
@cristianrgreco cristianrgreco deleted the add-support-for-ts-using branch July 18, 2025 16:09
Comment on lines +102 to +104
async [Symbol.asyncDispose]() {
await this.startedTestContainer[Symbol.asyncDispose]();
}
Copy link
Contributor

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?

Suggested change
async [Symbol.asyncDispose]() {
await this.startedTestContainer[Symbol.asyncDispose]();
}
async [Symbol.asyncDispose]() {
await this.stop();
}

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

Labels

enhancement New feature or request minor Backward compatible functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants