Packages
mneme
0.9.4
0.10.2
0.10.1
0.10.0
0.9.4
0.9.3
0.9.2
0.9.1
0.9.0
0.9.0-alpha.1
0.9.0-alpha.0
0.8.2
0.8.1
0.8.0
0.7.0
0.6.1
0.6.0
0.5.1
0.5.0
0.4.3
0.4.2
0.4.1
0.4.0
0.3.5
0.3.4
0.3.3
0.3.2
0.3.1
0.3.0
0.3.0-rc.1
0.3.0-rc.0
0.2.7
0.2.6
0.2.5
0.2.4
0.2.3
0.2.2
0.2.1
0.2.0
0.1.6
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
0.0.5
0.0.4
0.0.3
0.0.2
0.0.1
Snapshot testing tool using familiar assertions
Current section
Files
Jump to
Current section
Files
lib/mix/tasks/mneme.watch.ex
defmodule Mix.Tasks.Mneme.Watch do
@shortdoc "Run tests when files change"
@moduledoc """
Runs the tests for a project when source files change.
This task is similar to [`mix test.watch`](https://hex.pm/packages/mix_test_watch),
but updated to work with Mneme:
* interrupts Mneme prompts, saving already-accepted changes
* doesn't re-trigger when test files are updated by Mneme
## Setup
To ensure `mix mneme.watch` runs in the test environment, add a
`:preferred_cli_env` entry in `mix.exs`:
def project do
[
...
preferred_cli_env: [
"mneme.watch": :test
],
...
]
end
## Command line options
* `--exit-on-success` - stops the test watcher the first time the
test suite passes.
All other CLI arguments are passed to `mix test`, which runs under the
hood.
## The --stale option
The `--stale` command line option is especially useful. Run by itself,
`mix mneme.watch` will run all of your tests when any source file or
test is saved. When used with `--stale`, only tests that have gone
stale due to changes in `lib` will be re-run, greatly speeding up most
test runs.
For more information, see the `mix test` documentation for
[the `--stale` option](https://hexdocs.pm/mix/Mix.Tasks.Test.html#module-the-stale-option).
## Examples
```sh
$ mix mneme.watch --only some_tag
# runs tests tagged with `some_tag: true`
$ mix mneme.watch test/my_app/my_test.exs
# runs tests in the given file
$ mix mneme.watch --stale
# runs stale tests
```
"""
use Mix.Task
@doc false
@impl Mix.Task
@spec run([String.t()]) :: no_return()
def run(args) do
Mix.env(:test)
children = [
{Mneme.Watch.TestRunner, cli_args: args}
]
Supervisor.start_link(children, strategy: :one_for_one)
:timer.sleep(:infinity)
end
end