-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathplaywright.config.ts
More file actions
353 lines (313 loc) · 12.1 KB
/
Copy pathplaywright.config.ts
File metadata and controls
353 lines (313 loc) · 12.1 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
// ███████╗██╗ ██╗ █████╗ ███╗ ███╗██████╗ ██╗ ███████╗███████╗
// ██╔════╝╚██╗██╔╝██╔══██╗████╗ ████║██╔══██╗██║ ██╔════╝██╔════╝
// █████╗ ╚███╔╝ ███████║██╔████╔██║██████╔╝██║ █████╗ ███████╗
// ██╔══╝ ██╔██╗ ██╔══██║██║╚██╔╝██║██╔═══╝ ██║ ██╔══╝ ╚════██║
// ███████╗██╔╝ ██╗██║ ██║██║ ╚═╝ ██║██║ ███████╗███████╗███████║
// ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚══════╝╚══════╝╚══════╝
import {defineConfig, devices} from '@playwright/test'
const isHeadless = process.env.HEADLESS === 'true'
// Slug prefixes claimed by the context-scoped projects below. Each prefix
// claims the exact slug and any `<prefix>-*` variant. The `other` project
// collects every template.spec.ts whose slug no prefix claims, so a new
// template is tested by default instead of silently skipped.
// scripts/get-examples-for-project.mjs derives the CI build list from the
// same rule and scripts/assert-spec-coverage.mjs fails the build when a
// spec file still ends up matched by no project.
const claimedSlugPrefixes = [
'content',
'sidebar',
'action',
'newtab',
'special-folders',
'javascript',
'preact',
'react',
'svelte',
'typescript',
'vue'
]
const unclaimedTemplateSpec = new RegExp(
`examples/(?!(?:${claimedSlugPrefixes.join('|')})(?:-[^/]*)?/)` +
`[^/]+/template\\.spec\\.ts$`
)
/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// import dotenv from 'dotenv';
// dotenv.config({ path: path.resolve(__dirname, '.env') });
/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
// Pre-build every template referenced by the assets suite BEFORE workers
// start. resolveBuiltExtensionPath() shells out to the CLI at module-load
// time when dist/ is missing, and with 4 parallel workers re-importing the
// same spec the concurrent builds race and produce partial dist/ writes
// (observed as "manifest missing" chrome errors). Serial prebuild is the
// only reliable way to eliminate the race.
globalSetup: './scripts/prebuild-assets-templates.mjs',
// Reasonable timeout for CI environments
timeout: process.env.CI ? 60_000 : 30_000,
testDir: './examples',
// Global timeout to prevent worker teardown timeouts
globalTimeout: process.env.CI ? 1800_000 : 900_000, // 30 min CI, 15 min local
// Expect timeout for assertions
expect: {
timeout: process.env.CI ? 20_000 : 10_000
},
// Enable parallel execution for faster test runs
fullyParallel: true,
// Prevent accidental test.only commits
forbidOnly: !!process.env.CI,
// CI: 2 retries absorb transient failures. Local: 1 retry for faster iteration.
retries: process.env.CI ? 2 : 1,
// CI: 2 workers to avoid OOM with headed browsers. Local: 4 for speed.
// repeat-each forces 1: Playwright's worker hash includes repeatEachIndex,
// so repeats of one suite run concurrently and clobber the shared template
// sources that the dev-live tests edit in place.
workers: process.argv.some((arg) => arg.startsWith('--repeat-each'))
? 1
: process.env.CI
? 2
: 4,
// CI gets machine-readable JSON; locally just list + HTML report.
reporter: process.env.CI
? [
['list'],
['html', {outputFolder: 'e2e-report'}],
['json', {outputFile: 'test-results.json'}]
]
: [['list'], ['html', {outputFolder: 'e2e-report'}]],
use: {
// Respect HEADLESS environment variable, default to false (headed mode) for better extension compatibility
// Content scripts inject more reliably in headed mode
// In CI, use headless mode unless HEADLESS=false is explicitly set (requires xvfb-run)
// Extensions load reliably only in headed mode.
// Use HEADLESS=true explicitly when needed.
headless: isHeadless,
// Collect traces only on failure for better performance
trace: 'retain-on-failure',
// Capture media for all test failures
screenshot: 'only-on-failure',
video: 'retain-on-failure',
// Timeouts for network operations
actionTimeout: process.env.CI ? 30000 : 20000,
navigationTimeout: process.env.CI ? 60000 : 30000,
// Stable viewport
viewport: {width: 1280, height: 720},
// Remove slowMo for faster execution
launchOptions: {
// No slowMo - removed for performance
},
// Better error handling
ignoreHTTPSErrors: true
},
// Batch-based test execution for better performance
// Each batch runs tests for a specific extension context type
projects: [
// Content Scripts Batch - Tests that inject into web pages
{
name: 'content',
testMatch: /examples\/(content|content-.*)\/.*\.spec\.ts$/,
use: {
...devices['Desktop Chrome'],
headless: isHeadless
}
},
{
name: 'dev-live',
testMatch: /examples\/template\.dev\.spec\.ts$/,
// Same reason as `reload` below: every describe here starts its own
// `extension dev`, so running two at once leaves file watchers and
// browsers competing until a later context launch starves and the
// worker teardown times out. Retries do not help once that happens.
fullyParallel: false,
use: {
...devices['Desktop Chrome'],
headless: isHeadless
}
},
{
name: 'reload',
testMatch: /examples\/template\.reload\.spec\.ts$/,
// Disable parallel test execution: reload tests start dev servers
// and run builds that share the Extension.js CLI process.
fullyParallel: false,
use: {
...devices['Desktop Chrome'],
headless: isHeadless
}
},
// Content-script hot-reload regression gate. Parameterized over every
// example with `content_scripts` in its manifest. Each test launches a
// real `extension dev`, connects Playwright to that Chrome via CDP, and
// asserts that a source edit propagates to an already-open tab WITHOUT
// navigation. This is the only suite that exercises the full dev → CDP
// → open-tab reinject chain end-to-end.
{
name: 'content-reload',
testMatch: /examples\/template\.content-reload\.spec\.ts$/,
fullyParallel: false,
use: {
...devices['Desktop Chrome'],
headless: isHeadless
}
},
// `extension dev --no-browser` content-script reload gate. The controller-
// less counterpart to `content-reload`: loads the built dist into an
// independent Playwright Chrome and asserts an edit re-injects into the open
// tab IN PLACE via the control bridge (dev server -> SW producer ->
// chrome.scripting.executeScript) — no CDP controller, no manual page reload.
// Also live-proves the content script self-mounts under --no-browser.
{
name: 'no-browser-content-reload',
testMatch: /examples\/template\.no-browser-content-reload\.spec\.ts$/,
fullyParallel: false,
use: {
...devices['Desktop Chrome'],
headless: isHeadless
}
},
// Deterministic launched-Chromium content reload gate. Launches a real
// Chrome via `extension dev`, attaches Playwright over CDP (connectOverCDP),
// and asserts a JS edit AND a CSS edit propagate into the already-open page
// with no navigation. Unlike `content-reload` (raw CDP tab, flaky CSS), the
// Playwright page is a first-class SW-producer reinject target, so the CSS
// axis is deterministic. Scoped to the canonical `content` example.
{
name: 'launched-content-reload',
testMatch: /examples\/template\.launched-content-reload\.spec\.ts$/,
fullyParallel: false,
use: {
...devices['Desktop Chrome'],
headless: isHeadless
}
},
// Same nine-scenario sequence as `content-reload` but driven against
// real Firefox via the dev process's RDP socket. Spawns
// `extension dev --browser=firefox`, opens a tab via Firefox RDP
// `addTab` against example.com, queries shadow-DOM/computed-style via
// a parallel `evaluateJSAsync`. Covers the same revert + JS/CSS
// syntax-error preservation + post-fix recovery cases as Chromium.
{
name: 'firefox-content-reload',
testMatch: /examples\/template\.firefox-content-reload\.spec\.ts$/,
fullyParallel: false,
use: {
...devices['Desktop Firefox'],
headless: isHeadless
}
},
// Scaffold + install + first build per template
{
name: 'create',
testMatch: /examples\/template\.create\.spec\.ts$/,
use: {
...devices['Desktop Chrome'],
headless: isHeadless
}
},
// Per-template asset pipeline (shadow DOM, CSS, icons, frameworks, SW)
{
name: 'assets',
testMatch: /examples\/template\.assets\.spec\.ts$/,
use: {
...devices['Desktop Chrome'],
headless: isHeadless
}
},
// On-screen render verification for CSS-pipeline content templates
// (real pixels + geometry, catches "tests green but widget not visible")
{
name: 'visual-render',
testMatch: /examples\/template\.visual-render\.spec\.ts$/,
use: {
...devices['Desktop Chrome'],
headless: isHeadless
}
},
// Production build × chrome/edge/firefox with manifest validation
// Includes Firefox-specific manifest key checks and CSS presence assertions
{
name: 'multi-browser',
testMatch: /examples\/template\.multi-browser\.spec\.ts$/,
use: {
...devices['Desktop Chrome'],
headless: isHeadless
}
},
// Sidebar Batch - Tests for sidebar panel functionality
{
name: 'sidebar',
testMatch: /examples\/(sidebar|sidebar-.*)\/.*\.spec\.ts$/,
use: {
...devices['Desktop Chrome'],
headless: isHeadless
}
},
// Action Popup Batch - Tests for action/popup pages
{
name: 'action',
testMatch: /examples\/(action|action-.*)\/.*\.spec\.ts$/,
use: {
...devices['Desktop Chrome'],
headless: isHeadless
}
},
// New Tab Batch - Tests for new tab overrides
{
name: 'newtab',
testMatch: /examples\/(newtab|newtab-.*)\/.*\.spec\.ts$/,
use: {
...devices['Desktop Chrome'],
headless: isHeadless
}
},
// Special Folders Batch - Tests for special folder structures
{
name: 'special-folders',
testMatch: /examples\/special-folders-.*\/.*\.spec\.ts$/,
use: {
...devices['Desktop Chrome'],
headless: isHeadless
}
},
// Mixed Context Tests - Tests that cover both content and sidebar
{
name: 'mixed-context',
testMatch:
/examples\/(javascript|preact|react|svelte|typescript|vue)\/.*\.spec\.ts$/,
use: {
...devices['Desktop Chrome'],
headless: isHeadless
}
},
// Other Tests - catch-all for template specs no slug-scoped project
// above claims (init, playwright, transformers-js, ai-*, and any new
// template until it earns a dedicated project)
{
name: 'other',
testMatch: unclaimedTemplateSpec,
use: {
...devices['Desktop Chrome'],
headless: isHeadless
}
},
// Firefox Runtime - Loads built extensions in Firefox via RDP
{
name: 'firefox',
testMatch: /examples\/template\.firefox\.spec\.ts$/,
use: {
...devices['Desktop Firefox'],
headless: false // Extensions require headed Firefox
}
}
]
/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// url: 'http://127.0.0.1:3000',
// reuseExistingServer: !process.env.CI,
// },
})