|
| 1 | +--- |
| 2 | +permalink: /environment-variables |
| 3 | +title: Environment Variables |
| 4 | +--- |
| 5 | + |
| 6 | +# Environment Variables |
| 7 | + |
| 8 | +CodeceptJS reads several environment variables that change runtime behavior. They are useful for tuning CI runs, enabling extra logging, configuring the MCP server, or wiring values into the generated `codecept.conf.js`. |
| 9 | + |
| 10 | +This page is a reference for every `process.env.*` switch CodeceptJS reads or sets internally. |
| 11 | + |
| 12 | +## Quick Reference |
| 13 | + |
| 14 | +| Variable | Category | Default | Purpose | |
| 15 | +| :--- | :--- | :--- | :--- | |
| 16 | +| `profile` | Test execution | _unset_ | Profile name forwarded from `--profile`; readable from config and helpers. | |
| 17 | +| `CI` | Test execution | _unset_ | Auto-set by every CI provider; enables CI-aware behavior. | |
| 18 | +| `DONT_FAIL_ON_EMPTY_RUN` | Test execution | _unset_ | When set, do not fail CI if zero tests were executed. | |
| 19 | +| `RUNS_WITH_WORKERS` | Workers | _unset_ | Set to `true` while running in workers; read by helpers/plugins to branch behavior. | |
| 20 | +| `CODECEPT_WORKER_TIMEOUT` | Workers | `5m` | Hung-worker watchdog timeout. Accepts [ms](https://github.com/vercel/ms) strings (`30s`, `2m`, `1h`). | |
| 21 | +| `CODECEPT_AUTO_EXIT_TIMEOUT` | Workers | `2000` | Time in ms allowed for helper cleanup before forced `process.exit`. Set to `0` to disable. | |
| 22 | +| `DEBUG` | Debug | _unset_ | `debug` package namespace filter, e.g. `codeceptjs:*`, `codeceptjs:heal`. | |
| 23 | +| `HEADLESS` | Init template | _unset_ | Read by `setHeadlessWhen()` in the generated config to toggle headless mode. | |
| 24 | +| `BASE_URL` | Init template | `http://localhost` | Default URL written into the generated Playwright config. | |
| 25 | + |
| 26 | +## Test Execution |
| 27 | + |
| 28 | +### `profile` |
| 29 | + |
| 30 | +Set automatically when you pass `--profile <name>` to `run`, `run-workers`, `run-rerun`, `run-multiple`, or `interactive`. The value is available inside `codecept.conf.js`, helpers, and plugins via `process.env.profile`, which is the standard way to switch configuration based on environment: |
| 31 | + |
| 32 | +```js |
| 33 | +exports.config = { |
| 34 | + helpers: { |
| 35 | + Playwright: { |
| 36 | + url: process.env.profile === 'staging' ? 'https://staging.example.com' : 'http://localhost:3000', |
| 37 | + }, |
| 38 | + }, |
| 39 | +} |
| 40 | +``` |
| 41 | + |
| 42 | +### `CI` |
| 43 | + |
| 44 | +A de-facto standard variable exported by every major CI provider (GitHub Actions, GitLab CI, CircleCI, Jenkins, Travis, etc.). CodeceptJS uses it for two CI-aware behaviors: |
| 45 | + |
| 46 | +- Extends the polling timeout for `submittedData()` to 60s (vs 2s locally). |
| 47 | +- Fails the run with exit code `1` if no tests were executed (see `DONT_FAIL_ON_EMPTY_RUN`). |
| 48 | + |
| 49 | +You should not need to set this manually. |
| 50 | + |
| 51 | +### `DONT_FAIL_ON_EMPTY_RUN` |
| 52 | + |
| 53 | +By default, when `CI` is set and no tests are executed (e.g. an over-restrictive `--grep`), CodeceptJS fails the run to surface false-positive green builds. Set `DONT_FAIL_ON_EMPTY_RUN=true` to keep the run green even when nothing ran. |
| 54 | + |
| 55 | +```yaml |
| 56 | +# .github/workflows/tests.yml |
| 57 | +env: |
| 58 | + DONT_FAIL_ON_EMPTY_RUN: 'true' |
| 59 | +``` |
| 60 | +
|
| 61 | +## Workers |
| 62 | +
|
| 63 | +### `RUNS_WITH_WORKERS` |
| 64 | + |
| 65 | +Automatically set to `'true'` while a `run-workers` invocation is active and reset to `'false'` when it finishes. Read it from helpers or plugins when you need to behave differently in worker mode — for example, to disable an interactive feature or change reporter output: |
| 66 | + |
| 67 | +```js |
| 68 | +if (process.env.RUNS_WITH_WORKERS === 'true') { |
| 69 | + // running in a worker thread |
| 70 | +} |
| 71 | +``` |
| 72 | + |
| 73 | +Do not set this manually. |
| 74 | + |
| 75 | +### `CODECEPT_WORKER_TIMEOUT` |
| 76 | + |
| 77 | +Per-worker hung-process watchdog. If a worker produces no output for this duration, it is auto-terminated and reported as failed. Accepts any string parsed by the [`ms`](https://github.com/vercel/ms) package: `30s`, `2m`, `5m`, `1h`. Defaults to `5m`. |
| 78 | + |
| 79 | +```sh |
| 80 | +CODECEPT_WORKER_TIMEOUT=10m npx codeceptjs run-workers 4 |
| 81 | +``` |
| 82 | + |
| 83 | +### `CODECEPT_AUTO_EXIT_TIMEOUT` |
| 84 | + |
| 85 | +Time in **milliseconds** that CodeceptJS waits for helper `_cleanup()` hooks to complete before calling `process.exit()`. Defaults to `2000`. Set to `0` to disable the auto-exit and let the Node event loop drain naturally — useful when long-running async work (e.g. report uploads) must complete after the test run. |
| 86 | + |
| 87 | +```sh |
| 88 | +CODECEPT_AUTO_EXIT_TIMEOUT=0 npx codeceptjs run |
| 89 | +``` |
| 90 | + |
| 91 | +## Debug |
| 92 | + |
| 93 | +### `DEBUG` |
| 94 | + |
| 95 | +Standard [`debug`](https://www.npmjs.com/package/debug) package selector. CodeceptJS emits debug output under the `codeceptjs:*` namespace. Useful namespaces: |
| 96 | + |
| 97 | +| Namespace | Source | |
| 98 | +| :--- | :--- | |
| 99 | +| `codeceptjs:*` | All internal logs | |
| 100 | +| `codeceptjs:recorder` | Recorder/promise queue | |
| 101 | +| `codeceptjs:event` | Event dispatcher | |
| 102 | +| `codeceptjs:container` | DI container | |
| 103 | +| `codeceptjs:steps` | Step lifecycle | |
| 104 | +| `codeceptjs:exit` | Exit listener | |
| 105 | +| `codeceptjs:timeout` | Global timeout listener | |
| 106 | +| `codeceptjs:pause` | Interactive pause | |
| 107 | +| `codeceptjs:ai` | AI features | |
| 108 | +| `codeceptjs:heal` | Heal plugin | |
| 109 | +| `codeceptjs:analyze` | Analyze plugin | |
| 110 | +| `codeceptjs:retryFailedStep` | retryFailedStep plugin | |
| 111 | +| `codeceptjs:bdd` | Gherkin/BDD | |
| 112 | + |
| 113 | +```sh |
| 114 | +DEBUG="codeceptjs:*" npx codeceptjs run --verbose |
| 115 | +DEBUG="codeceptjs:heal" npx codeceptjs run |
| 116 | +DEBUG="codeceptjs:retryFailedStep" npx codeceptjs run |
| 117 | +``` |
| 118 | + |
| 119 | +When `DEBUG` includes a `codeceptjs:` selector, the `heal` plugin keeps healing enabled in `--debug` mode (which otherwise disables it). |
| 120 | + |
| 121 | +## Init Template |
| 122 | + |
| 123 | +These variables are read by the configuration scaffolded by `codeceptjs init`. They have no effect unless your project's generated `codecept.conf.js` references them. |
| 124 | + |
| 125 | +### `HEADLESS` |
| 126 | + |
| 127 | +Read by [`setHeadlessWhen()`](https://www.npmjs.com/package/@codeceptjs/configure) in the generated config. When truthy, the browser starts headless. The init template wires this in so you can run `HEADLESS=true npx codeceptjs run` on CI without changing the config. |
| 128 | + |
| 129 | +### `BASE_URL` |
| 130 | + |
| 131 | +The init template uses `BASE_URL` (falling back to `http://localhost`) as the Playwright `url` value. After scaffolding, edit the generated config to change this default. |
0 commit comments