Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .formatter.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import_deps: [:phoenix],
line_length: 120,
plugins: [Phoenix.LiveView.HTMLFormatter, Styler],
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
inputs: ["{mix,.formatter}.exs", "{config,e2e_pw,lib,test}/**/*.{ex,exs}"]
]
27 changes: 23 additions & 4 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ jobs:
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
elixir-version: "1.15"
otp-version: "26"
# playwright_ex needs Elixir ~> 1.18
elixir-version: "1.19"
otp-version: "28"

- name: Restore Elixir dependency cache
uses: actions/cache@v6
Expand All @@ -44,8 +45,26 @@ jobs:
- name: Install npm dependencies (root)
run: npm install

# mix.lock pins the playwright_ex driver and so the browser revisions
- name: Restore Playwright driver and browser cache
uses: actions/cache@v6
with:
path: |
~/.cache/playwright
~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ hashFiles('**/mix.lock') }}

- name: Install E2E dependencies and browsers
run: npm run e2e:install
run: mix playwright.install chromium --with-deps

# Up to two retries of the failed tests, as the `retries: 2` of Playwright Test
- name: Run E2E tests
run: npm run e2e:test
run: |
npm run e2e:build
mix test || { [ $? -eq 2 ] && mix test --failed; } || { [ $? -eq 2 ] && mix test --failed; }

- uses: actions/upload-artifact@v7
if: ${{ !cancelled() }}
with:
name: test-results
path: test-results
20 changes: 11 additions & 9 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Vue.js + Phoenix LiveView integration library. Version 1.0.0.
# Tests
mix test # Elixir tests
npm test # Vitest (assets/*.test.ts)
npm run e2e:test # Playwright E2E (test/e2e/)
mix e2e.test # Playwright E2E (e2e_pw/, server in test/e2e/)

# Setup
mix setup # First-time setup (deps + npm install)
Expand All @@ -30,7 +30,8 @@ assets/
├── useLiveForm.ts # Form handling with Ecto changesets
├── jsonPatch.ts # Efficient prop diffing
└── vitePlugin.js # Vite plugin for component discovery
test/e2e/ # Playwright E2E tests with Phoenix server
test/e2e/ # Phoenix server and features for the E2E tests
e2e_pw/ # Playwright E2E tests (ExUnit, playwright_ex)
```

## Key Patterns
Expand Down Expand Up @@ -67,20 +68,21 @@ test/e2e/features/
├── basic/ # Each feature is a directory
│ ├── live.ex # LiveView module
│ ├── counter.vue # Vue component(s)
│ └── basic.spec.js # Playwright test
│ └── ...
├── form/
├── stream/
└── ...
```

To add a new E2E test:
1. Create `test/e2e/features/my-feature/`
2. Add `live.ex` (LiveView), `*.vue` (components), `*.spec.js` (test)
3. Add route to `test/e2e/test_helper.exs` router
2. Add `live.ex` (LiveView) and `*.vue` (components)
3. Add route to `test/e2e/server.exs` router
4. Add the test to `e2e_pw/` (`use LiveVue.E2E.Case`)

Key utilities in `test/e2e/utils.js`:
- `syncLV(page)` - Wait for LiveView connection
- `evalLV(page, code)` - Execute Elixir in LiveView process
Key utilities in `e2e_pw/support/utils.ex`:
- `sync_lv(page)` - Wait for LiveView connection
- `eval_lv(page, code)` - Execute Elixir in LiveView process

## Conventions

