forked from phoenixframework/phoenix_live_view
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
proof of concept: playwright e2e tests
- Loading branch information
Showing
11 changed files
with
447 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -24,3 +24,5 @@ phoenix_live_view-*.tar | |
|
||
node_modules | ||
|
||
/test/e2e/test-results/ | ||
/playwright-report/ |
This file contains 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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,40 @@ | ||
// playwright.config.js | ||
// @ts-check | ||
const { devices } = require("@playwright/test"); | ||
|
||
/** @type {import("@playwright/test").PlaywrightTestConfig} */ | ||
const config = { | ||
forbidOnly: !!process.env.CI, | ||
retries: process.env.CI ? 2 : 0, | ||
reporter: process.env.CI ? [["github"], ["html"]] : "list", | ||
use: { | ||
trace: "retain-on-failure", | ||
screenshot: "only-on-failure", | ||
baseURL: "http://localhost:4000/", | ||
ignoreHTTPSErrors: true, | ||
}, | ||
webServer: { | ||
command: "npm run e2e:server", | ||
url: "http://127.0.0.1:4000/health", | ||
reuseExistingServer: !process.env.CI, | ||
stdout: "pipe", | ||
stderr: "pipe", | ||
}, | ||
projects: [ | ||
{ | ||
name: "chromium", | ||
use: { ...devices["Desktop Chrome"] }, | ||
}, | ||
{ | ||
name: "firefox", | ||
use: { ...devices["Desktop Firefox"] }, | ||
}, | ||
{ | ||
name: "webkit", | ||
use: { ...devices["Desktop Safari"] }, | ||
} | ||
], | ||
outputDir: "test-results" | ||
}; | ||
|
||
module.exports = config; |
This file contains 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,79 @@ | ||
Application.put_env(:phoenix_live_view, Phoenix.LiveViewTest.E2E.Endpoint, | ||
http: [ip: {127, 0, 0, 1}, port: 4000], | ||
# TODO: switch to bandit when Phoenix 1.7 is used | ||
# adapter: Bandit.PhoenixAdapter, | ||
server: true, | ||
live_view: [signing_salt: "aaaaaaaa"], | ||
secret_key_base: String.duplicate("a", 64), | ||
render_errors: [ | ||
# TODO: uncomment when LV Phoenix 1.7 is used | ||
# formats: [ | ||
# html: Phoenix.LiveViewTest.E2E.ErrorHTML, | ||
# ], | ||
view: Phoenix.LiveViewTest.E2E.ErrorHTML, | ||
layout: false | ||
], | ||
debug_errors: true | ||
) | ||
|
||
defmodule Phoenix.LiveViewTest.E2E.ErrorHTML do | ||
def render(template, _), do: Phoenix.Controller.status_message_from_template(template) | ||
end | ||
|
||
defmodule Phoenix.LiveViewTest.E2E.Layout do | ||
use Phoenix.Component | ||
|
||
def render("live.html", assigns) do | ||
~H""" | ||
<script src="/assets/phoenix/phoenix.min.js"></script> | ||
<script src="/assets/phoenix_live_view/phoenix_live_view.js"></script> | ||
<script> | ||
let liveSocket = new window.LiveView.LiveSocket("/live", window.Phoenix.Socket) | ||
liveSocket.connect() | ||
</script> | ||
<style> | ||
* { font-size: 1.1em; } | ||
</style> | ||
<%= @inner_content %> | ||
""" | ||
end | ||
end | ||
|
||
defmodule Phoenix.LiveViewTest.E2E.Router do | ||
use Phoenix.Router | ||
import Phoenix.LiveView.Router | ||
|
||
pipeline :browser do | ||
plug(:accepts, ["html"]) | ||
end | ||
|
||
live_session :default, layout: {Phoenix.LiveViewTest.E2E.Layout, :live} do | ||
scope "/" do | ||
pipe_through(:browser) | ||
|
||
live("/stream", Phoenix.LiveViewTest.StreamLive, :index) | ||
end | ||
end | ||
end | ||
|
||
defmodule Phoenix.LiveViewTest.E2E.Endpoint do | ||
use Phoenix.Endpoint, otp_app: :phoenix_live_view | ||
|
||
socket("/live", Phoenix.LiveView.Socket) | ||
|
||
plug Plug.Static, from: {:phoenix, "priv/static"}, at: "/assets/phoenix" | ||
plug Plug.Static, from: {:phoenix_live_view, "priv/static"}, at: "/assets/phoenix_live_view" | ||
|
||
plug :health_check | ||
|
||
plug Phoenix.LiveViewTest.E2E.Router | ||
|
||
defp health_check(%{request_path: "/health"} = conn, _opts) do | ||
conn |> Plug.Conn.send_resp(200, "OK") |> Plug.Conn.halt() | ||
end | ||
|
||
defp health_check(conn, _opts), do: conn | ||
end | ||
|
||
{:ok, _} = Supervisor.start_link([Phoenix.LiveViewTest.E2E.Endpoint], strategy: :one_for_one) | ||
Process.sleep(:infinity) |
Oops, something went wrong.