-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplaywright.config.ts
More file actions
282 lines (265 loc) · 9.34 KB
/
Copy pathplaywright.config.ts
File metadata and controls
282 lines (265 loc) · 9.34 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
import { defineConfig, devices } from '@playwright/test'
/**
* Playwright E2E Test Configuration for GitBox
*
* Features:
* - Real local Supabase database for data persistence tests
* - MSW for GitHub API mocking (external API stability)
* - Auth setup with cookie injection for Supabase + GitHub OAuth
* - Separate projects for authenticated vs unauthenticated tests
* - V8 code coverage collection with monocart-reporter
* - Global setup/teardown for database reset
*/
/** Path to store authenticated state for reuse across tests */
const AUTH_FILE = 'e2e/.auth/user.json'
/**
* Local Supabase configuration
* Using local instance for real database testing
*/
const LOCAL_SUPABASE_URL = 'http://127.0.0.1:54321'
const LOCAL_SUPABASE_ANON_KEY =
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0'
/**
* Parallel mode configuration.
* When E2E_PARALLEL_MODE is set, the orchestrator script (scripts/e2e-parallel.sh)
* manages server lifecycle and DB reset externally. Each shard gets its own
* Next.js server on a unique port via E2E_SHARD_PORT.
*/
const isParallelMode = !!process.env.E2E_PARALLEL_MODE
const shardPort = process.env.E2E_SHARD_PORT || '3008'
export default defineConfig({
testDir: './e2e',
/**
* Global setup: Reset database before all tests.
* Global teardown: Clean up database after all tests.
* Disabled in parallel mode — the orchestrator handles DB reset once.
*/
globalSetup: isParallelMode ? undefined : './e2e/global-setup.ts',
globalTeardown: isParallelMode ? undefined : './e2e/global-teardown.ts',
/**
* Disable full parallel execution for database state consistency.
* Tests share the same database, so they must run sequentially
* within each worker to avoid race conditions.
*/
fullyParallel: false,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
/**
* Worker configuration:
* - CI: 1 worker per shard for database state consistency
* - Local: 1 worker (during migration, can increase after verification)
*
* Note: With real database, parallel workers need careful test isolation.
* Starting with 1 worker for reliability, can optimize later.
*/
workers: process.env.CI ? 1 : 1,
/**
* Fail the test run if any tests are flaky (passed only after retry).
* This enforces test reliability — flaky tests must be fixed, not ignored.
*/
failOnFlakyTests: true,
/**
* Reporters:
* - CI: blob (for shard merging) + monocart (for coverage)
* - Local: list + monocart (for coverage)
*
* NOTE: blob reporter is required for CI sharding. It generates
* `blob-report/` directory with test results that are merged by
* `playwright merge-reports` in the merge-reports job.
*/
reporter: isParallelMode
? [
[
'blob',
{
outputDir: `./blob-report/shard-${process.env.SHARD_INDEX || '1'}`,
},
],
]
: process.env.CI
? [
['blob'],
[
'monocart-reporter',
{
name: 'GitBox E2E Coverage Report',
outputFile: './coverage-e2e/index.html',
coverage: {
reports: [
['v8'],
['html', { subdir: 'istanbul' }],
['lcovonly', { file: 'lcov.info' }],
['text-summary'],
['json-summary', { file: 'coverage-summary.json' }],
],
entryFilter: {
'**/node_modules/**': false,
'**/_next/static/chunks/webpack*': false,
'**/_next/static/chunks/polyfills*': false,
'**/_next/static/**': true,
},
sourceFilter: {
// Exclude: Server-side only code (E2E cannot trigger)
'**/lib/actions/**': false,
'**/lib/supabase/**': false,
'**/app/auth/callback/**': false,
'**/instrumentation*.ts': false,
'**/sentry.*.config.ts': false,
// Exclude: Test/dev infrastructure
'**/tests/**': false,
'**/mocks/**': false,
'**/*.spec.ts': false,
'**/*.test.ts': false,
'**/*.test.tsx': false,
'**/*.stories.tsx': false,
'**/.storybook/**': false,
// Exclude: Config & build
'**/*.config.ts': false,
'**/*.config.js': false,
'**/*.config.mjs': false,
'**/node_modules/**': false,
'**/.next/**': false,
// Include: Client code
'**/app/**': true,
'**/components/**': true,
'**/lib/**': true,
'**/packages/**': true,
},
sourcePath: (filePath: string) => {
return filePath
.replace(/^webpack:\/\/gitbox\//, '')
.replace(/^\.\//g, '')
},
},
},
],
]
: [
['list'],
[
'monocart-reporter',
{
name: 'GitBox E2E Coverage Report',
outputFile: './coverage-e2e/index.html',
coverage: {
reports: [
['v8'],
['html', { subdir: 'istanbul' }],
['lcovonly', { file: 'lcov.info' }],
['text-summary'],
['json-summary', { file: 'coverage-summary.json' }],
],
entryFilter: {
'**/node_modules/**': false,
'**/_next/static/chunks/webpack*': false,
'**/_next/static/chunks/polyfills*': false,
'**/_next/static/**': true,
},
sourceFilter: {
// Exclude: Server-side only code (E2E cannot trigger)
'**/lib/actions/**': false,
'**/lib/supabase/**': false,
'**/app/auth/callback/**': false,
'**/instrumentation*.ts': false,
'**/sentry.*.config.ts': false,
// Exclude: Test/dev infrastructure
'**/tests/**': false,
'**/mocks/**': false,
'**/*.spec.ts': false,
'**/*.test.ts': false,
'**/*.test.tsx': false,
'**/*.stories.tsx': false,
'**/.storybook/**': false,
// Exclude: Config & build
'**/*.config.ts': false,
'**/*.config.js': false,
'**/*.config.mjs': false,
'**/node_modules/**': false,
'**/.next/**': false,
// Include: Client code
'**/app/**': true,
'**/components/**': true,
'**/lib/**': true,
'**/packages/**': true,
},
sourcePath: (filePath: string) => {
return filePath
.replace(/^webpack:\/\/gitbox\//, '')
.replace(/^\.\//g, '')
},
},
},
],
],
timeout: 30000,
use: {
baseURL: `http://localhost:${shardPort}`,
trace: 'on-first-retry',
screenshot: 'only-on-failure',
video: 'retain-on-failure',
},
projects: [
/**
* Setup project: Injects auth cookies to bypass OAuth flow.
* Runs before authenticated tests.
*/
{
name: 'setup',
testMatch: 'auth.setup.ts',
},
/**
* Unauthenticated tests: Landing page, login page, etc.
* These don't require authentication state.
*/
{
name: 'unauthenticated',
use: {
...devices['Desktop Chrome'],
},
testMatch: /unauthenticated\/.*[.]spec.ts/,
},
/**
* Logged-in tests: Tests that require authenticated state.
* Depends on 'setup' project and uses its stored auth state.
*/
{
name: 'logged-in',
dependencies: ['setup'],
use: {
...devices['Desktop Chrome'],
storageState: AUTH_FILE,
},
testMatch: /logged-in\/.*[.]spec.ts/,
},
],
/**
* webServer: Build and start a local Next.js server.
*
* Configuration:
* - Uses local Supabase (127.0.0.1:54321) for real database testing
* - MSW enabled for GitHub API mocking only (external API stability)
* - APP_ENV=test enables test mode auth bypass
*
* CRITICAL: NEXT_PUBLIC_* vars must be set at BUILD time because Next.js
* inlines them during the build process.
*
* NOTE: reuseExistingServer is set to false to ALWAYS use a fresh server
* with correct test environment variables.
*
* Disabled in parallel mode — the orchestrator manages servers externally.
*/
webServer: isParallelMode
? undefined
: {
command: `pnpm build && pnpm start`,
url: 'http://localhost:3008',
reuseExistingServer: false,
timeout: 120000,
env: {
NEXT_PUBLIC_ENABLE_MSW_MOCK: 'true',
APP_ENV: 'test',
NEXT_PUBLIC_SUPABASE_URL: LOCAL_SUPABASE_URL,
NEXT_PUBLIC_SUPABASE_ANON_KEY: LOCAL_SUPABASE_ANON_KEY,
},
},
})