-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplaywright.config.ts
More file actions
301 lines (283 loc) · 9.71 KB
/
playwright.config.ts
File metadata and controls
301 lines (283 loc) · 9.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
import { defineConfig, devices } from '@playwright/test';
import { TEST_VIEWPORTS } from './src/config/test-viewports';
import type { TestViewport } from './src/types/mobile-first';
/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
require('dotenv').config();
/**
* Convert TestViewport to Playwright device config
*/
function createDeviceConfig(viewport: TestViewport) {
return {
viewport: {
width: viewport.width,
height: viewport.height,
},
deviceScaleFactor: viewport.deviceScaleFactor,
hasTouch: viewport.hasTouch,
isMobile: viewport.isMobile,
...(viewport.userAgent && { userAgent: viewport.userAgent }),
};
}
/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './tests/e2e',
/* Global setup runs once before all tests - validates prerequisites */
globalSetup: './tests/e2e/global-setup.ts',
/* Run test files sequentially on CI to avoid parallel database contention.
* Shard 2 messaging tests share test users in Supabase — parallel execution
* causes page.goto timeouts, missing conversations, and Realtime failures.
* Locally, parallel is fine (single user, no contention). */
fullyParallel: !process.env.CI,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* 1 worker on CI: with 6 shards × 3 browsers = 18 parallel jobs,
* intra-shard parallelism causes cross-file interference (e.g.
* friend-requests deletes connections while encrypted-messaging
* verifies they exist). Sequential execution within each shard
* is fast enough since load is spread across 18 jobs. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: [
['html', { open: 'never' }],
['list'],
process.env.CI ? ['github'] : ['line'],
['json', { outputFile: 'test-results/results.json' }],
['junit', { outputFile: 'test-results/junit.xml' }],
],
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: process.env.BASE_URL || 'http://localhost:3000',
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
/* Take screenshot on every failure */
screenshot: 'on',
/* Retain video on failure */
video: 'retain-on-failure',
/* Maximum time each action can take. 15s accounts for Supabase free tier
* query latency after conversation selection in messaging tests. */
actionTimeout: 15000,
/* Navigation timeout — 60s to account for Argon2id key derivation
* during handleReAuthModal after each page.goto('/messages') */
navigationTimeout: 60000,
/* Emulate mobile device capabilities */
isMobile: false,
/* Block service workers — they intercept navigations and cause
* ERR_ABORTED / "frame was detached" errors during page.goto()
* and page.reload() across all browsers, not just WebKit. */
serviceWorkers: 'block',
/* Context options */
contextOptions: {
ignoreHTTPSErrors: true,
},
},
/* Configure projects with ordered execution for rate-limiting isolation */
/* Note: storageState is set per-project (setup uses base, others use authenticated) */
projects: [
// ============================================================
// AUTH SETUP: Runs once, saves authenticated browser state
// All parallel projects depend on this and reuse the cached state.
// ============================================================
{
name: 'setup',
testMatch: /auth\.setup\.ts/,
use: {
storageState: './tests/e2e/fixtures/storage-state.json',
},
},
// ============================================================
// ORDERED PROJECTS: Rate-limiting tests run FIRST (unauthenticated)
// This prevents sign-up tests from exhausting Supabase's
// IP-based rate limits before rate-limiting tests can run.
// ============================================================
// Rate-limiting tests - run FIRST with clean IP quota
{
name: 'rate-limiting',
testDir: './tests/e2e/auth',
testMatch: /rate-limiting\.spec\.ts/,
use: {
...devices['Desktop Chrome'],
storageState: './tests/e2e/fixtures/storage-state.json',
},
},
// Brute-force tests - run after rate-limiting
{
name: 'brute-force',
testDir: './tests/e2e/security',
testMatch: /brute-force\.spec\.ts/,
dependencies: ['rate-limiting'],
use: {
...devices['Desktop Chrome'],
storageState: './tests/e2e/fixtures/storage-state.json',
},
},
// Sign-up tests - run LAST (consumes rate limit quota)
{
name: 'signup',
testDir: './tests/e2e/auth',
testMatch: /sign-up\.spec\.ts/,
dependencies: ['brute-force'],
use: {
...devices['Desktop Chrome'],
storageState: './tests/e2e/fixtures/storage-state.json',
},
},
// ============================================================
// PARALLEL PROJECTS: Pre-authenticated via storageState
// These exclude rate-limiting, brute-force, and sign-up tests
// ============================================================
// Messaging tests isolated into their own project — sharded separately
// in CI to prevent state contention (friend-requests deletes connections
// that encrypted-messaging/group-chat/offline-queue need).
{
name: 'chromium-msg',
testMatch: '**/messaging/**',
testIgnore: ['**/examples/**'],
dependencies: ['setup'],
use: {
...devices['Desktop Chrome'],
storageState: './tests/e2e/fixtures/storage-state-auth.json',
},
},
// General (non-messaging) tests
{
name: 'chromium-gen',
testIgnore: [
'**/messaging/**', // handled by chromium-msg
'**/examples/**', // POM tutorial, not production tests
'**/rate-limiting.spec.ts',
'**/brute-force.spec.ts',
'**/sign-up.spec.ts',
],
dependencies: ['setup'],
use: {
...devices['Desktop Chrome'],
storageState: './tests/e2e/fixtures/storage-state-auth.json',
},
},
// Firefox: split into msg/gen the same way as chromium
{
name: 'firefox-msg',
testMatch: '**/messaging/**',
testIgnore: ['**/examples/**'],
dependencies: ['setup'],
use: {
...devices['Desktop Firefox'],
storageState: './tests/e2e/fixtures/storage-state-auth.json',
},
},
{
name: 'firefox-gen',
testIgnore: [
'**/messaging/**',
'**/examples/**',
'**/rate-limiting.spec.ts',
'**/brute-force.spec.ts',
'**/sign-up.spec.ts',
],
dependencies: ['setup'],
use: {
...devices['Desktop Firefox'],
storageState: './tests/e2e/fixtures/storage-state-auth.json',
},
},
// WebKit: split into msg/gen the same way as chromium
{
name: 'webkit-msg',
testMatch: '**/messaging/**',
testIgnore: ['**/examples/**'],
dependencies: ['setup'],
use: {
...devices['Desktop Safari'],
storageState: './tests/e2e/fixtures/storage-state-auth.json',
},
},
{
name: 'webkit-gen',
testIgnore: [
'**/messaging/**',
'**/examples/**',
'**/rate-limiting.spec.ts',
'**/brute-force.spec.ts',
'**/sign-up.spec.ts',
],
dependencies: ['setup'],
use: {
...devices['Desktop Safari'],
storageState: './tests/e2e/fixtures/storage-state-auth.json',
},
},
/* Mobile-first test viewports (PRP-017) */
...TEST_VIEWPORTS.filter((v) => v.category === 'mobile').map(
(viewport) => ({
name: `Mobile - ${viewport.name}`,
testIgnore: [
'**/examples/**',
'**/rate-limiting.spec.ts',
'**/brute-force.spec.ts',
'**/sign-up.spec.ts',
],
dependencies: ['setup'],
use: {
...createDeviceConfig(viewport),
storageState: './tests/e2e/fixtures/storage-state-auth.json',
},
})
),
/* Tablet viewports */
...TEST_VIEWPORTS.filter((v) => v.category === 'tablet').map(
(viewport) => ({
name: `Tablet - ${viewport.name}`,
testIgnore: [
'**/examples/**',
'**/rate-limiting.spec.ts',
'**/brute-force.spec.ts',
'**/sign-up.spec.ts',
],
dependencies: ['setup'],
use: {
...createDeviceConfig(viewport),
storageState: './tests/e2e/fixtures/storage-state-auth.json',
},
})
),
/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],
/* Run your local dev server before starting the tests */
webServer: process.env.SKIP_WEBSERVER
? undefined
: process.env.CI
? {
command: 'npx serve out -l 3000',
url: 'http://localhost:3000',
reuseExistingServer: false,
timeout: 60 * 1000,
stdout: 'pipe',
stderr: 'pipe',
}
: {
command: 'pnpm run dev',
url: 'http://localhost:3000',
reuseExistingServer: true,
timeout: 120 * 1000,
stdout: 'pipe',
stderr: 'pipe',
},
/* Output folders */
outputDir: 'test-results/',
});