From 186d73c66b4b1173c17aa8818b5746ce5f0338d0 Mon Sep 17 00:00:00 2001 From: Cristian Greco Date: Sun, 11 Oct 2026 11:05:37 +0100 Subject: [PATCH 1/2] Run the smoke tests against the packed package Pack the built package and install the tarball into an empty project, then run the smoke tests there. They now import "testcontainers" by name, so they exercise the published files, the `main` entry and only the declared production dependencies. --- .github/workflows/checks.yml | 33 ++++++++++++++++------ packages/testcontainers/smoke-test.jest.js | 2 +- packages/testcontainers/smoke-test.js | 2 +- packages/testcontainers/smoke-test.mjs | 2 +- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index cf2ba23b3..e2e13aa68 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -131,17 +131,26 @@ jobs: workspace: "testcontainers" - name: Build testcontainers run: npm run build --workspace packages/testcontainers - - name: Remove dev dependencies - run: npm prune --omit=dev --workspace packages/testcontainers + - name: Install the packed package into an empty project + run: | + npm pack --workspace packages/testcontainers --pack-destination "${RUNNER_TEMP}" + mkdir "${RUNNER_TEMP}/smoke-test" + cp .npmrc packages/testcontainers/smoke-test.* "${RUNNER_TEMP}/smoke-test" + cd "${RUNNER_TEMP}/smoke-test" + npm init --yes > /dev/null + npm install "${RUNNER_TEMP}"/testcontainers-*.tgz - name: Run CommonJS module smoke test - run: node packages/testcontainers/smoke-test.js + working-directory: ${{ runner.temp }}/smoke-test + run: node ./smoke-test.js env: DEBUG: "testcontainers*" - name: Run ES module smoke test - run: node packages/testcontainers/smoke-test.mjs + working-directory: ${{ runner.temp }}/smoke-test + run: node ./smoke-test.mjs env: DEBUG: "testcontainers*" - name: Run Jest CommonJS runtime smoke test + working-directory: ${{ runner.temp }}/smoke-test run: npm exec --yes --package jest@30.4.2 -- jest --testMatch "**/smoke-test.jest.js" --runInBand --transform "{}" env: DEBUG: "testcontainers*" @@ -165,18 +174,26 @@ jobs: workspace: "testcontainers" - name: Build testcontainers run: npm run build --workspace packages/testcontainers - - name: Remove dev dependencies - run: npm prune --omit=dev --workspace packages/testcontainers + - name: Install the packed package into an empty project + run: | + npm pack --workspace packages/testcontainers --pack-destination "${RUNNER_TEMP}" + mkdir "${RUNNER_TEMP}/smoke-test" + cp .npmrc packages/testcontainers/smoke-test.* "${RUNNER_TEMP}/smoke-test" + cd "${RUNNER_TEMP}/smoke-test" + npm init --yes > /dev/null + npm install "${RUNNER_TEMP}"/testcontainers-*.tgz - name: Install Bun uses: oven-sh/setup-bun@v2 with: bun-version: 1.4.2 - name: Run CommonJS module smoke test - run: bun packages/testcontainers/smoke-test.js + working-directory: ${{ runner.temp }}/smoke-test + run: bun ./smoke-test.js env: DEBUG: "testcontainers*" - name: Run ES module smoke test - run: bun packages/testcontainers/smoke-test.mjs + working-directory: ${{ runner.temp }}/smoke-test + run: bun ./smoke-test.mjs env: DEBUG: "testcontainers*" diff --git a/packages/testcontainers/smoke-test.jest.js b/packages/testcontainers/smoke-test.jest.js index a7e23dfcd..701133723 100644 --- a/packages/testcontainers/smoke-test.jest.js +++ b/packages/testcontainers/smoke-test.jest.js @@ -1,4 +1,4 @@ -const { GenericContainer } = require("./build/index"); +const { GenericContainer } = require("testcontainers"); jest.setTimeout(120_000); diff --git a/packages/testcontainers/smoke-test.js b/packages/testcontainers/smoke-test.js index 0da0d1d0f..e37646d8b 100644 --- a/packages/testcontainers/smoke-test.js +++ b/packages/testcontainers/smoke-test.js @@ -1,4 +1,4 @@ -const { GenericContainer } = require("./build/index"); +const { GenericContainer } = require("testcontainers"); (async () => { const container = await new GenericContainer("alpine:3.12").withCommand(["sleep", "infinity"]).start(); diff --git a/packages/testcontainers/smoke-test.mjs b/packages/testcontainers/smoke-test.mjs index 2b23963f8..32ccc71f9 100644 --- a/packages/testcontainers/smoke-test.mjs +++ b/packages/testcontainers/smoke-test.mjs @@ -1,4 +1,4 @@ -import { GenericContainer } from "./build/index.js"; +import { GenericContainer } from "testcontainers"; const container = await new GenericContainer("alpine:3.12").withCommand(["sleep", "infinity"]).start(); From c394e52d03a885917338f54a3ef4b20c5d34ce27 Mon Sep 17 00:00:00 2001 From: Cristian Greco Date: Sun, 11 Oct 2026 11:17:29 +0100 Subject: [PATCH 2/2] Move the smoke test setup into an action and pin it to the lockfile Install the production dependencies with `npm ci --omit=dev` so the smoke tests use the versions in package-lock.json, then swap the workspace link for the unpacked tarball. Both jobs now share this through a smoke-test-setup action. --- .github/actions/smoke-test-setup/action.yml | 41 +++++++++++++++++++++ .github/workflows/checks.yml | 36 ++++++------------ 2 files changed, 52 insertions(+), 25 deletions(-) create mode 100644 .github/actions/smoke-test-setup/action.yml diff --git a/.github/actions/smoke-test-setup/action.yml b/.github/actions/smoke-test-setup/action.yml new file mode 100644 index 000000000..51ae79b57 --- /dev/null +++ b/.github/actions/smoke-test-setup/action.yml @@ -0,0 +1,41 @@ +name: "Smoke Test Setup" +description: "Installs the packed testcontainers package and its production dependencies into an empty project" + +outputs: + path: + description: "Directory containing the smoke tests and the installed package" + value: ${{ steps.install.outputs.path }} + +runs: + using: "composite" + steps: + - name: Build and pack testcontainers + shell: bash + run: | + npm run build --workspace packages/testcontainers + npm pack --workspace packages/testcontainers --pack-destination "${RUNNER_TEMP}" + + - name: Install the package into an empty project + id: install + shell: bash + run: | + project="${RUNNER_TEMP}/smoke-test" + package="${project}/node_modules/testcontainers" + + # Production dependencies only, at the versions in package-lock.json. + npm ci --omit=dev --workspace packages/testcontainers + + mkdir "${project}" + echo '{ "private": true }' > "${project}/package.json" + cp .npmrc packages/testcontainers/smoke-test.* "${project}" + mv node_modules "${project}/node_modules" + + # Replace the workspace link with the files that get published. + rm "${package}" + mkdir "${package}" + tar -xzf "${RUNNER_TEMP}"/testcontainers-*.tgz -C "${package}" --strip-components=1 + if [ -d packages/testcontainers/node_modules ]; then + mv packages/testcontainers/node_modules "${package}/node_modules" + fi + + echo "path=${project}" >> "$GITHUB_OUTPUT" diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index e2e13aa68..b3fd9cbb0 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -129,28 +129,21 @@ jobs: runner: ubuntu-24.04 node-version: ${{ matrix.node-version }} workspace: "testcontainers" - - name: Build testcontainers - run: npm run build --workspace packages/testcontainers - - name: Install the packed package into an empty project - run: | - npm pack --workspace packages/testcontainers --pack-destination "${RUNNER_TEMP}" - mkdir "${RUNNER_TEMP}/smoke-test" - cp .npmrc packages/testcontainers/smoke-test.* "${RUNNER_TEMP}/smoke-test" - cd "${RUNNER_TEMP}/smoke-test" - npm init --yes > /dev/null - npm install "${RUNNER_TEMP}"/testcontainers-*.tgz + - name: Install the packed package + id: smoke-test + uses: ./.github/actions/smoke-test-setup - name: Run CommonJS module smoke test - working-directory: ${{ runner.temp }}/smoke-test + working-directory: ${{ steps.smoke-test.outputs.path }} run: node ./smoke-test.js env: DEBUG: "testcontainers*" - name: Run ES module smoke test - working-directory: ${{ runner.temp }}/smoke-test + working-directory: ${{ steps.smoke-test.outputs.path }} run: node ./smoke-test.mjs env: DEBUG: "testcontainers*" - name: Run Jest CommonJS runtime smoke test - working-directory: ${{ runner.temp }}/smoke-test + working-directory: ${{ steps.smoke-test.outputs.path }} run: npm exec --yes --package jest@30.4.2 -- jest --testMatch "**/smoke-test.jest.js" --runInBand --transform "{}" env: DEBUG: "testcontainers*" @@ -172,27 +165,20 @@ jobs: runner: ubuntu-24.04 node-version: 24.x workspace: "testcontainers" - - name: Build testcontainers - run: npm run build --workspace packages/testcontainers - - name: Install the packed package into an empty project - run: | - npm pack --workspace packages/testcontainers --pack-destination "${RUNNER_TEMP}" - mkdir "${RUNNER_TEMP}/smoke-test" - cp .npmrc packages/testcontainers/smoke-test.* "${RUNNER_TEMP}/smoke-test" - cd "${RUNNER_TEMP}/smoke-test" - npm init --yes > /dev/null - npm install "${RUNNER_TEMP}"/testcontainers-*.tgz + - name: Install the packed package + id: smoke-test + uses: ./.github/actions/smoke-test-setup - name: Install Bun uses: oven-sh/setup-bun@v2 with: bun-version: 1.4.2 - name: Run CommonJS module smoke test - working-directory: ${{ runner.temp }}/smoke-test + working-directory: ${{ steps.smoke-test.outputs.path }} run: bun ./smoke-test.js env: DEBUG: "testcontainers*" - name: Run ES module smoke test - working-directory: ${{ runner.temp }}/smoke-test + working-directory: ${{ steps.smoke-test.outputs.path }} run: bun ./smoke-test.mjs env: DEBUG: "testcontainers*"