Fl4m3Ph03n1x

Fl4m3Ph03n1x

Run umbrella project tests sequencially

Background

I have an umbrella project with several apps.
Some of these apps have runtime libraries as dependencies, some apps depend on others and so on.

My objective is, when on the root level of the project, to run all the tests for all the child apps using mix test.

Problem

When on the root level, running mix test will run the tests of all child apps. However this happens in a parallel way, from what I can see.

This is a problem because some dependencies between child apps are shared. Consequently some apps succeed, and others fail, thus breaking my CI/CD pipeline.

This is not a problem at all if I run the tests for each child separately, but alas, I want to be able to use mix test from the root level.

What I tried

So, my initial approach was create an alias that replaces mix test with my own command:

defp aliases do
    [
      test: ["cmd --app app1 mix test --color", "cmd --app app2 mix test --color"]
    ]
  end

This will work and will execute the tests of the child apps sequentially.

Questions

However this solution is hard-coded and not very flexible. If tomorrow I remove an app, the command will break. If I add a new one, the command won’t run its tests unless I remember to edit it.

I wonder if there is a better way of doing this that would be:

  • flexible instead of hard-coded
  • run the tests sequentially instead of parallel

Marked As Solved

Fl4m3Ph03n1x

Fl4m3Ph03n1x

defp aliases do
  child_tests =
      Path.wildcard("apps/*")
      |> Enum.map(&String.replace(&1, "apps/", ""))
      |> Enum.map(fn app -> "cmd --app #{app} mix test --color" end)

    [test: child_tests]
end

This did the trick. Thanks :smiley:

Also Liked

LostKobrakai

LostKobrakai

So the proper solution would be removing any global state from your testsuites, which makes mix test fail as it does.

But also mix.exs is elixir – you can use code to define the alias:

test = 
  Mix.Project.apps_paths()
  |> Keyword.keys()
  |> Enum.map(fn app -> "cmd --app #{app} mix test --color" end)

[test: test]
LostKobrakai

LostKobrakai

Path.wildcard("apps/*) would likely do fine as well :sweat_smile:

Where Next?

Popular in Questions Top

New
Tee
can someone please explain to me how Enum.reduce works with maps
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Other popular topics Top

danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29377 241
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41539 114
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement