Repository navigation
Separate module-author internals from the user-facing entry point #1562
Description
What happens
testcontainers has a single entry point (main: build/index.js, no exports map) that serves both test authors and module authors. Utilities that exist for the modules and for core itself are exported next to the user-facing API, and every one of them is covered by semver:
log,IntervalRetry,RetryUuid,RandomUuid,randomUuidPortGenerator,RandomPortGeneratorBoundPorts,getContainerPort,hasHostBindinggetReaper,LABEL_TESTCONTAINERS_SESSION_IDContainerRuntimeClient,getContainerRuntimeClient,waitForContainer
Dockerode types are part of the public contract as well:
WaitStrategy.waitUntilReady(container: Dockerode.Container, ...)StartupCheckStrategy.checkStartupState(dockerClient: Dockerode, ...)- the protected
createOpts: ContainerCreateOptionsandhostConfig: HostConfigonGenericContainer, which subclasses read and write directly
That is why @types/dockerode is a runtime dependency, and why a Dockerode major is a breaking change here.
Because there is no exports map, consumers can also import anything under testcontainers/build/....
Usage inside this repo is narrow. Most modules import only GenericContainer, AbstractStartedContainer, Wait and StartedTestContainer. Five of them (kafka, redpanda, localstack, ollama, couchbase) reach for the runtime client, BoundPorts, waitForContainer or getReaper.
Expected
- The main entry exports what a test author needs.
- Module-author utilities move to a separate subpath (for example
testcontainers/module) with its own, looser stability promise. - An
exportsmap closes off deep imports. - Dockerode types stay out of the user-facing signatures where possible.
Where
packages/testcontainers/src/index.tspackages/testcontainers/package.jsonbiome.json(the import boundary rule that pins modules to thetestcontainersentry point)
Notes
- Removing exports and adding an
exportsmap are both breaking, hencemajor. - Related: Export the types used in public method signatures #1528 (types that should be exported but are not).
- Go keeps this split with
internal/packages.
Dependencies
- Blocked by Pass the started container to
WaitStrategy.waitUntilReady#1558: that removesDockerode.ContainerandBoundPortsfrom the wait strategy interface, which decides what is left to move. - Blocked by Remove the
Uuidtest seam from public constructors #1561: that removes theUuidexports outright. - Coordinate with Export the types used in public method signatures #1528: both edit
index.ts. - Coordinate with Add an escape hatch for raw container create options #1550: an escape hatch is the alternative to subclasses reaching into the protected fields.
Activity