Detalhes do pacote

elm-test

rtfeldman92.3kBSD-3-Clause0.19.1-revision16

Run elm-test suites.

elm, elm-test, cli

readme (leia-me)

node-test-runner Version

Runs elm-explorations/test suites in Node.js.

When people say “elm-test” they usually refer to either:

  • This CLI tool for running tests.
  • elm-explorations/test – an Elm package for defining tests that this CLI tool can run.

Versions

Not all versions of elm-explorations/test and this CLI tool work together!

elm-explorations/test elm-test CLI
>= 2.0.0 >= 0.19.1-revision10
<= 1.2.2 <= 0.19.1-revision9

Unfortunate behavior of 0.19.1-revision9 and older

  • elm-test init always installs the latest elm-explorations/test. This means that if you run elm-test init on version 0.19.1-revision9 or older, you will get elm-explorations/test 2.0.0 or later, which don’t work 100 % together (see the next point).
  • elm-test 0.19.1-revision9 or older do not validate that elm-explorations/test in your elm.json has a compatible version. If you upgrade to elm-explorations/test 2.0.0 or later but forget to upgrade the elm-test CLI, most things will still work, but test distribution diagrams (new in elm-explorations/test 2.0.0) won’t show up. So if you use Test.fuzzWith and wonder why distribution diagrams never show up – check your elm-test CLI version!
  • There exists an elm-test CLI version called just "0.19.1". It should have been called "0.19.1-revision1", but unfortunately isn’t. Don’t make the mistake thinking it’s the latest version! You always want "0.19.1-revisionX".

Installation

npm install --save-dev elm-test

Quick start

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

Where to put tests

Locating files containing tests

There are 3 places you could put your tests:

  1. In the tests/ folder.

    This is the default and requires no extra setup.

  2. In any source directory ("source-directories" in elm.json for applications, src/ for packages) as separate files.

    A convention is to put test files next to the file it tests with a Tests suffix. For example, you could have src/LoginForm.elm and 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.json are available in these files.

  3. 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.json into 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" in elm.json.

Locating tests within files

For elm-test to find tests in your files you need to:

  1. Create top-level values of the type Test. You can name the values anything – the only thing that matters is that their type is Test.
  2. Expose them.

Example:

module LoginForm exposing (alreadyLoggedInTests, tests)

import Test exposing (Test)


tests : Test
tests =
    -- ...


alreadyLoggedInTests : Test
alreadyLoggedInTests =
    -- ...

Some prefer to expose a single Test value and group everything using describe. Some prefer to expose several Test values.

Also check out the elm-explorations/test quick-start guide!

Command Line Arguments

These are the most common commands and flags. Run elm-test --help for an exhaustive list.

Note: Throughout this section, the npx prefix is omitted for brevity.

install

Like elm install, except elm-test will install to "test-dependencies" in your elm.json instead of to "dependencies".

elm-test install elm/regex

init

Runs elm-test install elm-explorations/test and then creates a tests/Example.elm example test to get you started.

elm-test init requires an elm.json file up the directory tree, so you will need to run elm init first if you don’t already have one.

After initializing elm-test in your project, try out the example by running elm-test with no arguments.

elm init
elm-test init
elm-test

--watch

Start the runner in watch mode. Your tests will automatically rerun whenever your project changes.

elm-test --watch

--seed

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 --seed flag) is printed after each test run. Copy, paste and run it!

elm-test --seed 336948560956134

--fuzz

Define how many times each fuzz-test should run. Defaults to 100.

elm-test --fuzz 500

--report

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

--no-color

Disable colored console output.

Colors are also disabled when you pipe the output of elm-test to another program. You can use --color to force the colors back.

Alternatively, you can set the environment variable FORCE_COLOR to 0 to disable colors, or to any other value to force them.

See chalk.supportsColor for more information.

--compiler

If elm is not in your $PATH when 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 npm you can use npx:

npx elm-test

npx adds the local node_modules/.bin/ folder to $PATH when it executes the command passed to it. This means that if you have installed elm locally, elm-test will 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.

Travis CI

If you want to run your tests on Travis CI, here's a good starter .travis.yml:

language: elm
elm:
  - 0.19.1

Here is an example travis.yml configuration file for running tests in CI.

changelog (log de mudanças)

Changelog

Notable changes to this project will be documented in this file.

The format is based on Keep a Changelog. This project mirrors the Elm version. So version 0.19.1-revisionX of this project will be compatible with Elm 0.19.1.

