-
Notifications
You must be signed in to change notification settings - Fork 54
change endpoint config into setup block style #299
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
Open
slapers
wants to merge
2
commits into
germsvel:main
Choose a base branch
from
slapers:feat/endpoint-config
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+201
−41
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| defmodule PhoenixTest.EndpointHelpers do | ||
| @moduledoc false | ||
|
|
||
| # This module replaces Phoenix test macros that require `@endpoint` to be set | ||
| # as a compile-time module attribute. Instead, the endpoint is read at runtime | ||
| # from `conn.private[:phoenix_endpoint]`, set via `PhoenixTest.put_endpoint/2`. | ||
|
|
||
| def endpoint_from!(conn) do | ||
| conn.private[:phoenix_endpoint] || | ||
| raise ArgumentError, """ | ||
| No endpoint set on conn. Use PhoenixTest.put_endpoint/2 in your test setup: | ||
|
|
||
| conn = Phoenix.ConnTest.build_conn() |> PhoenixTest.put_endpoint(MyAppWeb.Endpoint) | ||
| """ | ||
| end | ||
|
|
||
| def endpoint_from(conn) do | ||
| conn.private[:phoenix_endpoint] | ||
| end | ||
|
|
||
| def copy_endpoint(dest_conn, source_conn) do | ||
| Plug.Conn.put_private(dest_conn, :phoenix_endpoint, endpoint_from(source_conn)) | ||
| end | ||
|
|
||
| # Replaces: live(conn) | ||
| # The `live/1` macro's binary-path branch calls `get(conn, path)` which | ||
| # requires `@endpoint` at compile time, even when path is nil. | ||
| def live(conn) do | ||
| Phoenix.LiveViewTest.__live__(conn, nil, []) | ||
| end | ||
|
|
||
| # Replaces: follow_redirect(result, conn) for :live_redirect | ||
| def follow_live_redirect(conn, opts) do | ||
| endpoint = endpoint_from!(conn) | ||
| {conn, to} = Phoenix.LiveViewTest.__follow_redirect__(conn, endpoint, nil, opts) | ||
|
|
||
| conn | ||
| |> Phoenix.ConnTest.dispatch(endpoint, :get, to, nil) | ||
| |> Phoenix.LiveViewTest.__live__(to, []) | ||
| end | ||
|
|
||
| # Replaces: follow_redirect(result, conn) for :redirect | ||
| def follow_redirect(conn, opts) do | ||
| endpoint = endpoint_from!(conn) | ||
| {conn, to} = Phoenix.LiveViewTest.__follow_redirect__(conn, endpoint, nil, opts) | ||
| Phoenix.ConnTest.dispatch(conn, endpoint, :get, to, nil) | ||
| end | ||
|
|
||
| # Replaces: file_input(view, form_selector, name, entries) | ||
| # The `file_input/4` macro calls `Phoenix.ChannelTest.connect/2` which | ||
| # requires `@endpoint` at compile time. | ||
| def file_input(view, conn, form_selector, name, entries) do | ||
| endpoint = endpoint_from!(conn) | ||
| builder = fn -> Phoenix.ChannelTest.__connect__(endpoint, Phoenix.LiveView.Socket, %{}, []) end | ||
| Phoenix.LiveViewTest.__file_input__(view, form_selector, name, entries, builder) | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of my concerns with handling multiple endpoint configs is that we have to shadow these "internal" LiveViewTest functions.
I'm worried about that we'll either miss something or experience drift from how LiveViewTest tests things.
In this particular case, I think the
get(conn, path)is important for trying to emulate the real behavior LiveView has -- first we have a static connection which then gets upgraded.2 questions for you:
getrequest without having to include the compile time endpoint?LiveViewTestfunctions? I'm open to ideas.