diff --git a/test/channel_test.exs b/test/channel_test.exs index e123bf2..a13fa6c 100644 --- a/test/channel_test.exs +++ b/test/channel_test.exs @@ -108,33 +108,37 @@ defmodule Phoenix.LiveReloader.ChannelTest do end @endpoint MyApp.LogEndpoint - test "sends logs for web console only when enabled" do - System.delete_env("PLUG_EDITOR") - - update_live_reload_env(@endpoint, fn conf -> - Keyword.drop(conf, [:web_console_logger]) - end) + # web console logger relies on Logger.default_formatter/0 + # which is only available since Elixir v1.15 + if Version.match?(System.version(), ">= 1.15.0") do + test "sends logs for web console only when enabled" do + System.delete_env("PLUG_EDITOR") + + update_live_reload_env(@endpoint, fn conf -> + Keyword.drop(conf, [:web_console_logger]) + end) - {:ok, info, _socket} = - LiveReloader.Socket |> socket() |> subscribe_and_join(Channel, "phoenix:live_reload", %{}) + {:ok, info, _socket} = + LiveReloader.Socket |> socket() |> subscribe_and_join(Channel, "phoenix:live_reload", %{}) - assert info == %{} - Logger.info("hello") + assert info == %{} + Logger.info("hello") - refute_receive _ + refute_receive _ - update_live_reload_env(@endpoint, fn conf -> - Keyword.merge(conf, web_console_logger: true) - end) + update_live_reload_env(@endpoint, fn conf -> + Keyword.merge(conf, web_console_logger: true) + end) - {:ok, info, _socket} = - LiveReloader.Socket |> socket() |> subscribe_and_join(Channel, "phoenix:live_reload", %{}) + {:ok, info, _socket} = + LiveReloader.Socket |> socket() |> subscribe_and_join(Channel, "phoenix:live_reload", %{}) - assert info == %{} + assert info == %{} - Logger.info("hello again") - assert_receive %Phoenix.Socket.Message{event: "log", payload: %{msg: msg, level: "info"}} - assert msg =~ "hello again" + Logger.info("hello again") + assert_receive %Phoenix.Socket.Message{event: "log", payload: %{msg: msg, level: "info"}} + assert msg =~ "hello again" + end end test "sends editor_url and relative_path only when configurd" do diff --git a/test/live_reloader_test.exs b/test/live_reloader_test.exs index f76655a..d1a6bfd 100644 --- a/test/live_reloader_test.exs +++ b/test/live_reloader_test.exs @@ -141,12 +141,12 @@ defmodule Phoenix.LiveReloaderTest do |> Phoenix.LiveReloader.call(opts) |> send_resp(200, [ "", - '"], "

Phoenix

", "', + ~c"dy>", "" ]) @@ -161,7 +161,7 @@ defmodule Phoenix.LiveReloaderTest do |> Phoenix.LiveReloader.call([]) assert to_string(conn.resp_body) =~ - ~s[var targetWindow = "parent";\n] + ~s[var targetWindow = "parent";\n] end test "wrong window target defaults to top" do @@ -171,6 +171,6 @@ defmodule Phoenix.LiveReloaderTest do |> Phoenix.LiveReloader.call([]) assert to_string(conn.resp_body) =~ - ~s[var targetWindow = "top";\n] + ~s[var targetWindow = "top";\n] end end diff --git a/test/test_helper.exs b/test/test_helper.exs index 218de51..af3d053 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -34,14 +34,14 @@ Application.put_env(:phoenix_live_reload, MyApp.EndpointConfig, Application.put_env(:phoenix_live_reload, MyApp.EndpointParentWindow, pubsub_server: MyApp.PubSub, live_reload: [ - target_window: :parent, + target_window: :parent ] ) Application.put_env(:phoenix_live_reload, MyApp.EndpointWrongWindow, pubsub_server: MyApp.PubSub, live_reload: [ - target_window: "other", + target_window: "other" ] ) @@ -54,7 +54,7 @@ Application.put_env(:phoenix_live_reload, MyApp.ReloadEndpoint, ~r"priv/gettext/.*(po)$", ~r{web/views/.*(ex)$}, ~r{web/templates/.*(eex)$} - ], + ], notify: [ live_view: [ ~r{web/components.ex$}, @@ -64,9 +64,7 @@ Application.put_env(:phoenix_live_reload, MyApp.ReloadEndpoint, ] ) -Application.put_env(:phoenix_live_reload, MyApp.LogEndpoint, - pubsub_server: MyApp.PubSub -) +Application.put_env(:phoenix_live_reload, MyApp.LogEndpoint, pubsub_server: MyApp.PubSub) defmodule MyApp.Endpoint do use Phoenix.Endpoint, otp_app: :phoenix_live_reload