Elm Test Runner CLI
elm-test is the official Node.js command-line interface (CLI) for running test suites written with the `elm-explorations/test` Elm package. As of April 2026, the current stable version is `0.19.1-revision17`, with frequent patch-level releases (revisions) to address compatibility issues, bug fixes, and Node.js environment support. It functions by compiling Elm tests and executing them within a Node.js environment. A key differentiator is its tight coupling with specific versions of the `elm-explorations/test` Elm package; users must ensure compatibility between the CLI and the Elm testing library to avoid unexpected behavior, such as missing test distribution diagrams or compilation errors. It provides features like watch mode, selective test execution by file or glob, and various reporting formats.
Common errors
-
Error: Command failed: npx elm-test init --yes (or similar process crash output) / RuntimeError: unreachable
cause An older version of `elm-solve-deps-wasm` was causing runtime errors or `elm-test init` failures, or incompatibility with the Lamdera compiler.fixUpgrade `elm-test` to `0.19.1-revision11` or newer. This version bundles a fix for `RuntimeError: unreachable` and `0.19.1-revision16` fixed Lamdera compiler compatibility. -
XML parsing error or crash when generating JUnit report (e.g., `elm-test --report junit`)
cause Test outputs from `elm-program-test` (or other Elm test libraries) contained characters disallowed in XML, causing the JUnit reporter to crash.fixUpgrade `elm-test` to `0.19.1-revision12` or newer. This version escapes disallowed XML characters to prevent crashes. -
Error: Duplicate source directories (when `elm.json` contains `"source-directories": ["tests"]`)
cause A bug in `elm-test` versions prior to `0.19.1-revision13` would incorrectly report duplicate source directories if `tests` was explicitly listed in `elm.json`'s `source-directories`.fixUpgrade `elm-test` to `0.19.1-revision13` or newer.
Warnings
- breaking Starting with `elm-test@0.19.1-revision10`, this CLI tool strictly requires `elm-explorations/test` version `2.0.0` or newer (specifically `2.x.x`). Older versions of `elm-explorations/test` are incompatible.
- breaking Node.js 10 support was dropped in `elm-test@0.19.1-revision8`. The minimum required Node.js version is `12.20.0`.
- gotcha When using `elm-test` versions `0.19.1-revision9` or older, running `elm-test init` could install `elm-explorations/test@2.0.0` or later, which has known incompatibilities (e.g., missing distribution diagrams) despite partial functionality.
- gotcha Due to a naming quirk, there is an `npm` package named `0.19.1` which is not the latest version. The latest stable versions are always named `0.19.1-revisionX`.
- gotcha When specifying test files using globs (e.g., `src/**/*Tests.elm`), always wrap the glob pattern in double quotes. Without quotes, your shell might expand the glob prematurely, preventing `elm-test` from correctly handling file patterns, especially in watch mode or across different operating systems.
- gotcha Older `elm-test` revisions had intermittent Node.js compatibility issues, notably `0.19.1-revision13` and `0.19.1-revision14` which broke Node.js 12 (and `npm` v10 for `14-18`). While `0.19.1-revision15` and later restored Node.js 12 support, always check release notes if encountering Node.js environment errors.
Install
-
npm install elm-test -
yarn add elm-test -
pnpm add elm-test
Imports
- elm-test CLI
elm-test (without npx or if not globally installed)
npx elm-test
Quickstart
import { exec } from 'child_process';
import { promisify } from 'util';
const execPromise = promisify(exec);
async function runElmTests() {
try {
console.log("1. Installing elm-test as a dev dependency...");
// Using npm install locally ensures `npx elm-test` works reliably.
await execPromise('npm install --save-dev elm-test');
console.log("elm-test installed.");
console.log("2. Initializing Elm test project (creates tests/Example.elm and configures elm.json)...");
// The --yes flag answers 'y' to prompts, making it non-interactive.
const initOutput = await execPromise('npx elm-test init --yes');
console.log(initOutput.stdout);
console.log("3. Running all tests in the project...");
const runOutput = await execPromise('npx elm-test');
console.log(runOutput.stdout);
console.log("4. Running tests in a specific file (e.g., tests/Example.elm)...");
const specificFileOutput = await execPromise('npx elm-test tests/Example.elm');
console.log(specificFileOutput.stdout);
console.log("Quickstart complete. Note: Watch mode (npx elm-test --watch) runs indefinitely.");
} catch (error) {
console.error(`Error during elm-test quickstart: ${error.message}`);
console.error(`Stderr: ${error.stderr}`);
}
}
runElmTests();