Repository navigation
test(e2e): named per-role fixtures (alice, bob, multiTab) - #12
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThese changes replace manual Playwright context/page creation with new fixtures ( Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
…xtures Addresses the final CR comment on #9: manual `browser.newContext()` instances are not auto-disposed by Playwright. If a test fails mid-flow, contexts leak until the worker exits, which can starve memory and produce incomplete traces. Instead of adding try/finally blocks to every test (CR's suggestion) or a factory escape hatch, land named per-role fixtures in fixtures.ts: - `alice` / `bob` — each provides a Page inside its own fresh BrowserContext. Two-user tests destructure whichever they need; Playwright's fixture-level lazy evaluation ensures unused fixtures never create contexts. - `multiTab` — single shared BrowserContext + pre-created admin Page. Used only by `multi-tab.spec.ts` which intentionally tests cross-tab localStorage isolation within one browser. Every per-test manual `browser.newContext()` + `ctx.close()` pair is gone. Test signatures now read as what they need: async ({ alice, bob }) => { ... } async ({ multiTab: { ctx, admin } }) => { ... } Also fixed: the Alice-only `/waiting` "Edit my answers" test in `edit-post-completion.spec.ts` was previously creating a manual context for no reason — it's now on the built-in `{ page }` fixture since it's a genuinely single-user test. Why this pattern instead of a factory: - Self-documenting signatures (the test parameters tell you the topology before you read the body) - Lazy fixture evaluation: a `{ alice }` test doesn't create a Bob context - Type-safe, composable: adding roles means adding fixtures - Canonical per Playwright's fixture docs — no escape hatch needed Files touched: fixtures.ts + the 7 specs that previously used `browser.newContext()` manually. Refs: coderabbitai review on #9 (edit-post-completion.spec.ts:10) Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
6ba00b7 to
2cdd150
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (2)
e2e/fixtures.ts (2)
54-71: Reduce duplicated role fixture setup/teardown.Lines 54-71 repeat the same context/page lifecycle for
aliceandbob. Extracting a small helper will keep fixture changes safer and more maintainable.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@e2e/fixtures.ts` around lines 54 - 71, The alice and bob fixtures repeat identical setup/teardown logic; extract a shared helper (e.g., createRoleFixture) that accepts the fixture callback and returns an async fixture to create a new context and page, call use(page), and close the context with .catch(() => {}); replace alice and bob implementations to delegate to this helper and keep multiTab unchanged (it already differs) so future changes to lifecycle live in one place.
36-40: Extract fixture object shapes into interfaces.Lines 36-40 currently use inline object shapes for exported fixture typing. Please move these to named interfaces/types (PascalCase) to match repo TypeScript conventions.
♻️ Proposed refactor
import { type BrowserContext, test as base, expect, type Page } from "@playwright/test"; @@ -export const test = base.extend<{ - alice: Page; - bob: Page; - multiTab: { ctx: BrowserContext; admin: Page }; -}>({ +interface MultiTabFixture { + ctx: BrowserContext; + admin: Page; +} + +interface E2eFixtures { + alice: Page; + bob: Page; + multiTab: MultiTabFixture; +} + +export const test = base.extend<E2eFixtures>({As per coding guidelines: "Use interfaces for object shapes in TypeScript".
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@e2e/fixtures.ts` around lines 36 - 40, The inline fixture shape used in the exported const test (base.extend<{ alice: Page; bob: Page; multiTab: { ctx: BrowserContext; admin: Page }; }>) should be extracted into PascalCase interfaces; define e.g. interface TestFixtures { alice: Page; bob: Page; multiTab: MultiTabFixture } and interface MultiTabFixture { ctx: BrowserContext; admin: Page }, export them, then replace the inline generic on base.extend with base.extend<TestFixtures> so the fixture types follow the repo TypeScript convention and are reusable.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@e2e/fixtures.ts`:
- Around line 54-71: The alice and bob fixtures repeat identical setup/teardown
logic; extract a shared helper (e.g., createRoleFixture) that accepts the
fixture callback and returns an async fixture to create a new context and page,
call use(page), and close the context with .catch(() => {}); replace alice and
bob implementations to delegate to this helper and keep multiTab unchanged (it
already differs) so future changes to lifecycle live in one place.
- Around line 36-40: The inline fixture shape used in the exported const test
(base.extend<{ alice: Page; bob: Page; multiTab: { ctx: BrowserContext; admin:
Page }; }>) should be extracted into PascalCase interfaces; define e.g.
interface TestFixtures { alice: Page; bob: Page; multiTab: MultiTabFixture } and
interface MultiTabFixture { ctx: BrowserContext; admin: Page }, export them,
then replace the inline generic on base.extend with base.extend<TestFixtures> so
the fixture types follow the repo TypeScript convention and are reusable.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 41e0d46d-b909-4182-ab20-63b9262c3799
📒 Files selected for processing (8)
e2e/edit-post-completion.spec.tse2e/fixtures.tse2e/multi-tab.spec.tse2e/realtime-status.spec.tse2e/reconnect-resume.spec.tse2e/results.spec.tse2e/self-pick-flow.spec.tse2e/two-player.spec.ts
The test signature (`async ({ page }) => ...`) already communicates
that this is a single-user test using the built-in page fixture.
The comment restates what the code says.
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Response to reviewBoth nitpicks are pure style preferences and don't hold up on inspection. Rejecting both. Nitpick 1: extract
|
|
🎉 This PR is included in version 1.3.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Summary
Addresses the final CR comment on #9: manual
browser.newContext()instances leak on test failure because Playwright does not auto-dispose contexts created outside its built-in fixtures. Rather than addtry/finallyblocks to every test (CR's suggestion) or use a factory escape hatch, land named per-role fixtures infixtures.ts.New fixtures
Test signatures now self-document
async ({ browser }) => { const aliceCtx = await browser.newContext(); /* ... */ }async ({ alice, bob }) => { ... }async ({ browser }) => { const ctx = await browser.newContext(); const admin = await ctx.newPage(); /* ... */ }async ({ multiTab: { ctx, admin } }) => { ... }async ({ page }) => { ... }(built-in, no manual context needed)Why this design
{ alice }never creates a Bob context. No wasted work for single-user scenarios.Files touched
e2e/fixtures.ts— newalice/bob/multiTabfixturese2e/edit-post-completion.spec.ts— 2 tests migrated; the single-user waiting test moved to built-in{ page }e2e/multi-tab.spec.ts— 3 tests migrated tomultiTabe2e/realtime-status.spec.ts— 1 test migratede2e/reconnect-resume.spec.ts— 1 test migratede2e/results.spec.ts— 3 tests migratede2e/self-pick-flow.spec.ts— 1 test migratede2e/two-player.spec.ts— 1 test migrated (plain + encrypted)Zero manual
browser.newContext()calls remain in the suite.Test plan
pnpm exec biome check .pnpm --filter @spreadsheet/web typecheckpnpm exec playwright test --workers=2— 35/35 passing, ~3 min🤖 Generated with Claude Code
Summary by CodeRabbit