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
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
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.







