wallaby
wallaby copied to clipboard
Check if ExUnit is available before setting up after suite calls
I have a use case using Wallaby to control the browser outside the test suite and this code seems to be the only issue preventing that. It auto tries to call ExUnit when it's not available, maybe only execute ExUnit hooks if it's available.
Open to solving this another way if there are recommendations.
Thanks for the patch, I know this has been bothering some people for a while.
Another approach might be to require the user to set something up in their test_helper.exs, which will configure the after_suite callback.
Something like
# test/test_helper.exs
ExUnit.after_suite(&Wallaby.cleanup!/1)
ExUnit.start()
# lib/wallaby.ex
def cleanup! do
Wallaby.SessionStore.delete_all()
end
# lib/wallaby/session_store.ex
def delete_all(store \\ __MODULE__) do
GenServer.call(store, :delete_all)
end
def handle_call(:delete_all, _, %{ets_table: tid}) do
try do
:ets.tab2list(tid)
|> Enum.each(&delete_sessions/1)
rescue
_ -> nil
end
end
I think this puts more burden on the user of the library, which I try to avoid as Wallaby already has a ton of first time setup, but would avoid putting calls to ExUnit in the Wallaby codebase, which would avoid compiler warnings when running it in mix releases.