0.19.1-revision16 - 2025-07-06

Fixed

elm-test now works with an upcoming version of the Lamdera compiler. Lamdera has a cool new optimization, that unfortunately made elm-test unable to find tests. Now that is fixed! Thanks to Leonardo Taglialegne!

0.19.1-revision15 - 2025-02-16

Fixed

This version replaces the glob dependency with tinyglobby, which is used by elm-review, and many other popular projects. This has a couple of benefits:

  • Restores the Node.js 12 support lost in 0.19.1-revision13.
  • Fixes globs that resolve to directories on Windows. Regression since 0.19.1-revision13, due to the glob upgrade. The test suite was previously missing coverage for this.
  • tinyglobby is much smaller than glob, reducing the installation size and number of indirect dependencies.

Thanks to Jeroen Engels for making the pull request fixing this, and to @lishaduck for introducing tinyglobby to elm-review and suggesting elm-test should use it too!

0.19.1-revision14 - 2025-02-15

Fixed

0.19.1-revision13 unfortunately did not work out of the box in Node.js 12–18 due to a bug in npm versions older than v10. This version is a quick-fix that restores support for Node.js 14–18, while still not causing deprecation warnings. Thanks to @lishaduck for reporting!

Unfortunately, Node.js 12 is still broken. You need to stay on 0.19.1-revision12 if you use Node.js 12.

(For those interested, the fix was changing the glob version range to ^8.0.3 to ^8.0.3 || ^9.0.0 || ^10.0.0. ^11.0.0 was removed from it due to the linked npm bug.)

0.19.1-revision13 - 2025-02-14

Fixed

  • elm-test no longer fails with an error about duplicate source directories if your elm.json contains "source-directories": ["tests"].
  • The glob dependency version has been updated from ^8.0.3 to ^8.0.3 || ^9.0.0 || ^10.0.0 || ^11.0.0. This allows npm (or your package manager of choice) to install the latest version of glob that works with your Node.js version. Versions 8 and 9 are deprecated. If you use Node.js 16 or later, this allows you to get rid of deprecation warnings.
  • The elm-solve-deps-wasm dependency version has been updated from ^1.0.2 to ^1.0.2 || ^2.0.0, which is the same version constraint that elm-review 2.13.0 uses. If you install the latest version of both elm-test and elm-review, you only get one copy of elm-solve-deps-wasm in node_modules/ instead of two, saving about 288 KB.

0.19.1-revision12 - 2023-02-16

Fixed

  • elm-test --report junit now works with elm-program-test. The junit report is XML. elm-program-test uses some characters that are not allowed in XML. This version replaces such disallowed characters with an Elm-style escape sequence, instead of crashing like it did before. Thanks to Christoph Hermann for reporting and to Ilias Van Peer for fixing!

0.19.1-revision11 - 2023-01-02

Fixed

  • elm-test init now prints a working link to the elm-explorations/test package. Thanks to Max Strübing!
  • If you ever saw RuntimeError: unreachable when trying to use elm-test, that should not be possible to happen anymore. elm-test now depends on the latest version of elm-solve-deps-wasm which solved that problem. (Previously, you had to make sure you had that version installed yourself).

0.19.1-revision10 - 2022-10-11

⚠️ Updating to this version also requires upgrading to the just released elm-explorations/test 2.0.0!

Breaking

  • This version of elm-test only works with elm-explorations/test 2.x (2.0.0 <= v < 3.0.0), which was just released. The versions table should make it clear which versions work together.

  • Removed elm-test install-unstable-test-master and elm-test uninstall-unstable-test-master. They are no longer needed since elm-explorations/test 2.0.0 has been released.

Added

  • Fuzzer distribution statistics report. Fuzzer distribution is new in elm-explorations/test 2.0.0, and it required a change in how things are reported from Elm to the test runner, which is why elm-test 0.19.1-revision10 is not compatible with older elm-explorations/test versions.

  • The --no-clear-console flag. By default, elm-test --watch clears the screen on every re-run, so you only see up-to-date output. With --no-clear-console, the console is not cleared and a separator is instead printed between the old and new output instead (similar to how elm-test-rs works). This is useful if you are running several commands in the same terminal and don’t want elm-test --watch to clear away output from other commands.

0.19.1-revision9 - 2022-07-03

Fixed

  • elm-test install-unstable-test-master (added in the previous version) now works with packages.

