Skip to content

Commit e417e46

Browse files
committed
Merge branch 'main' into 276-implement-displaying-event-handling-time
2 parents 3c1737a + 794c76d commit e417e46

31 files changed

Lines changed: 707 additions & 321 deletions

.github/workflows/elixir-ci.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,12 @@ jobs:
4949
- name: Compile project
5050
run: mix compile --warnings-as-errors
5151

52-
- name: Run tests
52+
- name: Run unit tests
5353
run: mix test
5454

55+
- name: Run e2e tests
56+
run: mix e2e
57+
5558
- name: Check prettier
5659
working-directory: ./assets
5760
run: npx prettier . --check

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ config :live_debugger,
8686
secret_key_base: <SECRET_KEY_BASE>, # Secret key used for LiveDebugger.Endpoint
8787
signing_salt: "your_signing_salt", # Signing salt used for LiveDebugger.Endpoint
8888
adapter: Bandit.PhoenixAdapter # Adapter used in LiveDebugger.Endpoint
89+
tracing_setup_delay: 0 # Time in ms after tracing will be initialized. Useful in case multi-nodes envs
8990
```
9091

9192
## Contributing

config/config.exs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,30 @@ if config_env() == :dev do
4747
]
4848
]
4949

50+
config :live_debugger, server: true
51+
5052
config :live_debugger, browser_features?: true
53+
config :live_debugger, experimental_features: :all
54+
end
55+
56+
if config_env() == :test do
57+
config :wallaby,
58+
driver: Wallaby.Chrome,
59+
otp_app: :live_debugger,
60+
chrome: [headless: true],
61+
js_logger: nil
62+
63+
config :live_debugger,
64+
server: true,
65+
port: 4008
66+
67+
# Print only warnings and errors during test
68+
config :logger, level: :warning
69+
70+
# Initialize plugs at runtime for faster test compilation
71+
config :phoenix, :plug_init_mode, :runtime
72+
73+
config :phoenix_live_view,
74+
# Enable helpful, but potentially expensive runtime checks
75+
enable_expensive_runtime_checks: true
5176
end

dev/endpoint.ex

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ defmodule LiveDebuggerDev.Endpoint do
2020
plug(Plug.Static, from: {:phoenix, "priv/static"}, at: "/assets/phoenix")
2121
plug(Plug.Static, from: {:phoenix_live_view, "priv/static"}, at: "/assets/phoenix_live_view")
2222

23-
socket("/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket)
23+
if Mix.env() == :dev do
24+
socket("/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket)
2425

25-
plug(Phoenix.LiveReloader)
26-
plug(Phoenix.CodeReloader)
26+
plug(Phoenix.LiveReloader)
27+
plug(Phoenix.CodeReloader)
28+
end
2729

2830
plug(Plug.Session, @session_options)
2931

dev/live_components/send.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ defmodule LiveDebuggerDev.LiveComponents.Send do
99
<.box title="Send [LiveComponent]" color="green">
1010
<div class="flex flex-col gap-2">
1111
<div class="flex items-center gap-1">
12-
<.button phx-click="send_message" phx-target={@myself} color="green">
12+
<.button id="send-button" phx-click="send_message" phx-target={@myself} color="green">
1313
Send
1414
</.button>
1515

dev/live_views/main.ex

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ defmodule LiveDebuggerDev.LiveViews.Main do
77
socket =
88
socket
99
|> assign(counter: 0)
10-
|> assign(slow_counter: 0)
11-
|> assign(very_slow_counter: 0)
10+
|> assign(counter_slow: 0)
11+
|> assign(counter_very_slow: 0)
1212
|> assign(datetime: nil)
1313
|> assign(name: random_name())
1414
|> assign(single_element_list: [%Phoenix.LiveComponent.CID{cid: 1}])
@@ -22,7 +22,7 @@ defmodule LiveDebuggerDev.LiveViews.Main do
2222
<.box title="Main [LiveView]" color="blue">
2323
<div class="flex flex-col gap-2">
2424
<div class="flex items-center gap-2">
25-
<.button phx-click="increment" color="blue">
25+
<.button id="increment-button" phx-click="increment" color="blue">
2626
Increment
2727
</.button>
2828
<span class="text-xl"><%= @counter %></span>
@@ -31,16 +31,16 @@ defmodule LiveDebuggerDev.LiveViews.Main do
3131
<.button phx-click="slow-increment" color="blue">
3232
Slow Increment
3333
</.button>
34-
<span class="text-xl"><%= @slow_counter %></span>
34+
<span class="text-xl"><%= @counter_slow %></span>
3535
</div>
3636
<div class="flex items-center gap-2">
3737
<.button phx-click="very-slow-increment" color="blue">
3838
Very Slow Increment
3939
</.button>
40-
<span class="text-xl"><%= @very_slow_counter %></span>
40+
<span class="text-xl"><%= @counter_very_slow %></span>
4141
</div>
4242
<div class="flex items-center gap-1">
43-
<.button phx-click="change_name" color="red">
43+
<.button id="update-button" phx-click="change_name" color="red">
4444
Update
4545
</.button>
4646
<div>
@@ -82,17 +82,17 @@ defmodule LiveDebuggerDev.LiveViews.Main do
8282
end
8383

8484
def handle_event("increment", _, socket) do
85-
{:noreply, assign(socket, :counter, socket.assigns.counter + 1)}
85+
{:noreply, update(socket, :counter, &(&1 + 1))}
8686
end
8787

8888
def handle_event("slow-increment", _, socket) do
8989
Process.sleep(400)
90-
{:noreply, assign(socket, :slow_counter, socket.assigns.slow_counter + 1)}
90+
{:noreply, update(socket, :counter_slow, &(&1 + 1))}
9191
end
9292

9393
def handle_event("very-slow-increment", _, socket) do
9494
Process.sleep(2500)
95-
{:noreply, assign(socket, :very_slow_counter, socket.assigns.very_slow_counter + 1)}
95+
{:noreply, update(socket, :counter_very_slow, &(&1 + 1))}
9696
end
9797

9898
def handle_event("change_name", _, socket) do

dev/runner.ex

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,49 @@
11
defmodule LiveDebuggerDev.Runner do
22
def run() do
33
# Configures the endpoint
4-
Application.put_env(:live_debugger_dev_app, LiveDebuggerDev.Endpoint,
4+
5+
config =
6+
if Mix.env() == :test do
7+
common_config() ++ test_only_config()
8+
else
9+
common_config() ++ dev_only_config()
10+
end
11+
12+
Application.put_env(:live_debugger_dev_app, LiveDebuggerDev.Endpoint, config)
13+
14+
Application.put_env(:phoenix, :serve_endpoints, true)
15+
16+
Task.async(fn ->
17+
children = [
18+
{Phoenix.PubSub, name: LiveDebuggerDev.PubSub},
19+
LiveDebuggerDev.Endpoint
20+
]
21+
22+
{:ok, _} = Supervisor.start_link(children, strategy: :one_for_one)
23+
24+
# For some reason `Application.put_env` doesn't work and LiveDebugger starts without config
25+
Application.stop(:live_debugger)
26+
Application.start(:live_debugger)
27+
28+
Process.sleep(:infinity)
29+
end)
30+
end
31+
32+
defp common_config() do
33+
[
534
url: [host: "localhost"],
635
secret_key_base: "Hu4qQN3iKzTV4fJxhorPQlA/osH9fAMtbtjVS58PFgfw3ja5Z18Q/WSNR9wP4OfW",
736
live_view: [signing_salt: "hMegieSe"],
8-
http: [port: System.get_env("PORT") || 4004],
937
debug_errors: true,
1038
check_origin: false,
1139
pubsub_server: LiveDebuggerDev.PubSub,
12-
adapter: Bandit.PhoenixAdapter,
40+
adapter: Bandit.PhoenixAdapter
41+
]
42+
end
43+
44+
defp dev_only_config() do
45+
[
46+
http: [port: System.get_env("PORT") || 4004],
1347
watchers: [
1448
esbuild: {Esbuild, :install_and_run, [:dev_build, ~w(--watch)]},
1549
tailwind: {Tailwind, :install_and_run, [:dev_build, ~w(--watch)]}
@@ -28,23 +62,13 @@ defmodule LiveDebuggerDev.Runner do
2862
~r"dev/layout.ex"
2963
]
3064
]
31-
)
32-
33-
Application.put_env(:phoenix, :serve_endpoints, true)
34-
35-
Task.async(fn ->
36-
children = [
37-
{Phoenix.PubSub, name: LiveDebuggerDev.PubSub},
38-
LiveDebuggerDev.Endpoint
39-
]
40-
41-
{:ok, _} = Supervisor.start_link(children, strategy: :one_for_one)
42-
43-
# For some reason `Application.put_env` doesn't work and LiveDebugger starts without config
44-
Application.stop(:live_debugger)
45-
Application.start(:live_debugger)
65+
]
66+
end
4667

47-
Process.sleep(:infinity)
48-
end)
68+
defp test_only_config() do
69+
[
70+
http: [port: 4005],
71+
server: true
72+
]
4973
end
5074
end

lib/live_debugger.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ defmodule LiveDebugger do
2727
secret_key_base: Keyword.get(config, :secret_key_base, @default_secret_key_base),
2828
live_view: [signing_salt: Keyword.get(config, :signing_salt, @default_signing_salt)],
2929
adapter: Keyword.get(config, :adapter, default_adapter),
30-
live_reload: Keyword.get(config, :live_reload, [])
30+
live_reload: Keyword.get(config, :live_reload, []),
31+
server: Keyword.get(config, :server, false)
3132
]
3233

3334
Application.put_env(@app_name, LiveDebugger.Endpoint, endpoint_config)

lib/live_debugger/components.ex

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,13 @@ defmodule LiveDebugger.Components do
221221

222222
def section(assigns) do
223223
~H"""
224-
<div class={[
225-
"w-full min-w-[20rem] lg:max-w-[32rem] h-max flex flex-col shadow-custom rounded-sm bg-surface-0-bg border border-default-border"
226-
| List.wrap(@class)
227-
]}>
224+
<div
225+
id={@id}
226+
class={[
227+
"w-full min-w-[20rem] flex flex-col shadow-custom rounded-sm bg-surface-0-bg border border-default-border"
228+
| List.wrap(@class)
229+
]}
230+
>
228231
<div class="pl-4 flex items-center h-12 p-2 border-b border-default-border">
229232
<div class="flex justify-between items-center w-full">
230233
<div class="font-medium text-sm"><%= @title %></div>
@@ -234,7 +237,7 @@ defmodule LiveDebugger.Components do
234237
</div>
235238
</div>
236239
<div class={[
237-
"w-full flex overflow-auto rounded-sm bg-surface-0-bg p-2" | List.wrap(@inner_class)
240+
"flex flex-1 overflow-auto rounded-sm bg-surface-0-bg m-2" | List.wrap(@inner_class)
238241
]}>
239242
<%= render_slot(@inner_block) %>
240243
</div>
@@ -386,7 +389,7 @@ defmodule LiveDebugger.Components do
386389
id={@id}
387390
phx-hook="Fullscreen"
388391
class={[
389-
"relative h-max w-full lg:w-max lg:min-w-[50rem] bg-surface-0-bg p-2 overflow-auto hidden flex-col rounded-md backdrop:bg-black backdrop:opacity-50"
392+
"relative h-max w-full xl:w-max xl:min-w-[50rem] bg-surface-0-bg p-2 overflow-auto hidden flex-col rounded-md backdrop:bg-black backdrop:opacity-50"
390393
| List.wrap(@class)
391394
]}
392395
>
@@ -553,7 +556,7 @@ defmodule LiveDebugger.Components do
553556
<.icon name="icon-logo-text" class="h-6 w-32" />
554557
</div>
555558
<div class="flex items-center">
556-
<%= if LiveDebugger.Env.dev?() do %>
559+
<%= if LiveDebugger.Feature.enabled?(:dark_mode) do %>
557560
<.nav_icon
558561
id="light-mode-switch"
559562
class="dark:hidden"

0 commit comments

Comments
 (0)