phoenix_test icon indicating copy to clipboard operation
phoenix_test copied to clipboard

Dynamic endpoint

Open jpyamamoto opened this issue 6 months ago • 3 comments

Hello,

At my company we recently faced the challenge that we wanted to use this library for the tests of two different apps in the umbrella, each with a different endpoint.

This turned out to be unachievable with the current state of the library due to the endpoint configuration needing to be given at compile time.

In order to make it work, we had to hack into the library a way to retrieve the endpoint at runtime. We propose the following syntax:

config :phoenix_test,
  endpoints: %{
    opt_app1: MyApp1.Endpoint,
    otp_app2: MyApp2.Endpoint
    ...
  }

In order to make it work, the live and follow_redirect macros defined by Phoenix had to be replicated in the library as functions that invoke dispatch/5 instead of get/3, to manually pass the proper endpoint.

This MR preserves backwards compatibility as it will use the already established :phoenix_test, :endpoint config when endpoints isn't there.

Please, let me know if this would be a valuable contribution to the library and if so, if there are any changes I should make before this is merged.

jpyamamoto avatar Jul 04 '25 19:07 jpyamamoto

Modified the error messages, let me know if they're better this way.

jpyamamoto avatar Jul 07 '25 18:07 jpyamamoto

ok German - i would wait for your other PR to take shape to see whether this fix is even needed. I have created an issue in the mix_test_interactive repo also, to see whether there is any other way to handle this - mix test.interactive fails on a test that mix test passes using PhoenixTest · Issue #145 · randycoulman/mix_test_interactive

siraj-samsudeen avatar Sep 29 '25 09:09 siraj-samsudeen

@jpyamamoto is this something we still want to get into PhoenixTest?

Not trying to add pressure (I'm the first to know we all have other stuff to do). But wanted to check in.

I'd still like to get a couple of more things done (mentioned in previous comment) if we want to get this in:

Do you know if there's a way to for us to write an automated test within PhoenixTest's library so that we know (a) that this is working, and (b) that we don't introduce regressions?

Finally, could we update documentation so people know how to configure their apps if they have multiple endpoints?

germsvel avatar Oct 01 '25 09:10 germsvel