randycoulman / mix_test_interactive

Interactive watch mode for Elixir's mix test. https://hexdocs.pm/mix_test_interactive/
MIT License
85 stars 12 forks source link

feat: Support before_task and after_task #62

Closed jfpedroza closed 1 month ago

jfpedroza commented 1 year ago

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.

randycoulman commented 1 year ago

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
jfpedroza commented 1 year ago

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.

randycoulman commented 1 year ago

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

jfpedroza commented 1 year ago

Yes, that would be a good solution.

randycoulman commented 1 month ago

@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!