Skip to content

Commit

Permalink
add liveviews reload test
Browse files Browse the repository at this point in the history
  • Loading branch information
bemesa21 committed Nov 11, 2022
1 parent 779eb20 commit 494412e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
9 changes: 9 additions & 0 deletions test/channel_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,13 @@ defmodule Phoenix.LiveReloader.ChannelTest do
send(socket.channel_pid, file_event('a/b/c/lib/live_web/views/user_view.ex', :created))
assert_push "assets_change", %{asset_type: "ex"}
end

@endpoint MyApp.ReloadEndpoint
test "sends notification for liveviews" do
{:ok, _, socket} =
LiveReloader.Socket |> socket() |> subscribe_and_join(Channel, "phoenix:live_reload", %{})
socket.endpoint.subscribe("liveview")
send(socket.channel_pid, file_event("lib/live_web/live/user_live.ex", :created))
assert_receive {:phoenix_live_reload, :liveview, "lib/live_web/live/user_live.ex"}
end
end
26 changes: 26 additions & 0 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,37 @@ Application.put_env(:phoenix_live_reload, MyApp.EndpointWrongWindow,
]
)

Application.put_env(:phoenix_live_reload, MyApp.ReloadEndpoint,
pubsub_server: MyApp.PubSub,
live_reload: [
url: "ws://localhost:4000",
patterns: [
~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$",
~r"priv/gettext/.*(po)$",
~r{web/views/.*(ex)$},
~r{web/templates/.*(eex)$}
],
notify: [
liveview: [
~r{web/components.ex$},
~r{web/live/.*(ex)$}
]
]
]
)

defmodule MyApp.Endpoint do
use Phoenix.Endpoint, otp_app: :phoenix_live_reload

socket "/socket", Phoenix.LiveReloader.Socket, websocket: true, longpoll: true
end

defmodule MyApp.ReloadEndpoint do
use Phoenix.Endpoint, otp_app: :phoenix_live_reload

socket "/socket", Phoenix.LiveReloader.Socket, websocket: true, longpoll: true
end

defmodule MyApp.EndpointScript do
use Phoenix.Endpoint, otp_app: :phoenix_live_reload
end
Expand All @@ -74,6 +99,7 @@ children = [
MyApp.EndpointConfig,
MyApp.EndpointParentWindow,
MyApp.EndpointWrongWindow,
MyApp.ReloadEndpoint
]

Supervisor.start_link(children, strategy: :one_for_one)
Expand Down

0 comments on commit 494412e

Please sign in to comment.