Skip to content

⚠️ Replace fragile testcontainers internal imports with public API #1428

@coderabbitai

Description

@coderabbitai

Problem Description

The browser tests are importing testcontainers' internal build files which are not part of the public API and have broken multiple times during version updates:

// Current fragile approach
import {HttpWaitStrategy} from "testcontainers/build/wait-strategies/http-wait-strategy.js";

Issues:

  • Internal path testcontainers/build/…/http-wait-strategy.js is not part of public API
  • Already broke twice between versions 10.13 → 10.25
  • Requires adding .js extensions for ESM compatibility workarounds
  • Fragile to future testcontainers releases
  • Type safety concerns with internal imports

Affected Files:

  • tests/browser/tests/codeserver.spec.ts (lines 5-7, 45-47)

Solution

Replace internal imports with the public Wait builder API:

-import {HttpWaitStrategy} from "testcontainers/build/wait-strategies/http-wait-strategy.js";
+import { Wait } from "testcontainers";

// In container setup:
-          .withWaitStrategy(new HttpWaitStrategy('/', 8787, {abortOnContainerExit: true}))
+          .withWaitStrategy(
+            Wait.forHttp('/')
+                .forPort(8787)
+                .withStartupTimeout(10 * 60 * 1000)
+          )

Benefits:

  • Uses stable public API
  • Survives future testcontainers releases
  • Maintains type safety
  • Cleaner, more readable code
  • No ESM extension workarounds needed

Acceptance Criteria

  • Replace HttpWaitStrategy import with Wait import in tests/browser/tests/codeserver.spec.ts
  • Update container wait strategy implementation to use Wait.forHttp() builder
  • Verify tests still pass with the new implementation
  • Apply fix to both 2024b and main branches
  • Ensure timeout behavior remains equivalent (10 minute startup timeout)
  • Confirm no other internal testcontainers imports exist in the codebase

Implementation Notes

The Wait.forHttp() builder provides the same functionality as HttpWaitStrategy but through the stable public API. The timeout should be configured using .withStartupTimeout() to maintain the current 10-minute container startup timeout.

Context

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

📋 Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions