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

Add full e2e phoenix app test #797

Merged
merged 3 commits into from
Oct 21, 2024
Merged

Conversation

solnic
Copy link
Collaborator

@solnic solnic commented Sep 17, 2024

Here's a test setup that does e2e testing with a real phoenix app. This will be handy when testing more complex integrations like OTel stuff for a good start. It should also help us reduce the risk of introducing regressions in Phoenix apps (once we add more tests of course).

The only custom "trick" I had to use was defining endpoint in test/support because I made sentry depend on the phoenix_app from test/fixtures/phoenix_app and the endpoint needs access to Sentry.CapturePlug.

Another nice benefit is that we could set it up in the Sentry SDK project and it would make it simpler to test things out w/o having to create new setups manually.

@solnic solnic force-pushed the solnic/phoenix-test-setup branch 5 times, most recently from b1d4326 to bfd8d21 Compare September 17, 2024 12:25
@solnic solnic marked this pull request as ready for review September 17, 2024 12:28
@whatyouhide
Copy link
Collaborator

whatyouhide commented Sep 17, 2024

I’m wondering if a better way to do this would be to instead have a Phoenix app in integration_tests or something, and then have a specific Mix task for testing that app (mix test in the app basically). That app can then depend on {:sentry, path: ".."}.

https://github.com/elixir-ecto/ecto_sql does all this setup and has been running it successfully for a while, so it could be a good source of inspiration.

@solnic
Copy link
Collaborator Author

solnic commented Sep 18, 2024

@whatyouhide yeah this makes sense, thanks for suggestion!

@solnic solnic force-pushed the solnic/phoenix-test-setup branch 2 times, most recently from 4e6622d to f9848b3 Compare September 18, 2024 12:15
@solnic
Copy link
Collaborator Author

solnic commented Sep 19, 2024

==> Running tests for integration: phoenix_app
** (Mix) You're trying to run :phoenix_app on Elixir v1.13.4 but it has declared in its mix.exs file it supports only Elixir ~> 1.14
Integration tests for phoenix_app failed
Error: Process completed with exit code 1.

So, what's our strategy here? Can we drop 1.13 support given that more recent Phoenix versions do not support it?

@solnic solnic force-pushed the solnic/phoenix-test-setup branch 2 times, most recently from 09b7ab0 to c52cb9e Compare September 27, 2024 09:55
@solnic
Copy link
Collaborator Author

solnic commented Sep 27, 2024

I made mix test skip running test.integrations when Elixir version is < 1.16 for the time being.

@solnic solnic force-pushed the solnic/phoenix-test-setup branch 2 times, most recently from c5cb3ca to efc209a Compare September 27, 2024 13:14
mix.exs Outdated Show resolved Hide resolved
mix.exs Outdated Show resolved Hide resolved
mix.exs Outdated Show resolved Hide resolved
mix.exs Outdated Show resolved Hide resolved
mix.exs Outdated Show resolved Hide resolved
mix.exs Outdated Show resolved Hide resolved
test/test_helper.exs Outdated Show resolved Hide resolved
test_integrations/phoenix_app/mix.exs Show resolved Hide resolved
@solnic
Copy link
Collaborator Author

solnic commented Oct 14, 2024

@whatyouhide thank you so much for all the suggestions! I applied all of it + rebased/squashed + updated #784 (which waits for reviews too 🙏🏻)

Copy link
Collaborator

@whatyouhide whatyouhide left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was testing this locally, and noticed these issues:

  1. The first time I ran mix test.integrations, it didn't work because I had to go into the Phoenix app directory and run mix deps.get. I think we should shove that into the Mix alias itself.

  2. Can we fix this compilation warning within the Phoenix app?

==> phoenix_app
Compiling 18 files (.ex)
warning: defining a Gettext backend by calling

    use Gettext, otp_app: ...

is deprecated. To define a backend, call:

    use Gettext.Backend, otp_app: :my_app

Then, instead of importing your backend, call this in your module:

    use Gettext, backend: MyApp.Gettext

  lib/phoenix_app_web/gettext.ex:23: PhoenixAppWeb.Gettext (module)

The fix is exactly what it says it is 😄

Comment on lines +88 to +89
defp test_paths(nil), do: ["test"]
defp test_paths(integration), do: ["test_integrations/#{integration}/test"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this.

@whatyouhide whatyouhide merged commit 4403f5d into master Oct 21, 2024
4 checks passed
@whatyouhide whatyouhide deleted the solnic/phoenix-test-setup branch October 21, 2024 08:14
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.

2 participants