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
tests/Example.elm:
npx elm-test init
Run tests in the
tests/folder:
npx elm-test
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:
In the
tests/folder.
This is the default and requires no extra setup.
In any source directory (
"source-directories"in
elm.jsonfor applications,
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
src/LoginForm.elmand
src/LoginFormTests.elm.
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
"test-dependencies"in your
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
"test-dependencies"in your
elm.jsoninto regular
"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:
Test.
Example:
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
Testvalues.
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.
Like
elm install, except elm-test will install to
"test-dependencies"in your
elm.jsoninstead of to
"dependencies".
elm-test install elm/regex
Runs
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.
elm-test --watch
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
100.
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
FORCE_COLORto
0to disable colors, or to any other value to force them.
See chalk.supportsColor for more information.
If
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
npx:
npx elm-test
npxadds the local
node_modules/.bin/folder to
$PATHwhen it executes the command passed to it. This means that if you have installed
elmlocally,
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
.travis.yml:
language: elm elm: - 0.19.1
travis.ymlconfiguration file for running tests in CI.