Skip to content

Add the missing builder methods to the TestContainer interface - #1655

Merged
cristianrgreco merged 1 commit into
testcontainers:mainfrom
Pushkar236:feat/1529-testcontainer-interface
Nov 19, 2026
Merged

cristianrgreco merged 1 commit into
testcontainers:mainfrom
Pushkar236:feat/1529-testcontainer-interface

Conversation

@Pushkar236

Copy link
Copy Markdown
Contributor

Summary

GenericContainer has five public builder methods that the TestContainer interface does not declare: withName, withLabels, withNetworkAliases, withHealthCheck and withIpcMode. Code typed against TestContainer, such as the custom container example in docs/features/containers.md, could not call them. They are now declared on the interface with the same signatures.

A type-level test in test-container.test.ts checks that every public with* method on GenericContainer is declared on TestContainer, so the two can't drift apart again. Test files are compiled by npm run check-compiles (the Compile job), so a new builder method added only to the class fails CI with the missing names in the error.

Verification

The check is enforced by npm run check-compiles (the Compile job). expectTypeOf does nothing at runtime, so the Vitest run passes either way.

  • Red: against the interface on main, npm run check-compiles fails with TS2349 ... ExpectNever<"withHealthCheck" | "withIpcMode" | "withLabels" | "withName" | "withNetworkAliases">.
  • Green: npm run check-compiles (the package and all modules), npm run format, npm run lint and npm run knip pass.

Not breaking (minor)

This only adds members to TestContainer. Containers built on GenericContainer, which is how the docs say to write a custom container, already have these methods. Code that implements TestContainer from scratch, or mocks it, would need to add the five methods, but that isn't a documented extension point, so I've kept the minor label from the issue. No docs change is needed: the custom container example is already typed as TestContainer, and its calls now type-check.

Suggested labels: enhancement, minor.

Closes #1529

@cristianrgreco cristianrgreco added bug Something isn't working patch Backward compatible bug fix labels Nov 19, 2026
@cristianrgreco
cristianrgreco merged commit 38f9812 into testcontainers:main Nov 19, 2026
188 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working patch Backward compatible bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add the missing builder methods to the TestContainer interface

2 participants