Remove the need for `AbstractStartedContainer` wrappers in modules
Maintainers usually reply within 4 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
- Issue type
- Refactor
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- docker, node.js, typescript
Research direction
Read the four packages/testcontainers/src/generic-*/ files listed under “Where,” then inspect module start() overrides and started classes under packages/modules/*/src/. First resolve the stated dependencies and coordinate with issues #1521 and #1538; account for Compose and reuse paths that construct StartedGenericContainer. Done means modules can declare their started type without forwarding wrappers or wrapper-only start() overrides, with the listed follow-up work coordinated.
Written by the indexing model from the issue text.
Description
What happens
Every module is two classes joined by a forwarding wrapper. Simplified from the redis module:
export class RedisContainer extends GenericContainer {
public override async start(): Promise<StartedRedisContainer> {
return new StartedRedisContainer(await super.start(), this.password);
}
}
export class StartedRedisContainer extends AbstractStartedContainer {
constructor(startedTestContainer: StartedTestContainer, private readonly password?: string) {
super(startedTestContainer);
}
}
AbstractStartedContainer holds a StartedTestContainer and forwards each of its 20 methods to it.
- 50 module classes extend it.
- 50 module files override
start(), and each override has to wrap the result ofsuper.start()in the module's started class. - Every method added to
StartedTestContainerhas to be written three times: on the interface, onStartedGenericContainerand as a forwarder onAbstractStartedContainer. - Forwarding has caused bugs: #1202, where
Symbol.asyncDisposecalled the innerstop()and skipped the subclass's. - There are two sets of stop hooks:
containerStopping/containerStoppedonAbstractStartedContainer, andcontainerIsStopping/containerIsStoppedonStartedGenericContainer, which nothing overrides. That class is not exported. AbstractStoppedContainerrepeats the pattern and is used once (selenium).- Overriding
start()to wrap is also where modules put configuration, which is whystart()is not repeatable (#1520).
Expected
A module author declares the started type once, with no forwarding class and no start() override just to wrap. Some directions:
- Make
GenericContainergeneric over its started type, with a protected factory that the basestart()calls. Configuration moves to a hook such asbeforeContainerCreated. - Export a started base class that module containers extend directly, and let the builder say which class to construct. Inheritance replaces forwarding.
- One class for both states, as Java and Go have.
Where
packages/testcontainers/src/generic-container/abstract-started-container.tspackages/testcontainers/src/generic-container/abstract-stopped-container.tspackages/testcontainers/src/generic-container/started-generic-container.ts- every
packages/modules/*/src/*-container.ts
Notes
- Java and Go use a single type for a configured and a running container. .NET splits builder and container like this repo, but the module container extends the base container directly (
PostgreSqlContainer : DockerContainer, IDatabaseContainer), with no forwarding layer. - Compose and the reuse path construct
StartedGenericContainerthemselves, so the design has to cover those. - Semver: labelled
majorfor removingAbstractStartedContainer. The replacement can ship first in aminor, with the wrapper deprecated.
Dependencies
- Blocked by #1520, #1554: modules configure themselves inside
start()and through protected hooks. Both need their replacement first. - Coordinate with #1521: hook semantics for reused containers.
- Coordinate with #1538: both edit every module's started class.
- Land after the started-container additions (#1544, #1545, #1546, #1547, #1548, #1549, #1541). They add forwarders that this removes.
- Dominant language
- TypeScript
- Stars
- 2.7k
- Forks
- 290
- Avg merge
- 4d 1h
- Merged PRs (30d)
- 22
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- Ships a Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from testcontainers/testcontainers-node
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
testcontainers/testcontainers-node#1673 ·
Maintainers usually reply within 4 days
-
enhancement minor
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
testcontainers/testcontainers-node#1539 ·
Maintainers usually reply within 4 days
-
Let `Wait.forListeningPorts()` wait on specific portsPossibly taken @artbom claimed this 29 days ago. Openenhancement minor
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
testcontainers/testcontainers-node#1533 ·
Maintainers usually reply within 4 days
-
enhancement minor
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
testcontainers/testcontainers-node#1531 ·
Maintainers usually reply within 4 days
-
Export the types used in public method signaturesPossibly taken @artbom claimed this 29 days ago. Openenhancement minor
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
testcontainers/testcontainers-node#1528 ·
Maintainers usually reply within 4 days
All issues in testcontainers/testcontainers-node
Similar issues
-
prio:low scope:hud
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
OliverRomhagen/vrigstad-joyride#953 ·
Maintainers usually reply within 1 day
-
review-followup
Difficulty 1/5 Under an hour Newbie friendliness 92/100
griffinwork40/agent-afk#5446 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
kacper-szewczyk/Ticknest#346 ·
Maintainers usually reply within 1 day
-
echarts geo: a GeoJSON URL that returns 200 with a body that is not JSON is fetched on each refreshOpenbug plugin/echarts/geo
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
Yeachan-Heo/gajae-code#8230 ·
Maintainers usually reply within 1 day