0.19.1-revision8 - 2022-06-20

Breaking

  • Removed support for Node.js 10 (which reached end of life 2021-04-30). Node.js 12.20.0 is now the minimum supported Node.js version. (Node.js 12 actually reached end of life 2022-04-30, but we decided to keep support for it for a while longer since there was no need of dropping it right now.)

Added

  • elm-test install-unstable-test-master
    • which installs the master version of the elm-explorations/test library in place of the 1.2.2 version in your ELM_HOME
  • elm-test uninstall-unstable-test-master
    • which undoes that

This let’s you test the upcoming major version of elm-explorations/test. Big thanks to Martin Janiczek!

Changed

  • elm-test no longer uses elm-json to calculate the set of dependencies needed to run your tests. Instead, we use elm-solve-deps-wasm which basically is a WebAssembly port of the dependency solver in elm-test-rs. Big thanks to Matthieu Pizenberg! Benefits of this change:

    • elm-test no longer needs to download the elm-json binary at install time or run time. elm-solve-deps-wasm is a regular, cross platform npm package.
    • Improves compatibility with Lamdera.
    • elm-solve-deps-wasm works offline to a greater extent than elm-json. Many times it doesn’t need to make any calls to package.elm-lang.org at all!
  • elm-test now shows suggestions on misspelled CLI flags.

Fixed

  • If you have module MyTest exposing (..) with the expose-all (..) and a char literal with a unicode escape, like '\u{000D}', in the same file, elm-test now correctly finds all tests to run in that file. A bug with unicode escape parsing previously caused no tests to be found.

0.19.1-revision7 - 2021-05-14

Fixed

  • elm-test now works if you have { "type": "module" } in your package.json.
  • --output=/dev/null is now ignored. This is needed by Emacs’ flycheck-elm package, which calls both elm make and elm-test make with --output=/dev/null. elm-test make does not produce any output files, so the flag doesn’t change anything. (Before 0.19.1-revision5, all unknown flags were silently ignored.)
  • The “no tests found” error message now works with --report=json and --report=junit again (regression in 0.19.1-revision5).
  • Better error message for --fuzz=0.

0.19.1-revision6 - 2020-01-29

Fixed

  • The --no-color and --color flags (to disable and force colors) now work again (regression in 0.19.1-revision5).
  • --no-color now turns off colors in Elm compiler error messages as well.

0.19.1-revision5 - 2020-01-28

Breaking

  • Removed support for Node.js 8 (which reached end of life 2019-12-31). Node.js 10.13.0 is now the minimum supported Node.js version.
  • Removed the undocumented --verbose flag. It didn’t do much at all in its current state.

Fixed

  • Now works on Apple Silicon/M1/ARM MacBooks. Installation used to fail with “Error: No binaries are available for your platform: darwin-arm64.”
  • You can now run your test from a subdirectory. elm-test finds your elm.json up the directory tree instead of printing an error.
  • If you had a port named send or receive and they were reached via test cases, elm-test used to fail with a duplicate port error. elm-test has renamed its internal ports so that conflicts are very unlikely.
  • The JUnit reporter now says @failures instead of @failed which makes Jenkins happier.
  • elm-test now errors on unknown (misspelled) flags instead of silently ignoring them.
  • elm-test now errors on bad --fuzz and --seed values instead of silently ignoring them.
  • A whole host of Elm package dependencies errors, by using elm-json to calculate the set of dependencies needed to run your tests.
  • elm-test --watch no longer crashes if for packages if there are compilation errors in src/ at startup.
  • elm-test --watch now detects changes in your elm.json.
  • elm-test --watch now works better when lots of files change at once. If 10 files changed, your tests used to run 10 times in sequence (more or less). Now, they only run once or twice. Changes within 100 ms are batched together. Changes happening while the tests are running no longer queue up – they instead trigger one single test once the current run is done.
  • Compilation errors are no longer hidden by a super long “Compilation failed while attempting to build [absolute paths to every single test Elm file]” message.
  • A bunch of checks and validations have been added to help in edge cases.

Performance

  • elm-test is now faster to install (by having fewer dependencies). It used to be around 18 MB, now it’s just 2 MB.
  • elm-test now runs about half a second faster, by no longer using elmi-to-json. (As a bonus, if you ever encountered errors mentioning elmi-to-json, that won’t happen anymore.)
  • elm-test --watch now reruns your tests sooner after file changes (about 100 ms after the changes, instead of about 500 ms).

