johnhu

johnhu

Hi all,

I am a newbie to Elixir. I try to create an alias for running another group of tests which has its owned environment. It can be run with MIX_ENV specified. May I set the env at alias to have a simpler command? Like api_test:

defp aliases do
  [
    "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
    "ecto.reset": ["ecto.drop", "ecto.setup"],
    "test": ["ecto.create --quiet", "ecto.migrate", "test"],
    "api_test": "test --only api_test:true"
  ]
end

Showing Posts 1 to 10

NobbZ

NobbZ

defp aliases do
  [
    …,
    "api_test": &api_test/1
  ]
end

defp api_test(_) do
  Mix.env(:test) # or whatever env you need
  MixTask.run("test" ["--only", "api_test:true"])
end

This is from memory though, can’t test it right now.

johnhu

johnhu OP

Wow.. This is a great idea.. I will do that.

It failed. It tries to load the live reload server

** (UndefinedFunctionError) function Phoenix.LiveReloader.init/1 is undefined (module 
Phoenix.LiveReloader is not available)
    Phoenix.LiveReloader.init([])
    (plug) lib/plug/builder.ex:302: Plug.Builder.init_module_plug/4
    (plug) lib/plug/builder.ex:286: anonymous fn/5 in Plug.Builder.compile/3
    (elixir) lib/enum.ex:1899: Enum."-reduce/3-lists^foldl/2-0-"/3
    (plug) lib/plug/builder.ex:284: Plug.Builder.compile/3
    (plug) expanding macro: Plug.Builder.__before_compile__/1
LostKobrakai

LostKobrakai

there’s also this in mix.exs:

def project do
    [
      …,
      preferred_cli_env: [
        coveralls: :test,
        "coveralls.detail": :test,
        "coveralls.post": :test,
        "coveralls.html": :test,
        "test.reset": :test,
        "test.integration": :test
      ]
    ]
  end
johnhu

johnhu OP

After adding the preferred_cli_env, the previous error is gone. But it still not run the test because:
** (Mix) “mix test” is running on environment “api_test”. If you are running tests along another task, please set MIX_ENV explicitly

It looks like I have to use MIX_ENV…

NobbZ

NobbZ

I think you just did the :preferred_cli_env wrong. Can you please show how you set it up?

johnhu

johnhu OP

I use:

def project do
[
  ...
  preferred_cli_env: [
    "api_test": :api_test
  ]
]

end

NobbZ

NobbZ

Since you want to run :api_test in the MIX_ENV=test this needs to be api_test: :test.

johnhu

johnhu OP

no.. I want to run :api_test with the MIX_ENV=api_test… It does run it with api_test. But the mix test gives me the warning:

** (Mix) “mix test” is running on environment “api_test”. If you are running tests along another task, please set MIX_ENV explicitly

NobbZ

NobbZ

You are not allowed to call mix test in any other environment than :test, if you want to do it despite all warnings, then you have to set MIX_ENV explicitely. This is kind of saying “Yes, I know what I am doing and I am really sure I want to do this with all of its implcations and possible side effects which in worst case might destroy the world”.

If you really wan’t to use mix test in another environment, then there is no other way than to use the environment variable.

johnhu

johnhu OP

Thanks for the information…

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
ryanwinchester
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted” Version...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews