mix_test_interactive icon indicating copy to clipboard operation
mix_test_interactive copied to clipboard

feat: Support before_task and after_task

Open jfpedroza opened this issue 1 year ago • 4 comments

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.

jfpedroza avatar Nov 20 '22 07:11 jfpedroza

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

randycoulman avatar Nov 21 '22 18:11 randycoulman

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 avatar Nov 21 '22 19:11 jfpedroza

@jfpedroza Would #63 be an adequate solution to the problem you're solving with this PR?

randycoulman avatar Nov 29 '22 00:11 randycoulman

Yes, that would be a good solution.

jfpedroza avatar Nov 29 '22 00:11 jfpedroza