Skip to content

Commit 312361f

Browse files
Add support for TS 5.2 using
1 parent 8ed532e commit 312361f

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

packages/testcontainers/src/generic-container/generic-container.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ describe("GenericContainer", { timeout: 180_000 }, () => {
1515
const fixtures = path.resolve(__dirname, "..", "..", "fixtures", "docker");
1616

1717
it("should return first mapped port", async () => {
18-
const container = await new GenericContainer("cristianrgreco/testcontainer:1.1.14").withExposedPorts(8080).start();
18+
await using container = await new GenericContainer("cristianrgreco/testcontainer:1.1.14")
19+
.withExposedPorts(8080)
20+
.start();
1921

2022
expect(container.getFirstMappedPort()).toBe(container.getMappedPort(8080));
21-
22-
await container.stop();
2323
});
2424

2525
it("should bind to specified host port", async () => {

packages/testcontainers/src/generic-container/started-generic-container.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,4 +232,8 @@ export class StartedGenericContainer implements StartedTestContainer {
232232

233233
return client.container.logs(this.container, opts);
234234
}
235+
236+
async [Symbol.asyncDispose]() {
237+
await this.stop();
238+
}
235239
}

packages/testcontainers/src/test-container.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export interface StopOptions {
6464
removeVolumes: boolean;
6565
}
6666

67-
export interface StartedTestContainer {
67+
export interface StartedTestContainer extends AsyncDisposable {
6868
stop(options?: Partial<StopOptions>): Promise<StoppedTestContainer>;
6969
restart(options?: Partial<RestartOptions>): Promise<void>;
7070
commit(options: CommitOptions): Promise<string>;

0 commit comments

Comments
 (0)