You can probably build something over mix test --listen-on-stdin.
–listen-on-stdin - runs tests, and then listens on stdin. Receiving a newline will result in the tests being run again. Very useful when combined with --stale and external commands which produce output on stdout upon file system modification.
watchexec -c -p -e 'ex,exs,lock' -- mix test [--stale]
Here’s an Elixir-specific snippet from my dotfiles that I’m not sure of the provenance of, and that seems kind of overwrought, but I think it might have been derived from a José/Plataformatec tweet or something?
fswatch --latency=0.01 --one-per-batch lib/ test/ | MIX_ENV=test mix do test --stale, run --no-halt -e "IO.gets(:stdio, ''); IO.puts 'Restarting...'; :init.restart()"
And a variant for umbrella apps:
fswatch --latency=0.01 --one-per-batch apps/ config/ mix.exs mix.lock | MIX_ENV=test mix do test --stale, run --no-halt -e "IO.gets(:stdio, ''); IO.puts 'Restarting...'; :init.restart()"
Sweet. I’m actually back to the drawing board, because mix-test isn’t working for me in a Docker container with a Bind mount. I may need a tool that’s configureable enough to do polling.