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 cf2ba23b3..b3fd9cbb0 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -129,19 +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: Remove dev dependencies - run: npm prune --omit=dev --workspace packages/testcontainers + - name: Install the packed package + id: smoke-test + uses: ./.github/actions/smoke-test-setup - name: Run CommonJS module smoke test - run: node packages/testcontainers/smoke-test.js + working-directory: ${{ steps.smoke-test.outputs.path }} + run: node ./smoke-test.js env: DEBUG: "testcontainers*" - name: Run ES module smoke test - run: node packages/testcontainers/smoke-test.mjs + working-directory: ${{ steps.smoke-test.outputs.path }} + run: node ./smoke-test.mjs env: DEBUG: "testcontainers*" - name: Run Jest CommonJS runtime 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*" @@ -163,20 +165,21 @@ jobs: runner: ubuntu-24.04 node-version: 24.x 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 + 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 - run: bun packages/testcontainers/smoke-test.js + working-directory: ${{ steps.smoke-test.outputs.path }} + run: bun ./smoke-test.js env: DEBUG: "testcontainers*" - name: Run ES module smoke test - run: bun packages/testcontainers/smoke-test.mjs + working-directory: ${{ steps.smoke-test.outputs.path }} + 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();