Skip to content

Vitest run will not work with exposeHostPort #1188

@cre8

Description

@cre8

Expected Behaviour
Exposing ports when vitest is in run mode, not watch.

Actual Behaviour
Process is aborted and zero tests are executed. vitest run and vitest are both executed with the same configuration:
https://github.com/openwallet-foundation-labs/eudiplo/actions/runs/19799723787/job/56725238129

According to the vitest config it will execute the run mode when running just vitest in a CI environment.
When moving the the exposeports function to the end of my testfile, the other testcontainter calls like spinning up a container work, but as soon as the expose function is called, it get aborted without any error message or so.

Testcontainer Logs

  testcontainers [DEBUG] Acquiring lock file "/private/var/folders/y0/b_sql0pn5j978xs8jz_4kx580000gp/T/testcontainers-node-sshd.lock"... +0ms
  testcontainers [DEBUG] Acquired lock file "/private/var/folders/y0/b_sql0pn5j978xs8jz_4kx580000gp/T/testcontainers-node-sshd.lock" +1ms
  testcontainers [DEBUG] Checking container runtime strategy "TestcontainersHostStrategy"... +0ms
  testcontainers [DEBUG] Loading ".testcontainers.properties" file... +0ms
  testcontainers [DEBUG] Loaded ".testcontainers.properties" file +1ms
  testcontainers [DEBUG] Found custom configuration: tcHost: "tcp://127.0.0.1:49480", dockerHost: "tcp://127.0.0.1:49480" +0ms
  testcontainers [TRACE] Fetching Docker info... +0ms
  testcontainers [TRACE] Fetching remote container runtime socket path... +26ms
  testcontainers [TRACE] Resolving host... +0ms
  testcontainers [TRACE] Fetching Compose info... +0ms
  testcontainers [TRACE] Looking up host IPs... +0ms
  testcontainers [TRACE] Initialising clients... +0ms
  testcontainers [TRACE] Container runtime info:
  testcontainers {
  testcontainers   "node": {
  testcontainers     "version": "v24.5.0",
  testcontainers     "architecture": "arm64",
  testcontainers     "platform": "darwin"
  testcontainers   },
  testcontainers   "containerRuntime": {
  testcontainers     "host": "127.0.0.1",
  testcontainers     "hostIps": [
  testcontainers       {
  testcontainers         "address": "127.0.0.1",
  testcontainers         "family": 4
  testcontainers       }
  testcontainers     ],
  testcontainers     "remoteSocketPath": "/var/run/docker.sock",
  testcontainers     "indexServerAddress": "https://index.docker.io/v1/",
  testcontainers     "serverVersion": "27.4.0 (via Testcontainers Desktop 1.22.0)",
  testcontainers     "operatingSystem": "Docker Desktop",
  testcontainers     "operatingSystemType": "linux",
  testcontainers     "architecture": "aarch64",
  testcontainers     "cpus": 11,
  testcontainers     "memory": 8217825280,
  testcontainers     "runtimes": [
  testcontainers       "io.containerd.runc.v2",
  testcontainers       "runc"
  testcontainers     ],
  testcontainers     "labels": [
  testcontainers       "com.docker.desktop.address=unix:///Users/mirko/Library/Containers/com.docker.docker/Data/docker-cli.sock"
  testcontainers     ]
  testcontainers   }
  testcontainers } +0ms
  testcontainers [DEBUG] Container runtime strategy "TestcontainersHostStrategy" works +0ms
  testcontainers [DEBUG] Acquiring lock file "/private/var/folders/y0/b_sql0pn5j978xs8jz_4kx580000gp/T/testcontainers-node.lock"... +1ms
  testcontainers [DEBUG] Acquired lock file "/private/var/folders/y0/b_sql0pn5j978xs8jz_4kx580000gp/T/testcontainers-node.lock" +0ms
  testcontainers [DEBUG] Listing containers... +0ms
  testcontainers [DEBUG] Listed containers +34ms
  testcontainers [DEBUG] Creating new Reaper for session "690912bed6e7" with socket path "/var/run/docker.sock"... +0ms
  testcontainers [DEBUG] Checking if image exists "testcontainers/ryuk:0.14.0"... +0ms
  testcontainers [DEBUG] Checked if image exists "testcontainers/ryuk:0.14.0" +10ms
  testcontainers [DEBUG] Image "testcontainers/ryuk:0.14.0" already exists +0ms
  testcontainers [DEBUG] Creating container for image "testcontainers/ryuk:0.14.0"... +0ms
  testcontainers [DEBUG] [704cbfaa0b2a] Created container for image "testcontainers/ryuk:0.14.0" +49ms
  testcontainers [INFO] [704cbfaa0b2a] Starting container for image "testcontainers/ryuk:0.14.0"... +0ms
  testcontainers [DEBUG] [704cbfaa0b2a] Starting container... +0ms
  testcontainers [DEBUG] [704cbfaa0b2a] Started container +286ms
  testcontainers [INFO] [704cbfaa0b2a] Started container for image "testcontainers/ryuk:0.14.0" +0ms
  testcontainers [DEBUG] [704cbfaa0b2a] Fetching container logs... +7ms
  testcontainers [DEBUG] [704cbfaa0b2a] Waiting for container to be ready... +0ms
  testcontainers [DEBUG] [704cbfaa0b2a] Waiting for log message "/.*Started.*/"... +0ms
  testcontainers [DEBUG] [704cbfaa0b2a] Fetching container logs... +0ms
  testcontainers [DEBUG] [704cbfaa0b2a] Demuxing stream... +3ms
  testcontainers [DEBUG] [704cbfaa0b2a] Demuxed stream +0ms
  testcontainers [DEBUG] [704cbfaa0b2a] Demuxing stream... +0ms
  testcontainers [DEBUG] [704cbfaa0b2a] Demuxed stream +0ms
  testcontainers:containers [704cbfaa0b2a] time=2025-11-30T15:03:13.867Z level=INFO msg=starting connection_timeout=1m0s reconnection_timeout=10s request_timeout=10s shutdown_timeout=10m0s remove_retries=10 retry_offset=-1s changes_retry_interval=1s port=8080 verbose=false +0ms
  testcontainers:containers [704cbfaa0b2a] time=2025-11-30T15:03:13.868Z level=INFO msg=Started address=[::]:8080 +0ms
  testcontainers:containers [704cbfaa0b2a] time=2025-11-30T15:03:13.868Z level=INFO msg="client processing started" +0ms
  testcontainers [DEBUG] [704cbfaa0b2a] Log wait strategy complete +99ms
  testcontainers [INFO] [704cbfaa0b2a] Container is ready +1ms
  testcontainers [DEBUG] [704cbfaa0b2a] Connecting to Reaper (attempt 1) on "127.0.0.1:55172"... +0ms
  testcontainers [DEBUG] [704cbfaa0b2a] Connected to Reaper +1ms
  testcontainers [DEBUG] Releasing lock file "/private/var/folders/y0/b_sql0pn5j978xs8jz_4kx580000gp/T/testcontainers-node.lock"... +0ms
  testcontainers [DEBUG] Released lock file "/private/var/folders/y0/b_sql0pn5j978xs8jz_4kx580000gp/T/testcontainers-node.lock" +1ms
  testcontainers [DEBUG] Listing containers... +0ms
  testcontainers:containers [704cbfaa0b2a] time=2025-11-30T15:03:13.873Z level=INFO msg="client connected" address=172.17.0.1:63074 clients=1 +6ms
  testcontainers:containers [704cbfaa0b2a] time=2025-11-30T15:03:13.874Z level=INFO msg="adding filter" type=label values="[org.testcontainers.session-id=690912bed6e7]" +0ms
  testcontainers [DEBUG] Listed containers +37ms
  testcontainers [DEBUG] Creating new Port Forwarder... +1ms
  testcontainers [DEBUG] Checking if image exists "testcontainers/sshd:1.3.0"... +0ms
  testcontainers [DEBUG] Checked if image exists "testcontainers/sshd:1.3.0" +7ms
  testcontainers [DEBUG] Image "testcontainers/sshd:1.3.0" already exists +0ms
  testcontainers [DEBUG] Creating container for image "testcontainers/sshd:1.3.0"... +0ms
  testcontainers [DEBUG] [3ad74f7bc7e0] Created container for image "testcontainers/sshd:1.3.0" +36ms
  testcontainers [INFO] [3ad74f7bc7e0] Starting container for image "testcontainers/sshd:1.3.0"... +0ms
  testcontainers [DEBUG] [3ad74f7bc7e0] Starting container... +0ms
  testcontainers [DEBUG] [3ad74f7bc7e0] Started container +142ms
  testcontainers [INFO] [3ad74f7bc7e0] Started container for image "testcontainers/sshd:1.3.0" +0ms
  testcontainers [DEBUG] [3ad74f7bc7e0] Fetching container logs... +4ms
  testcontainers [DEBUG] [3ad74f7bc7e0] Waiting for container to be ready... +0ms
  testcontainers [DEBUG] [3ad74f7bc7e0] Waiting for host port 55173... +0ms
  testcontainers [DEBUG] [3ad74f7bc7e0] Waiting for internal port 22/tcp... +1ms
  testcontainers [DEBUG] [3ad74f7bc7e0] Host port 55173 ready +3ms
  testcontainers [DEBUG] [3ad74f7bc7e0] Host port wait strategy complete +0ms
  testcontainers [DEBUG] [3ad74f7bc7e0] Demuxing stream... +2ms
  testcontainers [DEBUG] [3ad74f7bc7e0] Demuxed stream +0ms
  testcontainers:containers [3ad74f7bc7e0] chpasswd: password for 'root' changed +232ms
  testcontainers [DEBUG] [3ad74f7bc7e0] Internal port 22/tcp ready +47ms
  testcontainers [DEBUG] [3ad74f7bc7e0] Internal port wait strategy complete +1ms
  testcontainers [INFO] [3ad74f7bc7e0] Container is ready +0ms
  testcontainers [DEBUG] Connecting to Port Forwarder on "127.0.0.1:55173"... +0ms
  testcontainers [DEBUG] Connected to Port Forwarder on "127.0.0.1:55173" +35ms
  testcontainers [DEBUG] Releasing lock file "/private/var/folders/y0/b_sql0pn5j978xs8jz_4kx580000gp/T/testcontainers-node-sshd.lock"... +0ms
  testcontainers [DEBUG] Released lock file "/private/var/folders/y0/b_sql0pn5j978xs8jz_4kx580000gp/T/testcontainers-node-sshd.lock" +0ms
got forwarder instance
  testcontainers [INFO] Exposing host port 3000... +0ms

Steps to Reproduce
https://github.com/cre8/testcontainers-vitest-bug
Repo to reproduce the bug.

Environment Information

  • Operating System: macOS and Github Public Runner
  • Docker Version: Docker version 27.4.0, build bde2b89
  • Node version: 24.5.0
  • Testcontainers version: 11.8.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions