-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplaywright.config.ts
More file actions
380 lines (358 loc) · 13 KB
/
Copy pathplaywright.config.ts
File metadata and controls
380 lines (358 loc) · 13 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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
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 }),
};
}
/**
* #116 Phase 2 — messaging specs converted to per-test fixture isolation
* (seedIsolatedConversation / openAsViewer). These own their data, so they run
* in a parallel `*-msg-iso` project at workers>1 instead of the serial
* `*-msg` shard. Add a spec here as it is converted; the serial `*-msg` project
* `testIgnore`s this same list so nothing runs twice.
*
* NOTE: this is the SINGLE source of truth — `MSG_ISO_GLOBS` is used as the iso
* projects' `testMatch` AND the serial projects' `testIgnore`.
*/
const MSG_ISO_GLOBS = [
'**/messaging/encrypted-messaging.spec.ts',
'**/messaging/real-time-delivery.spec.ts',
'**/messaging/offline-queue.spec.ts',
'**/messaging/offline-queue-sync.spec.ts',
'**/messaging/cross-window-delivery.spec.ts',
'**/messaging/complete-user-workflow.spec.ts',
'**/messaging/message-delete-placeholder.spec.ts',
'**/messaging/message-editing.spec.ts',
'**/messaging/performance.spec.ts',
'**/messaging/oauth-setup-modal.spec.ts',
'**/messaging/gdpr-compliance.spec.ts',
'**/messaging/friend-requests.spec.ts',
'**/messaging/group-chat-multiuser.spec.ts',
];
/* Parallelism for the iso projects is driven by Playwright's `--workers` CLI
* flag passed per CI job (so only the iso shard runs workers>1; gen/serial msg
* stay at the global `workers:1`). Locally, `fullyParallel` on the iso project
* + the default worker pool gives parallelism for free. */
/* Per-test budget for the iso messaging projects. A bidirectional test opens
* TWO browser contexts, each paying a gate-load (~11s) + Argon2id unlock (~3s,
* TIME_COST=3 — never lowered) before the first send. The Playwright default
* (30s) is exhausted by the two opens alone, so the test would time out and its
* afterEach would cascade-delete the partner's key mid-send → a spurious 406
* "needs to sign in". Size the budget to the work this slice actually does.
* Scoped to the iso projects so real hangs elsewhere still fail fast. */
const MSG_ISO_TIMEOUT = 180_000;
/**
* 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,
/* Default to 1 worker on CI. The *-gen and serial *-msg projects share
* fixed test users, so intra-shard parallelism would cause cross-file
* interference. The per-test-isolated *-msg-iso projects override this to
* workers>1 via the CI job's --workers flag (#116 Phase 2) — each of their
* tests owns its own throwaway users, so there is no shared state to race. */
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).
// Serial (workers:1): the UNconverted specs that still share PRIMARY/TERTIARY.
{
name: 'chromium-msg',
testMatch: '**/messaging/**',
testIgnore: ['**/examples/**', ...MSG_ISO_GLOBS],
dependencies: ['setup'],
use: {
...devices['Desktop Chrome'],
storageState: './tests/e2e/fixtures/storage-state-auth.json',
},
},
// #116 Phase 2: messaging specs converted to per-test fixture isolation.
// These own their data, so they run fully parallel (workers>1 via the CI
// job's `--workers` flag). storageState is irrelevant — each test injects
// its own throwaway viewer session — but kept for parity.
{
name: 'chromium-msg-iso',
testMatch: MSG_ISO_GLOBS,
fullyParallel: true,
timeout: MSG_ISO_TIMEOUT,
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/**', ...MSG_ISO_GLOBS],
dependencies: ['setup'],
use: {
...devices['Desktop Firefox'],
storageState: './tests/e2e/fixtures/storage-state-auth.json',
},
},
{
name: 'firefox-msg-iso',
testMatch: MSG_ISO_GLOBS,
fullyParallel: true,
timeout: MSG_ISO_TIMEOUT,
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/**', ...MSG_ISO_GLOBS],
dependencies: ['setup'],
use: {
...devices['Desktop Safari'],
storageState: './tests/e2e/fixtures/storage-state-auth.json',
},
},
{
name: 'webkit-msg-iso',
testMatch: MSG_ISO_GLOBS,
fullyParallel: true,
timeout: MSG_ISO_TIMEOUT,
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/',
});