Runs elm-test suites from Node.js. Get it with npm install -g elm-test
Runs elm-explorations/test suites in Node.js.
When people say “elm-test” they usually refer to either:
npm install --save-dev elm-test
Install elm-explorations/test and create
npx elm-test init
Run tests in the
Run tests in one particular file:
npx elm-test tests/Example.elm
Run tests in files matching a glob:
npx elm-test "src/**/*Tests.elm"
Note: The double quotes are important! Without quotes, your shell might expand the globs for you. With quotes, elm-test expands the globs. This way the watcher can pick up new tests matching the globs, and it will work cross-platform.
Run in watch mode:
npx elm-test --watch
There are 3 places you could put your tests:
This is the default and requires no extra setup.
In any source directory (
src/for packages) as separate files.
A convention is to put test files next to the file it tests with a
Testssuffix. For example, you could have
This requires telling elm-test which folders/files to run. Examples:
npx elm-test "src/**/*Tests.elm" npx elm-test test/frontend/elm
You might also need to configure your editor to understand that the
elm.jsonare available in these files.
In already existing source files.
This allows testing internal functions without exposing them. (Be aware that testing implementation details can sometimes be counter-productive.)
This requires moving everything in
"dependencies", so your project still compiles. This also helps your editor. Note that this approach isn’t suitable for packages, since you don’t want your package to unnecessarily depend on elm-explorations/test.
You can mix all three variants if you want:
npx elm-test tests "src/**/*Tests.elm" app
In this example,"src"and"app"need to be in"source-directories"inelm.json.
For elm-test to find tests in your files you need to:
module LoginForm exposing (alreadyLoggedInTests, tests)
import Test exposing (Test)
tests : Test tests = -- ...
alreadyLoggedInTests : Test alreadyLoggedInTests = -- ...
Some prefer to expose a single
Testvalue and group everything using describe. Some prefer to expose several
Also check out the elm-explorations/test quick-start guide!
These are the most common commands and flags. Run
elm-test --helpfor an exhaustive list.
Note: Throughout this section, the
npxprefix is omitted for brevity.
elm install, except elm-test will install to
elm.jsoninstead of to
elm-test install elm/regex
elm-test install elm-explorations/testand then creates a
tests/Example.elmexample test to get you started.
elm-test initrequires an
elm.jsonfile up the directory tree, so you will need to run
elm initfirst if you don’t already have one.
After initializing elm-test in your project, try out the example by running
elm-testwith no arguments.
elm init elm-test init elm-test
Start the runner in watch mode. Your tests will automatically rerun whenever your project changes.
Run with a specific fuzzer seed, rather than a randomly generated seed. This allows reproducing a failing fuzz-test. The command needed to reproduce (including the
--seedflag) is printed after each test run. Copy, paste and run it!
elm-test --seed 336948560956134
Define how many times each fuzz-test should run. Defaults to
elm-test --fuzz 500
Specify which format to use for reporting test results. Valid options are:
console(default): pretty, human readable formatted output.
json: newline-delimited json with an object for each event.
junit: junit-compatible xml.
elm-test --report json
Disable colored console output.
Colors are also disabled when you pipe the output of
elm-testto another program. You can use
--colorto force the colors back.
Alternatively, you can set the environment variable
0to disable colors, or to any other value to force them.
See chalk.supportsColor for more information.
elmis not in your
$PATHwhen elm-test runs, or the Elm executable is called something other than
elm, you can use this flag to point to your installation.
elm-test --compiler /path/to/elm
To run a tool installed locally using
npmyou can use
npxadds the local
$PATHwhen it executes the command passed to it. This means that if you have installed
elm-testwill automatically find that local installation.
As mentioned in Installation we recommend installing elm-test locally in every project. This ensures all contributors and CI use the same version, to avoid nasty “works on my computer” issues.
If you want to run your tests on Travis CI, here's a good starter
language: elm elm: - 0.19.1