skwidbreth

skwidbreth

Mix - can I recompile a dependency for the test environment?

When I’m working on a mix app, I’ve noticed that changes that I make to code in my app’s dependencies are observable in the dev environment after recompiling the dep, but not in the test environment. Is this an intentional part of mix’s design? If so, is there a mix-based workaround?

Here’s an example scenario… I’m working on an app, doing some basic red-to-green testing. I’m having trouble debugging my app’s integration with one of its dependencies, and want to throw some IO.inspects into the dep to help me debug. I add the debug code, recompile the dependency, and run the tests again, but the code I’ve added has no effect. However, if I remove the directory at _build/test/lib/my_dep and run the tests again, the changes are present.

Steps to replicate:

  • get a dependency with mix deps.get my_dep
  • compile the dependency with mix deps.compile my_dep

At this point, a compiled version of the dependency will appear at my_app/_build/dev/lib/my_dep, but not at my_app/_build/test/lib/my_dep

  • I run tests with mix test - the compiled version of my_dep now appears at my_app/_build/test/lib/my_dep
  • I make a change to a file in my_app/deps/my_dep, compile the dep with mix deps.compile my_dep, and run the tests again

The change that I’ve made to the dependency is reflected in the _build/dev/ version, but not in the _build/test/ version - so if I run the tests again, the change does not take affect, nor is it observable if I start an iex session via MIX_ENV=test iex -S mix (though it is observable if I start iex in the dev environment).

From walking through this step-by-step, it’s become evident to me that deps are compiled differently for different environments . If there’s no other way around this, it’s not a big deal - I just have to run $ rm -rf _build/test/lib/my_dep when I make changes… but I’m interested in learning more about this aspect of mix’s design, and if there’s a way that I can recompile a dependency specifically for the test environment.

Marked As Solved

NobbZ

NobbZ

You are not supposed to make any changes in deps, if you really have to, then you need to recompile the deps manually for each environment, eg. MIX_ENV=test mix deps.compile.

Also Liked

axelson

axelson

Scenic Core Team

While developing you could also try changing the dependency to:

    {:my_dep, '~> 1.0.0', path: 'deps/my_dep'}

But in either case you have to be very careful to not overwrite any changes you make and I wouldn’t commit code that includes a path dep in deps. But I have found this technique useful for testing changes locally.

Where Next?

Popular in Questions Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
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
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
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
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call t...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
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
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
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

Other popular topics Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
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 41989 114
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52673 488
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement