Server: true in test.exs doesn't run the test server

I have a Liveview page that forwards 3rd party webhook to my local machine and I want to test this functionality.

test "forward webhooks?" do
  {:ok, lv, html} = live(conn, path())
  
  target_domain = MyAppWeb.Endpoint.url()
  # This returns http://localhost:4003

   assert webhook_flash =
               lv
               |> element("#flash-info-0")
               |> render()
end

If it is successful, lv should have #flash-info-0 flash message. But I can’t foward a webhook to target domain.
But, If I run mix phx.server then forward to http://localhost:4000 it works.

So I updated test.exs file to run a test server

config :my_app, MyAppWeb.Endpoint,
  url: [host: "localhost", port: 4003],
  secret_key_base: "secret"
  server: true

But still failed to forward.

What am I doing wrong?

I don’t think the test tries to start your phoenix endpoint, only the repo.
Maybe start it yourself, :ok = Application.ensure_started(MyAppWeb.Endpoint)

LiveView tests are not complete integration tests all the way up to the http connection. They talk directly to the endpoint, so if the server is running or not doesn’t make a difference. The URL is there in case your own code uses it (and you can change it for testing).

1 Like