Fl4m3Ph03n1x

Fl4m3Ph03n1x

How to make `mix test` work in umbrella root and inside child app?

Background

I have an umbrella project with several apps. One of its child applications needs to read a file before it starts. If it cannot find the file, it crashes.

This means that if I want to run mix test, the child application has to find said file.

Problem

The problem here is that depending where I run mix test, the command will either fail or succeed.

If I run mix test inside the child’s application folder, the command will fail because the file it needs is not there.

If I runt he mix test at the root of my umbrella app, then the command succeeds because it can find said file.

This means that I am cannot run mix test while inside the child application folder, which is quite cumbersome. Sometimes I will open only that 1 application and do some changes there, other times I open the full umbrella project and make changes in multiple places.

Question

Is it possible to have mix test work both at the root of the umbrella project and inside its child app ?

This is the folder structure I have:

├───config
|     ├───prod.exs
|     ├───dev.exs
|     └───test.exs
├───assets
|    └─── products.json
├───apps
│   ├───manager
|   └─── ... 
│   ├───store
│   │   ├───lib
│   │   │   └───store
│   │   └───test
│   │       └───...

I have the following in my config/test.exs (root folder of umbrella project):

import Config

config :store,
  products: "assets/products.json",

I guess I could simply duplicate the products.json file everywhere in every app that needs to run a test using products, but I find this duplication rather unwise.

What is the preferred solution to this?

Marked As Solved

Fl4m3Ph03n1x

Fl4m3Ph03n1x

Correction: I should be using Path.expand (Path — Elixir v1.13.4) instead, which will result in:

Path.expand("#{__DIR__}/../assets/products.json")

>  PATH IS: ["c:/Users/my_app/assets/products.json"]

Also Liked

LostKobrakai

LostKobrakai

Use an absolute path or a relative one, which is relative to some well known location and not relative to your working directory. E.g. consider using __DIR__ to use a relative path to where the config file lives instead of having it be relative to the cwd.

Where Next?

Popular in Questions Top

jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
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
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New

Other popular topics Top

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
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement