-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
[Feature] Component testing: use vite dev server mode instead of production mode #14748
Comments
dev server actually makes things much, much slower. each test is making an endpoint request and with dev mode each request takes 200ms. so we deliberately made a decision to go prod mode. Once you have 100 tests, 200ms per request becomes a 20 seconds of delay non-starter. |
This feature is excellent, especially for debugging. Another addition that I thought. It would be great to combine |
I agree with @AlexanderMykulych, in my case I found it took me about 20 sec to finish the prod build. If we don't use dev server mode, then how are we going to support watch mode, HMR and TDD, and getting faster feedback? |
Same feature request. In my case debugging errors with React in the production build is painfully slow. |
Related to: #21960 |
My current approach is to use vite server, and create an index.html and index.tsx file for my tests, which is a bit of manual work. However it gives me a very fast feedback loop as I can run a component test almost without delay by pointing playwright at the vite server. When using playwright component testing, I have to wait for the full prod build which as mentioned above is very slow, though perfect for CI as the tests run the fastest they can - this leaves the dev experience lacking. |
Hi @cameronbraid , do you have an example how to set it up? |
Its just using normal vite running in dev mode and using playwright to drive the browser to the vite pages Just create a new folder for each test, with the following as an example src/test-a/index.html <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<div id="root" style="height:100%"></div>
<script type="module" src="./index.tsx"></script>
</body>
</html> src/test-a/index.tsx import * as React from "react"
import { createRoot } from "react-dom/client"
const TestComponent = () => {
return <div data-testid='TestComponent'>TestComponent</div>
}
createRoot(document.getElementById("root")).render(<TestComponent/>) src/test-a/test-Playwright.tsx import { expect, Request, Route, test } from "@playwright/test"
import { viteUrl } from "src/viteUrl"
test.describe("TestComponent", () => {
test("renders", async ({ page }) => {
await page.goto(viteUrl(`/src/test-a/`))
await expect(page.locator("[data-testid=TestComponent]").toContainText("TestComponent"))
})
}) src/viteUrl.ts export function viteUrl(path: string) {
return (process.env.VITE_URL || "http://localhost:3002") + path
} As I said above Cameron |
Would love to have a faster option that doesn't require a full prod build. 🙏 |
Any plans to improve the iteration rate? Right now, we have to wait for tens of seconds of vite production build time for each small change to the source code, for It makes TDD super painful for component testing under playwright. We have to stick to Vitest + RTL for component testing. |
Vite has plans to improve production builds by creating a faster, Rust-based replacement for the Rollup bundler. This will likely improve iteration speed/performance significantly. See @yyx990803's recent keynote for more info: https://youtu.be/hrdwQHoAp0M?si=DwWDdMWh7_zz51fv&t=501 |
What would be the preferred shape of a fix for this? (a) Watch mode# blocking process
npm run test -- --watch
(b) Dev server# blocking process
npm run test -- --dev
(c) Something else? |
Out of curiosity - will this change make the following scenarios possible:
I've been looking for ways to test a SvelteKit app E2E with playwright, but I need ways to catch and mock outgoing requests from the server-side part. Haven't found a solution so far and I've wondered whether playwright using vite's dev server might indeed give me a way to achieve this. |
@spuxx1701 there is a separate issue to track this: #19399.
See: #19399 (comment) |
Thanks for giving me pointers @sand4rt ! |
#21960 is what i was looking for and #23372 if i have to use VSCode. Would that be the same as option A? This approach enables me to keep the browser open alongside the editor, allowing for a more efficient workflow as changes to the component or test are automatically reflected in the browser without the necessity of executing Not sure if I understand the pro's and cons of option B correctly. It seems that i still have to execute |
When assessing the VS Code workflow, think about this feature as of two separate features that result in the "watch" behavior:
(1) is already implemented on ToT: # start the server
npx pw-react dev-server Then you just run the tests (console or run decoration in VS Code) and they will use the server. |
Hi there, I was wondering if there are any updates or new developments regarding this issue? |
When I run component tests, I found first uses rollup to bundle the files and then run the test, I wonder if we can use vite dev server mode to run the component tests, then we have many benefits from vite:
The text was updated successfully, but these errors were encountered: