Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if ExUnit is available before setting up after suite calls #718

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

agundy
Copy link

@agundy agundy commented Dec 8, 2022

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.

@mhanberg
Copy link
Member

mhanberg commented Dec 8, 2022

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.

@alinmarsh alinmarsh force-pushed the aaron-exunit-guards branch from be05a27 to 645ac43 Compare October 8, 2024 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants