forked from sjkelleyjr/trimmr
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplaywright.config.ts
More file actions
126 lines (117 loc) · 3.6 KB
/
Copy pathplaywright.config.ts
File metadata and controls
126 lines (117 loc) · 3.6 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
import fs from 'node:fs'
import os from 'node:os'
import path from 'node:path'
import { defineConfig, devices } from '@playwright/test'
/**
* Sandboxes (e.g. Cursor) may set PLAYWRIGHT_BROWSERS_PATH to an empty cache while
* `playwright install` already populated ~/Library/Caches/ms-playwright (macOS) or
* ~/.cache/ms-playwright (Linux). Point at the real cache so WebKit does not need a
* second download.
*
* Playwright has no --browsers-path flag; to force a path from the shell use:
* `PLAYWRIGHT_BROWSERS_PATH=/path/to/ms-playwright npx playwright test …`
*/
function ensurePlaywrightBrowsersPath(): void {
const standard =
process.platform === 'darwin'
? path.join(os.homedir(), 'Library', 'Caches', 'ms-playwright')
: path.join(os.homedir(), '.cache', 'ms-playwright')
function cacheHasPlaywrightBrowsers(root: string): boolean {
try {
return fs.readdirSync(root).some((name) =>
/^(chromium|chromium_headless_shell|webkit|firefox)/.test(name),
)
} catch {
return false
}
}
const current = process.env.PLAYWRIGHT_BROWSERS_PATH
if (current && cacheHasPlaywrightBrowsers(current)) {
return
}
if (current) {
const looksBroken =
current.includes('cursor-sandbox') ||
current.includes('sandbox-cache') ||
!cacheHasPlaywrightBrowsers(current)
if (looksBroken && cacheHasPlaywrightBrowsers(standard)) {
process.env.PLAYWRIGHT_BROWSERS_PATH = standard
return
}
}
if (!current && cacheHasPlaywrightBrowsers(standard)) {
process.env.PLAYWRIGHT_BROWSERS_PATH = standard
}
}
ensurePlaywrightBrowsersPath()
/** Dev server + tests: capture export blobs for assertions when Firefox omits the download event. */
process.env.VITE_PLAYWRIGHT_EXPORT_HOOK ??= '1'
/** Mobile-focused specs (viewport + export); keeps mobile CI fast vs full editor matrix. */
const mobileOnlyGlobs = ['**/mobile-overflow.spec.ts', '**/mobile-export.spec.ts']
export default defineConfig({
testDir: './apps/web/tests',
timeout: 900_000,
expect: { timeout: 30_000 },
workers: 1,
fullyParallel: false,
use: {
baseURL: 'http://127.0.0.1:4173',
headless: true,
actionTimeout: 30_000,
},
projects: [
{
name: 'chrome-desktop',
use: {
channel: 'chrome',
},
testIgnore: '**/mobile-export.spec.ts',
},
{
name: 'firefox-desktop',
use: {
...devices['Desktop Firefox'],
launchOptions: {
firefoxUserPrefs: {
// Headless Gecko is strict about media; keep decode + autoplay permissive for preview/export tests.
'media.autoplay.default': 0,
'media.autoplay.blocking_policy': 0,
'media.mediasource.enabled': true,
},
},
},
testIgnore: '**/mobile-export.spec.ts',
},
{
name: 'mobile-chrome',
use: {
...devices['Pixel 5'],
},
testMatch: mobileOnlyGlobs,
},
{
name: 'mobile-safari',
use: {
...devices['iPhone 12'],
},
testMatch: mobileOnlyGlobs,
},
{
name: 'webkit-desktop',
use: {
...devices['Desktop Safari'],
},
testMatch: '**/fixture-matrix.spec.ts',
},
],
webServer: {
command: 'npm run dev -w apps/web -- --host 127.0.0.1 --port 4173',
port: 4173,
// Reusing a manually started dev server can omit VITE_PLAYWRIGHT_EXPORT_HOOK, breaking Firefox
// export tests that rely on __PLAYWRIGHT_LAST_EXPORT. CI always boots a fresh server with env below.
reuseExistingServer: !process.env.CI,
env: {
VITE_PLAYWRIGHT_EXPORT_HOOK: '1',
},
},
})