Expand All @@ -94,5 +96,5 @@ For hex.pm releases, `mix release.{patch,minor,major}` runs easy_publish (bumps

## Notes

- This is a library - use E2E tests (`npm run e2e:test`) for testing
- This is a library - use E2E tests (`mix e2e.test`) for testing
- CI: Elixir (.github/workflows/elixir.yml), Frontend (.github/workflows/frontend.yml)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ Ensure you have Node.js installed. Clone the repo and run `mix setup`.

No build step is required for the library itself - Vite handles TypeScript transpilation when consumers bundle their app.

Use `npm run e2e:test` to run the Playwright E2E tests.
Use `mix e2e.test` to run the Playwright E2E tests (first `MIX_ENV=e2e mix playwright.install chromium`).

### Testing Local Changes in Another Project

Expand Down
2 changes: 1 addition & 1 deletion conductor-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ npm ci

# Install Playwright browsers for E2E tests
echo "🎭 Installing Playwright browsers..."
npm run e2e:install
MIX_ENV=e2e mix deps.get && MIX_ENV=e2e mix playwright.install chromium

echo "✅ Setup complete! Run 'cd example_project && mix phx.server' to start development."
9 changes: 9 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,12 @@ config :live_vue,
# if false, we will always update full props and not send diffs
# defaults to true as it greatly reduces payload size
enable_props_diff: true

if config_env() == :e2e do
config :playwright, :expect, timeout: 1000
# The Playwright suite in e2e_pw/
config :playwright, :test,
base_url: "http://localhost:4004/",
trace: :retain_on_failure,
screenshot: :only_on_failure
end
6 changes: 6 additions & 0 deletions config/runtime.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Config

# Desktop Chrome for every test. Here, as config.exs runs before Playwright.device/1 is compiled.
if config_env() == :e2e do
config :playwright, :test, Playwright.device("Desktop Chrome")
end
36 changes: 36 additions & 0 deletions e2e_pw/basic_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
defmodule LiveVue.E2E.BasicTest do
use LiveVue.E2E.Case, async: true

describe "LiveVue Basic E2E Tests" do
test "renders Vue component inside LiveView and handles increment events", %{page: page} do
Page.goto!(page, "/test")
sync_lv(page)

# Verify Vue component is mounted and displays initial count
Expect.to_be_visible!(Page.locator(page, ~s([phx-hook="VueHook"])))
Expect.to_have_text!(Page.locator(page, "[data-pw-counter]"), "0")

# Verify the diff slider is present and has default value
diff_slider = Page.locator(page, ~s(input[type="range"]))
Expect.to_be_visible!(diff_slider)
Expect.to_have_value!(diff_slider, "1")

# Test incrementing by default value (1)
Locator.click!(Page.locator(page, "button"))
sync_lv(page)
Expect.to_have_text!(Page.locator(page, ~s([phx-hook="VueHook"] [data-pw-counter])), "1")

# Test incrementing by a different value (3)
Locator.fill!(diff_slider, "3")
Locator.click!(Page.locator(page, "button"))
sync_lv(page)
Expect.to_have_text!(Page.locator(page, ~s([phx-hook="VueHook"] [data-pw-counter])), "4")

# Test incrementing by maximum value (10)
Locator.fill!(diff_slider, "10")
Locator.click!(Page.locator(page, "button"))
sync_lv(page)
Expect.to_have_text!(Page.locator(page, ~s([phx-hook="VueHook"] [data-pw-counter])), "14")
end
end
end
26 changes: 26 additions & 0 deletions e2e_pw/dead_view_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
defmodule LiveVue.E2E.DeadViewTest do
use LiveVue.E2E.Case, async: true

alias Playwright.Response

describe "LiveVue Dead View Tests" do
test "renders Vue component inside regular Phoenix controller view (dead view)", %{page: page} do
# Navigate to the dead view page
response = Page.goto!(page, "/dead-view")

# First check if the page loaded successfully (no 500 error)
assert Response.status(response) == 200

# Verify the server-rendered content from the controller
Expect.to_have_text!(Page.locator(page, "[data-pw-server-message]"), "Hello from dead view!")

# Wait for Vue to initialize and hydrate the component
# In dead views, Vue still mounts via the VueHook initialization
Page.wait_for_timeout!(page, 500)

# Verify the Vue component rendered correctly
Expect.to_be_visible!(Page.locator(page, "[data-pw-dead-view]"))
Expect.to_have_text!(Page.locator(page, "[data-pw-vue-message]"), "Hello from dead view!")
end
end
end
Loading