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

Warn on duplicate IDs and fail test, but don't prevent debugging #3588

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

SteffenDE
Copy link
Collaborator

Relates to: #3560

I don't think that the code is particularly pretty, but it shows the idea.

Sample output:

Running ExUnit with seed: 389897, max_cases: 20

.........................................................................................................................................................................................warning: Duplicate id found while testing LiveView: push-to-self

    <button id="push-to-self" phx-click="[[&quot;push&quot;,{&quot;value&quot;:{&quot;inc&quot;:1},&quot;target&quot;:&quot;#child_1&quot;,&quot;event&quot;:&quot;inc&quot;}],[&quot;push&quot;,{&quot;value&quot;:{&quot;inc&quot;:10},&quot;target&quot;:&quot;#child_1&quot;,&quot;event&quot;:&quot;inc&quot;}]]">
       Both to self
     </button>


LiveView requires that all elements have unique ids, duplicate IDs will cause
undefined behavior at runtime, as DOM patching will not be able to target the correct
elements.

  (phoenix_live_view 1.0.1) lib/phoenix_live_view/test/live_view_test.ex:430: Phoenix.LiveViewTest.warn_duplicate_ids_loop/3

warning: Duplicate id found while testing LiveView: push-to-other-targets

    <button id="push-to-other-targets" phx-click="[[&quot;push&quot;,{&quot;value&quot;:{&quot;inc&quot;:2},&quot;target&quot;:&quot;#child_2&quot;,&quot;event&quot;:&quot;inc&quot;}],[&quot;push&quot;,{&quot;value&quot;:{&quot;inc&quot;:1},&quot;target&quot;:&quot;#child_1&quot;,&quot;event&quot;:&quot;inc&quot;}],[&quot;push&quot;,{&quot;value&quot;:{&quot;inc&quot;:-1},&quot;event&quot;:&quot;inc&quot;}]]">
       One to everyone
     </button>


LiveView requires that all elements have unique ids, duplicate IDs will cause
undefined behavior at runtime, as DOM patching will not be able to target the correct
elements.

  (phoenix_live_view 1.0.1) lib/phoenix_live_view/test/live_view_test.ex:430: Phoenix.LiveViewTest.warn_duplicate_ids_loop/3

warning: Duplicate id found while testing LiveView: push-to-self

    <button id="push-to-self" phx-click="[[&quot;push&quot;,{&quot;value&quot;:{&quot;inc&quot;:1},&quot;target&quot;:&quot;#child_1&quot;,&quot;event&quot;:&quot;inc&quot;}],[&quot;push&quot;,{&quot;value&quot;:{&quot;inc&quot;:10},&quot;target&quot;:&quot;#child_1&quot;,&quot;event&quot;:&quot;inc&quot;}]]">
       Both to self
     </button>


LiveView requires that all elements have unique ids, duplicate IDs will cause
undefined behavior at runtime, as DOM patching will not be able to target the correct
elements.

  (phoenix_live_view 1.0.1) lib/phoenix_live_view/test/live_view_test.ex:430: Phoenix.LiveViewTest.warn_duplicate_ids_loop/3

warning: Duplicate id found while testing LiveView: push-to-other-targets

    <button id="push-to-other-targets" phx-click="[[&quot;push&quot;,{&quot;value&quot;:{&quot;inc&quot;:2},&quot;target&quot;:&quot;#child_2&quot;,&quot;event&quot;:&quot;inc&quot;}],[&quot;push&quot;,{&quot;value&quot;:{&quot;inc&quot;:1},&quot;target&quot;:&quot;#child_1&quot;,&quot;event&quot;:&quot;inc&quot;}],[&quot;push&quot;,{&quot;value&quot;:{&quot;inc&quot;:-1},&quot;event&quot;:&quot;inc&quot;}]]">
       One to everyone
     </button>


LiveView requires that all elements have unique ids, duplicate IDs will cause
undefined behavior at runtime, as DOM patching will not be able to target the correct
elements.

  (phoenix_live_view 1.0.1) lib/phoenix_live_view/test/live_view_test.ex:430: Phoenix.LiveViewTest.warn_duplicate_ids_loop/3



  1) test LiveViewTest supports multiple JS.push events from a component to other targets (Phoenix.LiveView.EventTest)
     test/phoenix_live_view/integrations/event_test.exs:194
     ** (RuntimeError) Detected duplicate IDs! Check the warnings logged for details.
     stacktrace:
       (phoenix_live_view 1.0.1) lib/phoenix_live_view/test/live_view_test.ex:420: anonymous fn/2 in Phoenix.LiveViewTest.start_duplicate_id_check/1
       (ex_unit 1.19.0-dev) lib/ex_unit/on_exit_handler.ex:136: ExUnit.OnExitHandler.exec_callback/1
       (ex_unit 1.19.0-dev) lib/ex_unit/on_exit_handler.ex:122: ExUnit.OnExitHandler.on_exit_runner_loop/0

.

  2) test LiveViewTest supports multiple JS.push events from a component to itself (Phoenix.LiveView.EventTest)
     test/phoenix_live_view/integrations/event_test.exs:183
     ** (RuntimeError) Detected duplicate IDs! Check the warnings logged for details.
     stacktrace:
       (phoenix_live_view 1.0.1) lib/phoenix_live_view/test/live_view_test.ex:420: anonymous fn/2 in Phoenix.LiveViewTest.start_duplicate_id_check/1
       (ex_unit 1.19.0-dev) lib/ex_unit/on_exit_handler.ex:136: ExUnit.OnExitHandler.exec_callback/1
       (ex_unit 1.19.0-dev) lib/ex_unit/on_exit_handler.ex:122: ExUnit.OnExitHandler.on_exit_runner_loop/0

.............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
Finished in 4.5 seconds (1.8s async, 2.6s sync)
6 doctests, 1219 tests, 2 failures

@SteffenDE
Copy link
Collaborator Author

I think we may want to remove the warning and extend the error message instead. Just noticed that they are swallowed by capture_io sometimes.

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.

1 participant