File size: 793 Bytes
6778ee0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
defmodule Plausible.Test.Support.Sentry do
  @moduledoc """
  Helper for setting up Sentry test mode in ExUnit tests.

  Usage inside a `setup` callback:

      setup %{test_pid: test_pid} do
        Plausible.Test.Support.Sentry.setup(test_pid)
      end

  This enables Sentry's test mode, starts collecting reports owned by the
  test process, and restores the original config on exit.
  """

  def setup(test_pid) do
    Sentry.put_config(:test_mode, true)
    Sentry.put_config(:send_result, :sync)
    Sentry.put_config(:dedup_events, false)

    :ok = Sentry.Test.start_collecting(owner: test_pid)

    ExUnit.Callbacks.on_exit(fn ->
      Sentry.put_config(:test_mode, false)
      Sentry.put_config(:send_result, :none)
      Sentry.put_config(:dedup_events, true)
    end)
  end
end