• Stars
    star
    133
  • Rank 272,600 (Top 6 %)
  • Language
    JavaScript
  • License
    BSD 3-Clause "New...
  • Created over 9 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Runs elm-test suites from Node.js. Get it with npm install -g elm-test

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.

More Repositories

1

seamless-immutable

Immutable data structures for JavaScript which are backwards-compatible with normal JS Arrays and Objects.
JavaScript
5,363
star
2

elm-spa-example

A Single Page Application written in Elm
Elm
3,251
star
3

elm-css

Typed CSS in Elm.
Elm
1,239
star
4

dreamwriter

(NOTE! This has not been updated since Elm 0.15.1.) Streamlined long-form writing software. Written in Elm.
JavaScript
459
star
5

elm-workshop

An introductory Elm workshop. Video available on Frontend Masters!
Elm
438
star
6

elm-0.19-workshop

Elm 0.19 workshops. Includes Intro and Advanced courses.
Elm
212
star
7

rust-1.51-workshop

Richard Feldman's Rust workshop
Rust
192
star
8

node-elm-compiler

A Node.js interface to the Elm compiler binaries.
TypeScript
170
star
9

elm-in-action

Resources for the Elm In Action book.
JavaScript
160
star
10

elm-validate

Convenience functions for validating Elm data.
Elm
144
star
11

elm-google-maps

Using Google Maps in Elm by way of Polymer
Elm
56
star
12

elm-use

Switch between Elm versions
JavaScript
38
star
13

elm-iso8601-date-strings

Convert between ISO-8601 date strings and Time.Posix
Elm
30
star
14

elm-web-workers

Write Elm code that talks to Web Workers.
Elm
28
star
15

selectlist

A nonempty list in which exactly one element is always selected.
Elm
27
star
16

elm-json-experiment

Experimental API for building JSON decoders
Elm
20
star
17

lambdaconf-2015-elm-workshop

Materials for the Elm Workshop at LambdaConf 2015
Elm
20
star
18

grunt-elm

Grunt plugin that compiles Elm files to JavaScript.
JavaScript
19
star
19

elm-codify

A tool to generate Elm decoders, encoders, and type aliases from JSON.
Elm
16
star
20

elm-0.18-workshop

An introductory Elm 0.18 workshop.
Elm
14
star
21

elm-node-app

Communication layer so Elm code can talk to Node.js code.
Elm
13
star
22

elm-css-helpers

Helpers for using elm-css with elm-html
Elm
11
star
23

dotfiles

Configuration files I use.
Shell
11
star
24

style-elements-demo

style-elements demo for ReactiveConf 2017 talk, "CSS as Bytecode"
Elm
8
star
25

elm-sorter-experiment

Experimental Sorter/Dict/Set API
Elm
8
star
26

elm-hex

Work with Hexadecimal numbers in Elm.
Elm
6
star
27

dreamwriter-coffee

Streamlined writing software. Written in React and CoffeeScript.
CoffeeScript
6
star
28

vector

List where head & tail don't return Maybe and still can't crash
Elm
6
star
29

count

Call record constructors with increasing integers. Surprisingly useful!
Elm
5
star
30

elm-signup-form

JavaScript
5
star
31

test-update

Convenience functions for testing update functions
Elm
5
star
32

mloc-2015-elm-workshop

Materials for the Elm Workshop at mloc.js 2015
Elm
5
star
33

hashed-class

Generate CSS classnames by hashing their styles.
Elm
5
star
34

hex

Work with Hexadecimal numbers in Elm.
Elm
4
star
35

roc-decimal-draft

Rust
3
star
36

quicksort-benchmarks

quicksort-benchmarks
Swift
3
star
37

csrf-xhr

Automatically add Rails CSRF tokens into XMLHttpRequest headers.
JavaScript
3
star
38

elm-in-action.com

Website for the book Elm in Action, from Manning Publications
3
star
39

console-print

Print special characters to the console, in Elm
Elm
3
star
40

ziplist

DEPRECATED in favor of rtfeldman/selectlist (better name!)
Elm
3
star
41

path

Elm
2
star
42

operation-pterodactyl

🦉
Elm
2
star
43

elm-css-util

Utility functions shared by elm-css and elm-css-helpers
Elm
2
star
44

elm-dropbox

Elm API for integrating with Dropbox
JavaScript
2
star
45

legacy-elm-test

An implementation of the legacy ElmTest module for backwards compatibility.
Elm
2
star
46

openresty-postgres-example

RealWorld example backend using OpenResty, Postgres, and nothing else
JavaScript
1
star
47

binstall

JavaScript
1
star
48

sweetvalidation

CoffeeScript
1
star
49

promises-done-polyfill

Polyfills Promise.done()
JavaScript
1
star