Run tests against a lane
Use this when tests need the project’s services up, such as API or end-to-end tests.
::example{slug="workflows-ci-with"}
Read the URLs from the environment
Section titled “Read the URLs from the environment”Ports and hostnames differ per lane, so read each service’s URL from DEVLANES_PUBLIC_URL_<SERVICE>, such as DEVLANES_PUBLIC_URL_API for the API:
import assert from "node:assert/strict";import { test } from "node:test";
test("api answers /healthz", async () => { const res = await fetch(new URL("/healthz", process.env.DEVLANES_PUBLIC_URL_API)); assert.equal(res.status, 200);});The tests also get variables that point Node, Deno and Python at the devlanes CA, so they trust the HTTPS URLs. Environment variables lists them.
Run the tests
Section titled “Run the tests”Put the test command after the two dashes:
$ devlanes with -- node --test "api/*.test.mjs"devlanes starts what the lane needs, waits until the services are ready, runs the tests, stops what it started and exits with the tests’ exit code. On a lane that already runs, it starts only what is missing and leaves the rest running. When a service fails to start, the tests do not run and the command exits with 1.
If the tests need other settings
Section titled “If the tests need other settings”Name a profile, a named set of services and their settings, such as one that runs each service’s start script instead of its dev script:
profiles: e2e: include: ["*"] run_scripts: dev: startprofilesNamed selections of services for devlanes start --profile <name>. A plain devlanes start brings back what the lane ran before; default is used when there is nothing to bring back, such as after devlanes stop. A profile is a list of names, globs and +tag selectors, or a mapping that can also exclude services, skip infra, add env and remap script names.
profiles.<name>Services started by devlanes start --profile <name> (default when no profile is given): a list of names, globs and +tag selectors, or a mapping that can also exclude services, skip infra, add env and remap script names. Several --profile flags start the union.
profiles.<name>.includeServices this profile starts: names, globs such as crm-*, and +tag selectors. Globs skip services with autostart: false; names and tags include them.
profiles.<name>.run_scriptsSwap script names for services that use run_script: { dev: start } runs the start script wherever a service's run_script names dev. The file stays the same, and each name is swapped once, not chained. The whole name is matched, so a Maven or Gradle name such as spring-boot:run -Pdev is swapped only by that exact text.
profiles.<name>.run_scripts.<name>Swap script names for services that use run_script: { dev: start } runs the start script wherever a service's run_script names dev. The file stays the same, and each name is swapped once, not chained. The whole name is matched, so a Maven or Gradle name such as spring-boot:run -Pdev is swapped only by that exact text.
$ devlanes with --profile e2e -- npm testIf you need the logs afterwards
Section titled “If you need the logs afterwards”--logs-dir writes one log file per service and task the run started, such as unit-api.log, into the folder you name. A unit that printed nothing gets no file. Run tests in CI keeps that folder.