Files
webstudio/apps/builder/e2e
Oleg Isonen b9319a3891 perf: share CLI startup for user-site publishing (#6704)
This PR reduces user-site publish time by sharing CLI startup between
sync and build, reducing asset downloads when hosted builds do not need
them, and testing smaller publish artifacts. The paired [SaaS PR
#685](https://github.com/webstudio-is/webstudio-saas/pull/685) uses the
combined CLI path when the Builder artifact advertises support; older
artifacts keep the existing split path.

The paired staging publish served HTML and JavaScript successfully. The
combined CLI step took 4 s versus about 8 s for the previous split steps
in that run; total publish time remained about 40 s. This is one
observation, not a controlled benchmark or a large-site measurement.
Local artifact pruning reduced the compressed archive from 119 MiB to
111 MiB (6.7%); it was not adopted. The full artifact is still
downloaded and extracted on every publish.

## Checklist

- [x] Preserve standalone sync/build behavior and gate combined
sync/build with an artifact capability marker.
- [x] Skip hosted asset downloads only when content indexing does not
need them; preserve static and MDX-required downloads.
- [x] Test CLI startup, synthetic build, and artifact-size
opportunities; record why no riskier change was adopted.
- [x] Verify the paired staging publish and review Builder
documentation.
- [x] Keep only the E2E schema snapshot matching current inputs; no
migration source or migration was added.
- [x] Retry the failing `pages-drag` shard: all 17 tests passed,
including the drag-and-nest test.
- [x] Resolve the two outdated review threads; current code retains
finding details and closes diagnostics on element navigation.
- [x] Required CI on the cleanup commit passed, including all Builder
E2E shards, visual regression, and the existing migration-chain check.
- [ ] Run the agent evaluation suite only after separate approval;
remind the user before merging.

No large-site publish or production release has been tested.
2026-11-17 14:04:00 +01:00
..

Builder E2E tests

Builder E2E workflows run with Playwright Test. The Playwright setup project waits for PostgREST, resets the disposable database, and warms the login route before Chromium runs the selected tests.

Run the suite

Use the full command for CI-like validation:

pnpm e2e:builder

The local command builds Builder and the generated React Router components used by Preview tests.

In CI, the build job caches those compiled files. A later E2E-only change can restore them after dependency setup; changes outside apps/builder/e2e still compile Builder before the five shards download the build artifact.

The schema snapshot is generated from the regular migration pipeline and committed at e2e/schema/schema-<fingerprint>.sql. When a migration or backend input changes, refresh the snapshot and commit the new file:

pnpm e2e:builder:refresh-schema-cache

The regular E2E suite uses lightweight PostgreSQL containers. Verify that the complete migration chain also applies to the pinned Supabase PostgreSQL image with:

pnpm e2e:builder:check-supabase-migrations

Pass normal Playwright Test arguments after --. For example:

pnpm e2e:builder -- --grep "Builder can copy, duplicate, and delete a page"
pnpm e2e:builder -- 'pages-actions'
pnpm e2e:builder -- --debug --grep "Builder can copy"

A lightweight Playwright discovery pass validates the selection before Docker, database migrations, browser installation, or the Builder build starts. A filter that matches no tests therefore fails without starting the test environment.

Fast local reruns

Keep the E2E backend and Builder development server running to avoid rebuilding Builder and restarting Docker for each edit.

Terminal 1:

pnpm e2e:builder:dev:backend

Terminal 2:

pnpm dev

Terminal 3:

pnpm e2e:builder:dev -- --grep "Builder can copy, duplicate, and delete a page"

pnpm e2e:builder:dev defaults to E2E_BUILDER_URL=https://127.0.0.1:3000. Override it when the development server uses another port. Chromium maps wstd.dev and its project subdomains to loopback for local Builder URLs, so host-file changes are unnecessary.

The development backend uses E2E_DB_BOOTSTRAP=if-empty and keeps Docker containers running. The Playwright setup project still resets test data before each invocation.

Test organization

  • Put workflows in e2e/tests/*.e2e.ts and import test from e2e/test.ts.
  • Use Playwright's page fixture for the workflow under test. Playwright gives each test an isolated context and closes it automatically.
  • Use Playwright's context fixture when setup should share authentication with the workflow page.
  • Use withBrowserContext(browser, callback) for isolated setup or setup that runs in beforeAll. If cookies must survive from beforeAll into the tests, create an explicit context with newBrowserContext(browser) and close it in afterAll.
  • Use newIsolatedPage(browser) for identities that must not share cookies.
  • Keep tests in a file independent even though Playwright runs them in declaration order by default.

CI runs five isolated Playwright shards with four workers each. Files have a fixed assignment based on measured CI duration to keep the slowest job short:

pages-actions.[shard-3].e2e.ts

Every E2E filename in CI must contain one shard tag. The build job checks that the tags match the five shards in the workflow. Rebalance by changing filename tags when measured job durations drift.

Suites may opt into parallel mode only when every worker creates uniquely named setup data and the tests do not depend on each other's mutations.

Backend organization

Development, E2E, schema-cache, and Supabase compatibility commands share the backend definition in apps/builder/backend. compose.yaml defines the common services, and compose.<mode>.yaml defines only the differences for a named mode. Backend commands resolve these files by convention; callers do not pass Compose filenames.

The snapshot fingerprint discovers migration sources and non-test backend files automatically. Adding a database image, initialization script, Compose override, or migration therefore requires a new snapshot. CI checks that the matching snapshot is committed, and the Supabase migration job still checks the complete migration chain.

Failures

Failed shard jobs upload the Playwright HTML report, traces, screenshots, videos, and backend service logs.

When you need a completely clean backend locally:

E2E_SKIP_CLEANUP=false pnpm e2e:builder