Run API tests in Docker, with no Node.js on the machine

Not every machine that should run API tests has Node.js: a Jenkins agent, a locked-down build server, a teammate who doesn't write JavaScript. Docker solves that. The Requestarium CLI runs from the official node image with npx, so there's nothing to build.

One command

Terminal
export REQUESTARIUM_TOKEN=trt_…
docker run --rm \
  -e REQUESTARIUM_TOKEN \
  -e REQUESTARIUM_NO_UPDATE_CHECK=1 \
  -v "$PWD/reports:/reports" \
  node:22-alpine \
  npx --yes @requestarium/[email protected] run-collection "Users API" \
    --env Staging --junit /reports/results.xml --html /reports/report.html
  • -e REQUESTARIUM_TOKEN passes the token from your shell without writing it on the command line.
  • The exit code of docker run is the CLI's exit code, so CI fails the step when a test fails.
  • Pin the CLI version (@0.7.0) so the image and the CLI change only when you decide.

Test a service in docker compose

When the API under test runs in compose, run the tests as one more service. Containers on the same compose network reach each other by service name:

docker-compose.test.yml
services:
  api:
    build: .
    environment:
      DATABASE_URL: postgres://app:app@db:5432/app
    depends_on: [db]
  db:
    image: postgres:17
    environment:
      POSTGRES_USER: app
      POSTGRES_PASSWORD: app
  api-tests:
    image: node:22-alpine
    depends_on: [api]
    environment:
      REQUESTARIUM_TOKEN: ${REQUESTARIUM_TOKEN}
      REQUESTARIUM_NO_UPDATE_CHECK: "1"
    volumes:
      - ./reports:/reports
    command: >
      npx --yes @requestarium/cli@0.7.0 run-collection "Users API"
      --env Local --var baseUrl=http://api:8080
      --junit /reports/results.xml
Terminal
docker compose -f docker-compose.test.yml up --build --exit-code-from api-tests

--exit-code-from api-tests makes compose return the tests' exit code and stop the other services when the tests finish.

The requests are sent from the container, so http://api:8080 works even though nothing is published on your machine. More on the setup in test APIs on localhost and docker compose.

A small image for repeat runs

npx downloads the CLI on every run. If that's too slow or your build servers have no npm access, bake it into an image once:

DOCKERFILE
FROM node:22-alpine
RUN npm install -g @requestarium/[email protected]
ENV REQUESTARIUM_NO_UPDATE_CHECK=1
ENTRYPOINT ["requestarium"]
Terminal
docker build -t api-tests .
docker run --rm -e REQUESTARIUM_TOKEN api-tests run-collection "Users API" --env Staging

Certificates and proxies

Behind a corporate proxy or with an internal CA, pass them in like any other option:

Terminal
docker run --rm -e REQUESTARIUM_TOKEN \
  -e REQUESTARIUM_PROXY=http://proxy.internal:3128 \
  -v "$PWD/certs:/certs:ro" -e REQUESTARIUM_CA_CERT=/certs/company-ca.pem \
  node:22-alpine npx --yes @requestarium/[email protected] run-collection "Users API" --env Staging