Skip to content

Commit cc17b3e

Browse files
committed
refactor(web): remove e2e fixture logic from production code
Remove test-specific code from production page.tsx by using Playwright's route mocking for both SSR and hydration tests: - Remove E2E_ENABLE_QUERY_FIXTURE env var checks from page.tsx - Remove e2eFixture query param handling from page.tsx - Delete web/src/app/store/e2e-fixture.ts (no longer needed) - Update store-ssr.spec.ts to use page.route() for API mocking - Update documentation to reflect Playwright-based mocking approach This keeps production code clean and uses proper e2e testing patterns where test infrastructure handles mocking instead of production code having test-specific branches.
1 parent d949acf commit cc17b3e

File tree

4 files changed

+38
-67
lines changed

4 files changed

+38
-67
lines changed

web/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ On Render, set the Health Check Path to `/api/healthz` in your service settings
100100

101101
### E2E tests for SSR and hydration
102102

103-
- Hydration fallback: `src/__tests__/e2e/store-hydration.spec.ts`
104-
- SSR HTML: `src/__tests__/e2e/store-ssr.spec.ts` (JavaScript disabled) using server-side fixture `src/app/store/e2e-fixture.ts` when `E2E_ENABLE_QUERY_FIXTURE=1`.
103+
- Hydration fallback: `src/__tests__/e2e/store-hydration.spec.ts` - Tests client-side data fetching when SSR data is empty
104+
- SSR HTML: `src/__tests__/e2e/store-ssr.spec.ts` - Tests server-side rendering with JavaScript disabled
105+
106+
Both tests use Playwright's `page.route()` to mock API responses without polluting production code.
105107

106108
Run locally:
107109

web/src/__tests__/e2e/store-ssr.spec.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,37 @@ import { test, expect } from '@playwright/test'
44
test.use({ javaScriptEnabled: false })
55

66
test('SSR HTML contains at least one agent card', async ({ page }) => {
7-
const response = await page.goto('/store?e2eFixture=1', {
7+
const agents = [
8+
{
9+
id: 'base',
10+
name: 'Base',
11+
description: 'desc',
12+
publisher: { id: 'codebuff', name: 'Codebuff', verified: true, avatar_url: null },
13+
version: '1.2.3',
14+
created_at: new Date().toISOString(),
15+
weekly_spent: 10,
16+
weekly_runs: 5,
17+
usage_count: 50,
18+
total_spent: 100,
19+
avg_cost_per_invocation: 0.2,
20+
unique_users: 3,
21+
last_used: new Date().toISOString(),
22+
version_stats: {},
23+
tags: ['test'],
24+
},
25+
]
26+
27+
// Mock the server-side API call that happens during SSR
28+
// This intercepts the request before SSR completes
29+
await page.route('**/api/agents', async (route) => {
30+
await route.fulfill({
31+
status: 200,
32+
contentType: 'application/json',
33+
body: JSON.stringify(agents),
34+
})
35+
})
36+
37+
const response = await page.goto('/store', {
838
waitUntil: 'domcontentloaded',
939
})
1040
expect(response).not.toBeNull()

web/src/app/store/e2e-fixture.ts

Lines changed: 0 additions & 50 deletions
This file was deleted.

web/src/app/store/page.tsx

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,12 @@ interface PublisherProfileResponse {
99
}
1010

1111
export async function generateMetadata(): Promise<Metadata> {
12-
// In E2E mode, avoid DB by using local fixture
1312
let agents: Array<{
1413
name?: string
1514
publisher?: { avatar_url?: string | null }
1615
}> = []
1716
try {
18-
agents =
19-
process.env.E2E_ENABLE_QUERY_FIXTURE === '1'
20-
? (await import('./e2e-fixture')).getAgentsFixture()
21-
: await (await import('@/server/agents-data')).getCachedAgents()
17+
agents = await (await import('@/server/agents-data')).getCachedAgents()
2218
} catch {
2319
agents = []
2420
}
@@ -59,17 +55,10 @@ interface StorePageProps {
5955
}
6056

6157
export default async function StorePage({ searchParams }: StorePageProps) {
62-
// E2E fixture path to prevent DB dependency during e2e
63-
const useFixture =
64-
process.env.E2E_ENABLE_QUERY_FIXTURE === '1' &&
65-
(searchParams['e2eFixture'] === '1' || searchParams['e2eFixture'] === 'true')
66-
67-
// Fetch agents data on the server with ISR cache (or use test fixture)
58+
// Fetch agents data on the server with ISR cache
6859
let agentsData: any[] = []
6960
try {
70-
agentsData = useFixture
71-
? (await import('./e2e-fixture')).getAgentsFixture()
72-
: await (await import('@/server/agents-data')).getCachedAgents()
61+
agentsData = await (await import('@/server/agents-data')).getCachedAgents()
7362
} catch {
7463
agentsData = []
7564
}

0 commit comments

Comments
 (0)