• Stars
    star
    867
  • Rank 50,444 (Top 2 %)
  • Language
    Elixir
  • License
    Other
  • Created about 9 years ago
  • Updated 8 months ago

Reviews

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

Repository Details

🎠 Because TDD is awesome

mix test.watch

Build Status Module Version Hex Docs Total Download License Last Updated

Automatically run your Elixir project's tests each time you save a file.

Because Test-driven development (TDD) is awesome.

Usage

Add it to your dependencies:

For Elixir 1.4 onwards:

# mix.exs
def deps do
  [
    {:mix_test_watch, "~> 1.0", only: [:dev, :test], runtime: false}
  ]
end

For Elixir 1.3 and earlier:

# mix.exs
def deps do
  [
    {:mix_test_watch, "~> 1.0", only: [:dev, :test]}
  ]
end

Optionally, add preferred_cli_env: ["test.watch": :test] for running mix test.watch in :test env by default. It prevents the task from running :dev env config scripts.

# mix.exs
def project do
  [
    ...
    preferred_cli_env: [
      "test.watch": :test
    ],
    ...
  ]
end

Run the mix task:

mix test.watch

Start hacking :)

Running Additional Mix Tasks

Through the mix config it is possible to run other mix tasks as well as the test task. For example, if I wished to run the Credo code analysis tool after my tests I would do so like this.

# config/config.exs
use Mix.Config

if Mix.env == :dev do
  config :mix_test_watch,
    tasks: [
      "test",
      "credo",
    ]
end

Tasks are run in the order they appear in the list, and the progression will stop if any command returns a non-zero exit code.

All tasks are run with MIX_ENV set to test.

Passing Arguments To Tasks

Any command line arguments passed to the test.watch task will be passed through to the tasks being run. If I only want to run the tests from one file every time I save a file I could do so with this command:

mix test.watch test/file/to_test.exs

Note that if you have configured more than one task to be run these arguments will be passed to all the tasks run, not just the test command.

Running tests of modules that changed

Elixir 1.3 introduced --stale option that will run only those test files which reference modules that have changed since the last run. You can pass it to test.watch:

mix test.watch --stale

Clearing The Console Before Each Run

If you want mix test.watch to clear the console before each run, you can enable this option in your config/dev.exs as follows:

# config/config.exs
use Mix.Config

if Mix.env == :dev do
  config :mix_test_watch,
    clear: true
end

Excluding files or directories

To ignore changes from specific files or directories just add exclude: regexp patterns to your config in config/config.exs:

# config/config.exs
use Mix.Config

if Mix.env == :dev do
  config :mix_test_watch,
    exclude: [~r/db_migration\/.*/,
              ~r/useless_.*\.exs/]
end

