mix_test_interactive
mix_test_interactive copied to clipboard
feat: Support before_task and after_task
This adds support for before_task
and after_task
config options.
It allows you to run tasks before and after the actual test task.
Usage would be like:
config :mix_test_interactive, :before_task, [
["run", "-e", ~s|IO.puts("RAN BEFORE")|],
["my_task_before"]
]
config :mix_test_interactive, :after_task, [
["my_task_after", "some_arg"],
]
I would like to know if you have any feedback before adding tests and updating the docs.
Thanks for this contribution!
Can you give me a better sense of the use case for this feature? What kinds of things would you like to run before or after every single test run?
Could this same goal by achieved by using aliases in mix.exs
? For example, a standard Phoenix app will generate an alias for the test
task, and this works fine as-is with mix test.interactive
.
defp aliases do
[
test: ["ecto.create --quiet", "ecto.migrate", "test"]
]
end
I am integrating mix_test_interactive
with a testing plugin for Neovim (Neotest).
I have it working with mix test
by adding a couple of files dynamically (a formatter, for example), using elixir -r formatter.ex -S mix test
.
For mix_test_interactive
, it doesn't work to simply replace the task because the files are not passed to mix test
(similar to the --sname
issue).
For now, I have it solved by having a copy of the PortRunner
that adds the needed files, but thought making it generic was a good idea.
The files could also be in an Elixir library like this one, but I don't think it is necessary to install another dependency in the project only for testing with Neovim.
@jfpedroza Would #63 be an adequate solution to the problem you're solving with this PR?
Yes, that would be a good solution.
@jfpedroza At long last, I've implemented the command
configuration option and released it as v3.1.0. Please try it out and let me know if it works for you (if you're still interested).
I'm going to close this Draft PR in the mean time. Feel free to re-open if the new option doesn't meet your needs. Thanks!