Replies: 3 comments 5 replies
-
I don't believe the live session on mount hook is activated for normal controller routes. You need to add the sandbox plug to your endpoint as indicated in the docs. I'm on my phone right now but this is the snippet for quick viewing, you can find the rest in the readme. # lib/your_app_web/endpoint.ex
defmodule YourAppWeb.Endpoint do
use Phoenix.Endpoint, otp_app: :your_app
if sandbox = Application.compile_env(:your_app, :sandbox, false) do
plug Phoenix.Ecto.SQL.Sandbox, sandbox: sandbox
end
# ...
socket("/live", Phoenix.LiveView.Socket,
websocket: [connect_info: [:user_agent, session: @session_options]]
)
|
Beta Was this translation helpful? Give feedback.
-
Thank you so much for helping educate me on this :)
Thanks!! It looks like I have not, assuming you mean this: # config/support/sandbox.ex
defmodule YourApp.Sandbox do
def allow(repo, owner_pid, child_pid) do
# Delegate to the Ecto sandbox
Ecto.Adapters.SQL.Sandbox.allow(repo, owner_pid, child_pid)
# Add custom process-sharing configuration
Mox.allow(MyMock, owner_pid, child_pid)
end
end The first time I added Wallaby, I was not using any shared resources that I was aware of, so I interpreted this as optional:
Clearly. now that Ive added LiveView and also want to run some async tests, this is not optional. Im going to add this to my app and re-test. |
Beta Was this translation helpful? Give feedback.
-
This did fix non LiveView tests that we failing to run async, they run async now. The final thing I dont understand is what to put in the commented area here: live_session :default, on_mount: MyAppElixir.Hooks.AllowEctoSandbox do
# ...
end Here is all of the code I have in this area of scope "/", MyAppElixirWeb do
pipe_through [:browser]
delete "/admins/log_out", AdminSessionController, :delete
live_session :default, on_mount: MyAppElixir.Hooks.AllowEctoSandbox do
# ...
end
live_session :current_admin,
on_mount: [{MyAppWeb.AdminAuth, :mount_current_admin}] do
live "/admins/confirm/:token", AdminConfirmationLive, :edit
live "/admins/confirm", AdminConfirmationInstructionsLive, :new
end
end The Can you help me understand what to do with the |
Beta Was this translation helpful? Give feedback.
-
My ultimate problem is that when I click on a
DELETE
route (to test user log-out), I get a huge wall of errors culminating in(DBConnection.OwnershipError)
, when I haveasync: true
for a Wallaby test. I believe this is due to my LiveView config for Wallaby. If I useasync: false
, this error goes away and my test passes as expected, though Id rather not have a random smattering of non async tests.I am also using Elixir for the first time in ~5 years, and have not followed Elixir or Phoenix developments in that time. My team does not believe acceptance testing is valuable, and I think a web application cannot be managed well over time without acceptance testing. Thus I need to sell my team on this "new" culture of testing, which is getting difficult for me given that Wallaby has been quite time consuming for me to get set up properly (much of this due to my lack of Elixir/Phoenix fundamentals).
The current state of the readme suggests the a configuration for LiveView in wallaby tests so that they can be async. I have the following config for my app:
And in my router, where I actually am somewhat clueless as to how to do this properly, esp with whatever is meant by the
# ...
in the README:I am essentially writing acceptance tests for
mix phx.gen.auth ...
. Its pretty much vanilla generated auth code.I do not believe the
Hooks
code is executing at all (for one, I cannot see theIO.inspect()
results).How can I know exactly how to implement this configuration, so that my acceptance tests can run async? For now I will keep this one "admin logout" test in its own file that has just one test to run async.
Is there something missing from my Phoenix knowledge that is assumed by the docs?
What exactly is expected to be between the
do .. end
in the docs regarding#...
? What does that comment represent?This is how its defined in the README:
And finally, does placing routes within this block have any effect on the actual app? That is, this seems like test specific code, how am I able to isolate the behavior just to tests if I need to use my "production" routes in this block?
Thanks for any help that can be provided, I want to convince the word that acceptance testing is absolutely fundamental to a web application's success.
Beta Was this translation helpful? Give feedback.
All reactions