Make the port optional in `Wait.forHttp`

Open
#1,534 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 4 days

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
82/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
docker, node.js, typescript
Domain
devtools, testing

Research direction

Start with packages/testcontainers/src/wait-strategies/wait.ts and packages/testcontainers/src/wait-strategies/http-wait-strategy.ts to trace how Wait.forHttp creates the HTTP wait strategy and how exposed ports are available. Check the existing API and tests for Wait.forHttp, then add coverage for defaulting to the first exposed port, fluent .forPort(8081), and the existing Wait.forHttp(path, port) call. Done means all three forms work.

Written by the indexing model from the issue text.

Description

enhancement minor

What happens

Wait.forHttp(path, port, options) requires the port, even for the usual case of a container with one exposed port:

new GenericContainer(image)
  .withExposedPorts(8080)
  .withWaitStrategy(Wait.forHttp("/health", 8080));

The port is repeated, and in a module it has to be kept in step with the exposed port by hand. Because options is the third positional parameter, it cannot be passed without the port.

Expected

  • The port is optional and defaults to the first exposed port.
  • The port can be set fluently, for example Wait.forHttp("/health").forPort(8081).
  • Wait.forHttp(path, port) keeps working.

Where

  • packages/testcontainers/src/wait-strategies/wait.ts
  • packages/testcontainers/src/wait-strategies/http-wait-strategy.ts

Notes

  • Java's Wait.forHttp(String path) takes only the path, uses the container's first exposed port by default, and has forPort(int) and Wait.forHttps(path).
  • Related: #1507, which is about the options argument (abortOnContainerExit).

Dependencies

  • Nothing blocks this. It can start now.
Dominant language
TypeScript
Stars
2.7k
Forks
290
Avg merge
4d 1h
Merged PRs (30d)
22

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from testcontainers/testcontainers-node

All issues in testcontainers/testcontainers-node

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.