Two Element Web users open widget-rtc-sdk/index.html as a widget, join and exchange data. `pnpm dev:widget-rtc-sdk` serves the example on :3003 with its import pointed at the source; Playwright builds and previews it instead, since Firefox now and then stalls on the dev server's module requests. The widget fixture's display names get the worker's parallelIndex, as parallel workers could reach it in the same millisecond. The README notes that the example asks for an OpenID token more than once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3.2 KiB
Testing
Three layers; a user-facing feature needs all three. Unit proves the logic, Storybook proves the rendering, e2e proves the feature. Codecov gates 80% on the lines a PR touches.
Unit
- View model tests use
withTestScheduler+testScope()fromsrc/utils/test.tsand read as ASCII timelines. CopyLayoutSwitchViewModel.test.ts. - Component tests use Testing Library, queried by role and accessible name.
- Reuse the factories in
src/utils/test.ts—mockRemoteParticipant,mockMatrixRoom,mockLivekitRoom,MockRTCSession. Hand-rolled mocks drift. - Snapshots live in
__snapshots__/; update withpnpm test <Name> -u. - How often something redraws is testable: drive the frames and count commits, not render calls. An effect with no dependency array runs once per commit.
component/**/*.test.tsruns in the same jsdom project assrc.
Storybook
A deliverable, not documentation: pnpm test:storybook runs every story as a real
browser test in the same CI job as the unit suite. A UI change without a story is
incomplete. Only three stories exist so far, so copy CallFooter.stories.tsx.
- Drive the component from a snapshot via
useStaticViewModel, never internals. - One named story per state that matters — loading, error, empty, denied, mobile.
- Assert in a
playfunction withuserEvent/expectfromstorybook/test. - Mobile is
globals: { viewport: { value: "mobile2" } }, not a second component. - Expose interesting props through
argTypes.
.storybook/preview.tsx supplies TooltipProvider, src/index.css and English
translations. The browser is Playwright's, so a fresh clone needs
pnpm playwright install once.
End-to-end
The Element Web instance HOST1 opens the app the dev server serves. The instance
HOST2 (the other site) opens the embedded package as a host ships it. This package
is built by the build-embedded setup project and mounted in docker-compose-playwright.yml.
playwright/*.spec.ts— standalone, on Chromium and Firefox.playwright/widget/— widget mode, where cross-context bugs surface.playwright/component/— the component in a host page, via the harness on port 3001 that Playwright starts as a second web server. Catches container-relative layout, styles escaping the root, two instances on a page, host-bridge reports.playwright/sdk/— the MatrixRTC SDK through its harness on port 3002, a page with none of Element Call on it. The smoke test is what the implementation is built against.playwright/mobile/— Pixel 7,mobileproject only.
Test what a user observes: the peer sees the change, it survives a reconnect, it is
right after a reload. Reuse playwright/spa-helpers.ts,
playwright/widget/test-helpers.ts, playwright/fixtures/.
To mark new release announcements as viewed, add them in backend/ew.test*.config.json.
pnpm test # unit + storybook
pnpm backend # Synapse + LiveKit, required for e2e
pnpm test:playwright # or :open
pnpm dev:component # component harness, port 3001
pnpm dev:sdk # SDK harness, port 3002
pnpm dev:widget-rtc-sdk # widget RTC SDK example widget, port 3003