Repository navigation
Expand file tree
/
Copy pathplaywright.config.ts
More file actions
206 lines (182 loc) · 7.41 KB
/
Copy pathplaywright.config.ts
File metadata and controls
206 lines (182 loc) · 7.41 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
import { defineConfig, devices } from '@playwright/test';
import path from 'path';
import os from 'os';
/**
* Playwright E2E Test Configuration for eXeLearning
* @see https://playwright.dev/docs/test-configuration
*/
/**
* Detect which projects are being run from command line
* This allows smart server selection:
* - --project=static → only static server (port 3002)
* - --project=chromium/firefox → only dynamic server (port 3001)
* - No --project (run all) → both servers start
*/
const projectArgs = process.argv.filter((arg) => arg.startsWith('--project='));
const requestedProjects = projectArgs.map((arg) => arg.replace('--project=', ''));
const isRunningOnlyStatic = requestedProjects.length > 0 && requestedProjects.every((p) => p === 'static');
const isRunningOnlyDynamic =
requestedProjects.length > 0 && requestedProjects.every((p) => p === 'chromium' || p === 'firefox');
const isRunningMixed = !isRunningOnlyStatic && !isRunningOnlyDynamic;
// Set STATIC_MODE env var for test helpers when running static-only tests
// This allows helpers like gotoWorkarea() to detect static mode and navigate correctly
if (isRunningOnlyStatic) {
process.env.STATIC_MODE = 'true';
}
// Shared environment for dynamic server (chromium/firefox)
const dynamicServerEnv = {
DB_PATH: ':memory:',
// FIX: '/tmp/' usually does not exist on Windows.
// We use the OS temporary folder dynamically.
FILES_DIR: path.join(os.tmpdir(), 'exelearning-e2e'),
PORT: '3001',
APP_PORT: '3001',
APP_AUTH_METHODS: 'password,guest,openid',
OIDC_ISSUER: '',
OIDC_AUTHORIZATION_ENDPOINT: 'https://oidc.example.test/authorize',
OIDC_CLIENT_ID: 'e2e-client',
ADMIN_EMAIL: 'admin@exelearning.test',
ADMIN_PASSWORD: 'AdminPass123!',
ONLINE_THEMES_INSTALL: '1', // Enable theme import for E2E tests
};
// Dynamic server config (used by chromium/firefox projects)
const dynamicWebServer = process.env.E2E_BASE_URL
? undefined
: {
command: 'bun src/index.ts',
url: 'http://localhost:3001/login',
reuseExistingServer: !process.env.CI,
timeout: 120 * 1000, // 2 minutes to start
stdout: 'pipe' as const,
stderr: 'pipe' as const,
env: { ...process.env, ...dynamicServerEnv },
};
// Static server config (port 3002)
const staticWebServer = {
command: 'bun x serve dist/static -p 3002 --no-request-logging',
url: 'http://localhost:3002',
reuseExistingServer: !process.env.CI,
timeout: 120 * 1000, // 2 minutes to start
stdout: 'pipe' as const,
stderr: 'pipe' as const,
};
/**
* Determine which server(s) to start based on requested projects:
* - Only static → static server only
* - Only chromium/firefox → dynamic server only
* - Mixed or no project specified → both servers (array)
*/
function getWebServerConfig() {
if (process.env.E2E_BASE_URL) {
return undefined; // External server, don't start any
}
if (isRunningOnlyStatic) {
return staticWebServer;
}
if (isRunningOnlyDynamic) {
return dynamicWebServer;
}
// Mixed or all projects - start both servers
return [dynamicWebServer, staticWebServer].filter(Boolean);
}
export default defineConfig({
testDir: './test/e2e/playwright/specs',
// Run tests in files in parallel
// Allows tests WITHIN the same file to run simultaneously.
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,
// Number of workers.
//
// Each worker drives a full editor: Chromium (several processes), the Yjs document, a
// Service Worker and the preview iframe. Past roughly four of those in parallel the
// machine stops keeping up and pages start dying mid-test — the symptom is
// `page.reload: Target page, context or browser has been closed`, or a downstream
// `locator.click: Timeout` against a page that is already gone. It reads as flaky
// tests and is really oversubscription.
//
// Measured on a 10-core / 24 GB machine.
//
// `specs/idevices/` (189 tests) — the heaviest cluster:
// 8 workers (the old 80% of cores) → 6 failed, 10.1 min
// 4 workers → 0 failed, 6.3 / 6.6 min on two runs
//
// full suite (492 tests):
// 8 workers → 1, 3 and 4 failed across three runs, 10.0–13.1 min
// 4 workers → 0 failed, 17.5 min
//
// On the heavy cluster fewer workers were faster as well as greener — the machine was
// thrashing. Across the whole suite the trade is real: about six minutes slower, and
// reliable. Six minutes is worth paying for a suite whose failures currently cannot be
// told apart from real regressions.
//
// Hence a hard ceiling of 4 on top of the previous 80% rule: machines with four cores
// or fewer behave exactly as before, larger ones simply stop over-committing.
//
// Deliberately NOT a timeout increase: the pages were dead, so no amount of waiting
// would have helped — it would only have hidden the failure for longer.
//
// CI is untouched. `ubuntu-latest` has 4 cores, so '100%' there already resolves to 4,
// which is why this never reproduced in CI and only bit developer machines.
workers: process.env.CI ? '100%' : Math.min(4, Math.max(1, Math.floor(os.cpus().length * 0.8))),
/* Reporter to use */
reporter: [['html', { outputFolder: 'playwright-report' }], ['github'], ['list']],
/* Shared settings for all the projects below */
use: {
/* Base URL - each project overrides this with its specific URL */
baseURL: process.env.E2E_BASE_URL || 'http://localhost:3001',
/* Collect trace when retrying the failed test */
trace: 'on-first-retry',
/* Capture screenshot on failure */
screenshot: 'only-on-failure',
/* Video recording on failure */
video: 'on-first-retry',
/* Maximum time each action can take */
actionTimeout: 20000,
/* Navigation timeout */
navigationTimeout: 15000,
},
/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: {
...devices['Desktop Chrome'],
baseURL: process.env.E2E_BASE_URL || 'http://localhost:3001',
},
testIgnore: /.*-static\.spec\.ts/,
},
{
name: 'firefox',
use: {
...devices['Desktop Firefox'],
baseURL: process.env.E2E_BASE_URL || 'http://localhost:3001',
serviceWorkers: 'allow',
},
testIgnore: /.*-static\.spec\.ts/,
},
// {
// name: 'webkit',
// use: { ...devices['Desktop Safari'] },
// },
{
name: 'static',
// OIDC requires backend routes (https://github.com/exelearning/exelearning/issues/2377).
testIgnore: /oidc-login\.spec\.ts/,
use: {
...devices['Desktop Chrome'],
baseURL: 'http://localhost:3002',
},
},
],
/* Global webServer - smart selection based on requested projects */
webServer: getWebServerConfig(),
/* Global timeout for each test */
timeout: 45000,
/* Expect timeout */
expect: {
timeout: 7000,
},
});