The default is exclude: [~r/\.#/, ~r{priv/repo/migrations}].

Watching files with other extensions

To watch files with extensions other than the default (.erl, .ex, .exs, .eex, .leex, .heex, .xrl, .yrl, .hrl) add them to extra_extensions: in your config:

# config/config.exs
use Mix.Config

if Mix.env == :dev do
  config :mix_test_watch,
    extra_extensions: [".rs"]
end

Compatibility Notes

On Linux you may need to install inotify-tools.

Desktop Notifications

You can enable desktop notifications with ex_unit_notifier.

Alternatives

mix_test_interactive is based on mix test.watch but adds an interactive mode that allows you to dynamically change which tests to run.

Copyright and Licence

mix test.watch

Copyright Β© 2015 Louis Pilfold

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

dogma

πŸ” A code style linter for Elixir
Elixir
472
star
2

exfmt

🌸 An opinionated Elixir source code formatter
Elixir
439
star
3

sonic-pi-tool

🎻 Controlling Sonic Pi from the command line
Rust
200
star
4

thoas

A blazing fast JSON parser and generator in pure Erlang.
Erlang
130
star
5

rustexp

A Rust regular expression editor and tester that runs entirely within the browser!
Rust
109
star
6

elixre

πŸ¦‘ An Elixir regular expression editor & tester, with Elm
Elm
101
star
7

icalendar

πŸ—“οΈ A small library for reading and writing ICalendar files.
Elixir
94
star
8

yesql

An Elixir library for using SQL.
Elixir
76
star
9

purescript-aws-lambda-express

PureScript
22
star
10

wisp

Gleam
20
star
11

sqlight

πŸ’‘ Use SQLite from Gleam!
Gleam
19
star
12

clint

🏚️ Nothing to see here.
Elixir
19
star
13

learning

Elixir
16
star
14

total

Basic exhaustiveness checking of unions in Elixir
Elixir
15
star
15

puter

Setting up a computer is annoying so let's automate it.
Ruby
14
star
16

soup

A simple interpreted language written in Elixir
Elixir
14
star
17

plug-redirect

A plug builder for redirecting requests.
Elixir
13
star
18

temporary-env

A tool for managing application environment state within tests.
Elixir
11
star
19

gleeunit

Gleam bindings for the Erlang EUnit test framework
Erlang
11
star
20

gleam-cloudflare-worker

JavaScript
10
star
21

nerf

Gleam bindings to gun, the Erlang HTTP/1.1, HTTP/2 and Websocket client
Gleam
9
star
22

generative-elm

Exploring Matt Pearson's "Generative Art" book, with Elm!
Elm
9
star
23

exercism

Because problems are fun.
Elixir
9
star
24

erlcaml

Erlang
8
star
25

gleam_sendgrid

A client for the SendGrid transactional email API
Gleam
8
star
26

tetromino

A little game of Tetris!
Rust
7
star
27

ecoji

Base64 is so 1999, isn't there something better?
Rust
6
star
28

linux-audio-interface-compatibility

6
star
29

elm-hearts

Inspired by the 1998 intro of the Powerpuff Girls <3
Elm
6
star
30

action

Gleam
5
star
31

lpil

Code monkey monorepo trinkets
Elixir
5
star
32

glance

Gleam
5
star
33

latex-templates

Because words are hard, and MS Word is terrible
TeX
4
star
34

elixir-aws-lambda

JavaScript
4
star
35

advent-of-code

Rust
4
star
36

dotfiles

Magic!
Shell
4
star
37

epgsql

Rust
4
star
38

htmb

Gleam
4
star
39

decksterity

A thingy for DJ me
Rust
4
star
40

gh-counts

How many Gleam projects are there?
Erlang
4
star
41

antigone

Argon2 password hashing for Gleam.
Gleam
4
star
42

cymbal

Build YAML in Gleam!
Gleam
4
star
43

purescript-format

Haskell
3
star
44

serverless-static-site

JavaScript
3
star
45

beam-lisp

Erlang
3
star
46

talk-slides

https://lpil.github.io/talk-slides/
HTML
3
star
47

osc

Because I want to learn about OSC and handling binaries in Elixir.
Elixir
3
star
48

stepper

A little JS step sequencer
JavaScript
3
star
49

formal

Gleam
3
star
50

justin

Gleam
3
star
51

exception

Gleam
2
star
52

llvm

Louis' Little Virtual Machine
Rust
2
star
53

phoenix-webpack-example

CSS
2
star
54

rust-stepper

Rust
2
star
55

kent-erlang-mooc

Erlang
2
star
56

kalimba-tabs

Elm
2
star
57

crisp

A Rusty Lisp
Rust
2
star
58

archive

Elixir
2
star
59

99-bottles-of-oop

Ruby
2
star
60

logging

Erlang
2
star
61

glue

🩹 Generate functions from your Gleam code!
Gleam
2
star
62

xcss-crystal

Abandoned, see the README
Crystal
2
star
63

zeptomail

A client for the Zeptomail transactional email API
Gleam
2
star
64

life

Conway's game of life in various languages.
Rust
2
star
65

palette

A useless library that does stuff the standard library does better.
Elixir
2
star
66

gleam-elixir-london-preview

Rust
1
star
67

waive-website

HTML
1
star
68

ka-li-da-scope

JavaScript
1
star
69

joy

Gleam
1
star
70

reddit-css

Stylesheets for various subreddits -
CSS
1
star
71

roman-numerals

Convert numbers to Roman numerals and back.
Elixir
1
star
72

gleam-test-ci-project

Erlang
1
star
73

nice-button

JavaScript
1
star
74

i3-conf

My 'puter. Tiling is fun.
Perl
1
star
75

lans-syn

Because the ANS synth is cool.
Clojure
1
star
76

natter

Elixir
1
star
77

photobank

An app for sharing photos!
Elixir
1
star
78

pushover-error-logger

An Erlang/OTP logger handler that sends error logs to Pushover
Erlang
1
star
79

elm-against-humanity

https://lpil.uk/elm-against-humanity
Elm
1
star
80

a-blog

CSS
1
star
81

learn-you-some-elixir

CSS
1
star
82

find_my_primes

Elixir
1
star
83

jot

Gleam
1
star
84

access

Clojure
1
star
85

openbox-conf

My openbox desktop config
Shell
1
star
86

my-first-code

HTML
1
star
87

purescript-datastore

PureScript
1
star
88

elixir-jot

Slightly more fun than HTML
Elixir
1
star
89

beecrypt

🐝 Buzzing Gleam bindings to the Erlang bcrypt hashing library
Gleam
1
star
90

vim2hs-flexible

Vim Script
1
star
91

prismic_ecto

An Ecto adapter for the Prismic.io CMS
Elixir
1
star
92

ex-unit-pride

Run your tests with pride.
Elixir
1
star
93

javascript-dom-parser

Gleam
1
star
94

spinner

Gleam
1
star
95

cheep

Because graphical programming is no fun.
Ruby
1
star
96

envoy

πŸ“‚ A zero dependency cross platform Gleam package for reading environment variables
Gleam
1
star
97

cgi

Gleam
1
star
98

youid

Gleam
1
star