-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplaywright.config.ts
More file actions
209 lines (196 loc) · 7.08 KB
/
playwright.config.ts
File metadata and controls
209 lines (196 loc) · 7.08 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
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();
require('dotenv').config({ path: '.env.supabase.local', override: true });
/**
* 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 - cleans orphaned e2e-* users before tests */
globalSetup: './tests/e2e/global-setup.ts',
/* Run tests in files in parallel */
fullyParallel: true,
/* 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,
/* Opt out of parallel tests on CI. */
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' }],
],
/* Visual regression snapshot settings */
snapshotDir: './tests/e2e/__snapshots__',
expect: {
toHaveScreenshot: {
maxDiffPixelRatio: 0.01, // Allow 1% pixel difference
threshold: 0.2, // Color threshold per pixel
},
},
/* 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',
/* Note: storageState is set per-project (setup uses base, others use authenticated) */
/* 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 */
actionTimeout: 10000,
/* Global timeout for each test */
navigationTimeout: 30000,
/* Emulate mobile device capabilities */
isMobile: false,
/* Context options */
contextOptions: {
ignoreHTTPSErrors: true,
},
},
/* Configure projects for major browsers */
projects: [
// Auth setup - runs once, saves authenticated state
{
name: 'setup',
testMatch: /auth\.setup\.ts/,
use: {
// Use base storage state (cookie consent only)
storageState: './tests/e2e/fixtures/storage-state.json',
},
},
// Unauthenticated tests (signup, login flows, rate-limiting, public profiles) - no auth dependency
{
name: 'chromium-noauth',
testMatch:
/auth\/(sign-up|user-registration|rate-limiting)\.spec\.ts|company\/company-profile-public\.spec\.ts|worker\/(worker-profile-public|workers-filter)\.spec\.ts/,
use: {
...devices['Desktop Chrome'],
storageState: './tests/e2e/fixtures/storage-state.json',
},
},
// Browser projects depend on setup, use authenticated state
{
name: 'chromium',
testIgnore:
/auth\/(sign-up|user-registration|rate-limiting)\.spec\.ts|company\/company-profile-public\.spec\.ts|worker\/(worker-profile-public|workers-filter)\.spec\.ts/,
use: {
...devices['Desktop Chrome'],
storageState: './tests/e2e/fixtures/storage-state-auth.json',
},
dependencies: ['setup'],
},
{
name: 'firefox',
testIgnore:
/auth\/(sign-up|user-registration|rate-limiting)\.spec\.ts|company\/company-profile-public\.spec\.ts|worker\/(worker-profile-public|workers-filter)\.spec\.ts|map\.spec\.ts|mobile-check\.spec\.ts/,
// map.spec.ts: MapLibre GL requires WebGL — CI runners have no GPU, firefox has no software fallback
// (chromium/webkit have software WebGL; firefox doesn't — verified with firefoxUserPrefs force-enable)
// mobile-check.spec.ts: Playwright firefox rejects isMobile context option (driver limitation)
// 1 retry (vs chromium's 2) — firefox is 2-3x slower
retries: process.env.CI ? 1 : 0,
use: {
...devices['Desktop Firefox'],
storageState: './tests/e2e/fixtures/storage-state-auth.json',
// Firefox needs longer action timeout for navigation tracking
actionTimeout: 15000,
},
dependencies: ['setup'],
},
{
name: 'webkit',
testIgnore:
/auth\/(sign-up|user-registration|rate-limiting)\.spec\.ts|company\/company-profile-public\.spec\.ts|worker\/(worker-profile-public|workers-filter)\.spec\.ts/,
// 1 retry (vs chromium's 2) — webkit is 2-3x slower, shard 2/4 hits 75min timeout
retries: process.env.CI ? 1 : 0,
use: {
...devices['Desktop Safari'],
storageState: './tests/e2e/fixtures/storage-state-auth.json',
// WebKit is slower with client-side hydration and session validation
actionTimeout: 15000,
navigationTimeout: 45000,
},
dependencies: ['setup'],
},
/* Mobile-first test viewports (PRP-017) */
...TEST_VIEWPORTS.filter((v) => v.category === 'mobile').map(
(viewport) => ({
name: `Mobile - ${viewport.name}`,
use: {
...createDeviceConfig(viewport),
storageState: './tests/e2e/fixtures/storage-state-auth.json',
},
dependencies: ['setup'],
})
),
/* Tablet viewports */
...TEST_VIEWPORTS.filter((v) => v.category === 'tablet').map(
(viewport) => ({
name: `Tablet - ${viewport.name}`,
use: {
...createDeviceConfig(viewport),
storageState: './tests/e2e/fixtures/storage-state-auth.json',
},
dependencies: ['setup'],
})
),
/* 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/',
});