Changed

  • The --help output is now more conventional and hopefully easier to read.

0.19.1-revision4 - 2020-09-21

Fixed

  • The --compiler command line flag now correctly finds elm executables on your PATH (see #438).
  • We have hugely slimmed down the reproduction instructions so that the test runner no longer prints hundreds of test file paths to the console (see issue #431 and fix #432).

Performance

  • A whole host of spring cleaning that streamlines the test runner. (see #425).

0.19.1-revision3 - 2020-01-10

Fixed

  • Pointing to specific test files sometimes failed (see issue #391 and fix #404).

0.19.1-revision2 - 2019-10-22

Performance

  • Update elmi-to-json and use --for-elm-test to optimise collection of tests (#396).

0.19.1 - 2019-12-04

Breaking

  • drop support for elm 0.19.0
  • elm-test --help now exits with code 0.

Added

0.19.0-rev6 - 2019-03-10

Fixed

  • npm audit complaints on versions of chokidar and node-elm-compiler

0.19.0-rev5 - 2019-02-22

Fixed

  • Excessive small highlights in some diffs (#263)
  • Upgraded to a version of lodash with a vulnerability fixed.

0.19.0 - 2018-08-19

Added

  • elm-test install PACKAGE - works like elm install but installs into test-dependencies

Removed

  • --add-dependencies (replaced by elm-test install)
  • CLI aliases (e.g. -f as a shorthand for --fuzz).

0.18.11 - 2017-08-07

Fixed

  • Low-contrast diff color (#229)
  • Socket write edge case (#228)
  • Invalid JUnit XML (#218)

0.18.10 - 2017-11-16

Fixed

  • Potentially fixed: elm-test hanging

0.18.8 - 2017-08-07

Added

  • Run tests in parallel (#45)

Fixed

  • --watch error reporting (#192)
  • --watch potential extra compile processes (#194)

Internal

  • More accurate timetracking
  • Use symlinks to improve generated code performance
  • Use Elm instead of Chalk for colored console output
  • Use Prettier

0.18.7 - 2017-06-30

Fixed

  • All reporters were considered "machine readable", resulting in the error stream being ignored (#161)

Added

  • We have a changelog! (#151)
  • Proper error messages when username or repository name contains dots (#166)

Internal

  • Add flow type annotations to prevent silly JS mistakes! (#162)

0.18.6 - 2017-06-12

Changed

  • Imports in the Example.elm file are now sorted for compatibility with elm-format@exp

0.18.5 - 2017-06-11

Fixed

  • --report flag broken (#155)

Added

  • If your project depends on elm-lang/html, elm-test init will add a dependency to eeue56/elm-html-test so you can test your HTML. (#154)

0.18.4 - 2017-05-30

Fixed

  • Runner no longer fails when CWD has spaces in it (#147)
  • Tests that are port modules or effect modules are no longer rejected (#143)

0.18.3 - 2017-05-25

Added

  • --add-dependencies target/elm-package.json flag to add any missing dependencies from the elm-package.json file in the current director to the target/elm-package.json file. (#28)
  • Test.todo to mark tests as not yet implemented. (#104)
  • --fuzz flag to override the default fuzz count. (#77)
  • Test.only and Test.skip to limit which tests will be executed.

Changed

  • elm-test init now adds all dependencies from the package elm-package.json to the generated tests/elm-package.json file. (#68)
  • You no longer write a tests/Main.elm file. Rather, you pass the paths to your tests to the elm-test executable to run just those files, or you run elm-test without arguments which will look for all elm files under tests/ and test/. (#72)
  • All exposed values of type Test are executed by the test-runner.
  • Duplicate titles/descriptions fail the test run. (#115)
  • Empty describes are no longer allowed. (#95)

Fixed

  • Ignores elm-stuff (#100)
  • Tests that throw a runtime exception fail with the exception message as failure, rather than crashing the runner. (#69)

Migrating from 0.18.2

  • Upgrade the runner npm i -g elm-test
  • Remove tests/Main.elm
  • Remove the dependency on rtfeldman/node-test-runner from tests/elm-package.json
  • Bump the dependency on elm-community/elm-test to 4.2.0 <= v < 5.0.0 in tests/elm-package.json
  • Ensure your test files expose each test you want to run, and that those values are of type Test
  • Make sure those tests aren't defined twice (for example: once as a top-level value, and again in a describe block) or they will be executed twice.
  • run elm-test to execute your tests.