Cannot run tests from specified paths using alias

I want to run tests from a specific folder that is not part of the default test path.

I can do this easily running from console:

mix test lib/checks/**/*_test.exs

However when I define an alias, for some reason it is unable to find the folder:

"test.checks": ["test lib/checks/**/*_test.exs"],

Paths given to “mix test” did not match any directory/file: lib/checks/**/*_test.exs

From what I understand there is some issue with the relative path, however it is totally unclear why the console command works and the alias doesn’t. Any idea on why this is happening?

Not sure this is exactly what you’re running into, but I’ve had to put stuff like this in mix.exs:

def project do
      elixirc_paths: elixirc_paths(Mix.env()),

defp elixirc_paths(:test), do: elixirc_paths() ++ ["test/support"]
defp elixirc_paths(:dev), do: elixirc_paths() ++ ["dev_support"]
defp elixirc_paths(_), do: elixirc_paths()
defp elixirc_paths(), do: ["lib"]

My recollection is that I’ve gotten errors like you’re reporting when I didn’t get the elixirc_paths correct.

1 Like

I run the default setup from a phoenix generated project:

  # Specifies which paths to compile per environment.
  defp elixirc_paths(:test), do: ["lib", "test/support"]
  defp elixirc_paths(_), do: ["lib"]

It seems these paths are only required for the setup part, otherwise the .exs files are compiled on the fly when tests are called.

After reading once more the documentation, it seems that the mix test expects a path and not a pattern, because after changing the configuration to:

"test.checks": ["test lib/checks"],

It seems to work as expected.

It would be great to know if this is a bug though, because the behavior seems incosistent.

1 Like