3

I am experiencing an issue where my test/support past is not getting compiled:

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

I decided to check the environment when running mix test and to my surprise its :dev

pry(1)> Mix.env()
:dev

Am I missing some additional configuration?

mix file:

defmodule ProjectWeb.MixProject do
  use Mix.Project

  def project do
    [
      app: :project,
      version: "0.1.0",
      build_path: "../../_build",
      config_path: "../../config/config.exs",
      deps_path: "../../deps",
      lockfile: "../../mix.lock",
      elixirc_paths: elixirc_paths(Mix.env),
      elixir: "~> 1.6",
      start_permanent: Mix.env() == :prod,
      deps: deps()
    ]
  end

  # Run "mix help compile.app" to learn about applications.
  def application do
    [
      extra_applications: [:logger],
      mod: {ProjectWeb.Application, []}
    ]
  end

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

  # Run "mix help deps" to learn about dependencies.
  defp deps do
    [
      {:phoenix, "~> 1.3.3"},
      {:pre_plug, "~> 1.0"},
      {:cowboy, "~> 1.0"},
      {:phoenix_live_reload, "~> 1.1", only: :dev}
    ]
  end

end
lapinkoira
  • 8,320
  • 9
  • 51
  • 94
  • It is incredibly hard to tell whether you are missing some _additional_ configuration when you have not shared your _existing_ config. `mix test` should set an environment to `:test` in a default configuration. – Aleksei Matiushkin Aug 13 '18 at 07:52
  • There is my current mix file, notice I modified the defp elixirc_paths(:dev), do: ["lib", "test/support"] to make it work – lapinkoira Aug 13 '18 at 08:28
  • I have also a config/test.exs file with just use Mix.Config – lapinkoira Aug 13 '18 at 08:34
  • The file looks ok. Could you try to `IO.puts Mix.env` from your `config.exs` instead of dealing with `pry`. Honestly, I am not sure if either `iex` or `pry` does not set the environment on it’s own. – Aleksei Matiushkin Aug 13 '18 at 08:36
  • 2
    well I found the issue, if you have set the env variable MIX_ENV=dev it will still be :dev even using mix test – lapinkoira Aug 13 '18 at 08:45
  • 1
    Of course it will; it’s intended behaviour, allowing you to preserve the better control of the environment, rather than implied by `mix` itself. – Aleksei Matiushkin Aug 13 '18 at 09:56

0 Answers0