-
Notifications
You must be signed in to change notification settings - Fork 949
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
Proof of concept: playwright e2e tests #3001
Proof of concept: playwright e2e tests #3001
Conversation
A lot of devs hate end-to-end/feature tests because flakiness and speed, but front-end <-> back-end integration is uniquely crucial in LiveView, so I'd love to see the core happy paths tested end-to-end at the lib level. I've got a lot of experience de-flaking and optimizing e2e builds, so I'd be down to collaborate/contribute. Regarding tooling, we already have |
@vanderhoop what makes Playwright special is that it supports all browser engines. Wallaby seems to only support Chromium and Firefox. There is a playwright library for Elixir, but it is not yet in a state comparable to the official libraries (TS, JS, Python, Java, .NET). As this is just about telling the browsers what to do I don't think that it is crucial that the end to end tests are written in Elixir. It would definitely be nice though! I am using Playwright for testing a big LiveView app at work now for ~2 years and they do a really good job at preventing flakiness. |
41c3f36
to
fc125aa
Compare
55f9ce9
to
91fdc20
Compare
91fdc20
to
90bb9bd
Compare
references phoenixframework#3009 references phoenixframework#2993 references phoenixframework#1759
7b726e8
to
ab0bf00
Compare
We want to run the e2e tests with the latest assets without the need to commit them to the repository. Otherwise we would not see test failures from changes to the js code as early as possible.
ab0bf00
to
52bcaae
Compare
Adjusting CI pipelines is always fun... I added some more tests for changes in other recent PRs on mine, but in general this is ready for review (probably @chrismccord). I know that the style I used in the e2e test files is different than the assets js files, because that's the style I usually use when writing javascript (semicolons, spaces between curly braces, ...) and the assets eslint config does not apply to this folder. A project-wide linter or formatter for the JS code would be nice. If needed, I'll adjust the style accordingly. I also thought about a way to define the LiveView code that is necessary for the tests in the test files themselves. At work, we have an HTTP endpoint that const { elixirEval } = require("../does_not_exist_yet");
test("my test 123", async ({ page, request }) => {
await elixirEval(request, `
defmodule LiveView.LiveViewTest.E2E.MyLiveViewTest123 do
...
def render(assigns) do
...
end
end
LiveView.LiveViewTest.E2E.Router.somehow_define_live_route_at_runtime("/my-liveview-test-123", LiveView.LiveViewTest.E2E.MyLiveViewTest123)
`);
await page.goto("/my-liveview-test-123");
...
}); This would be especially nice for self-contained regression tests. This has the drawback of not getting any compilation errors before starting the tests. |
@SteffenDE This looks amazing! The dynamic code eval could work by compiling entire routers for each test case, and dispatching from the elixir script endpoint to a "dynamic" router, but I am not sure yet about the tradeoffs. For now, it's probably best for us to simply start with the elixir script server serving up LV's that smoke test all our core features like you've started here. JS Style wise, I am not overly concerned and can touch up myself if needed. I'm happy to merge this as is at this point and we can revisit collocated elixir snippets if things get unruly in the future. Is the |
Awesome, very happy to hear that! I think the problem with the skipped test is that LiveViewTest and the JS client handle prepend differently, because you recently changed the JS code not to move elements on prepend if they already exist. So actually the problem is probably on the LiveViewTest side. The fix would be to change |
Makes sense. The LV test should be using stream_delete + stream_insert anyway. I'll fix it up and unfail the test. Thank you for this! |
❤️❤️❤️🐥🔥 |
This PR implements a proof of concept of using Playwright to run end to end browser tests that actually run the whole LiveView pipeline from JavaScript to Elixir, no weird mocking necessary.
I'm happy to discuss how to move this forward.