forked from exelearning/exelearning
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplaywright.config.ts
More file actions
174 lines (150 loc) · 5.52 KB
/
playwright.config.ts
File metadata and controls
174 lines (150 loc) · 5.52 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
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',
ADMIN_EMAIL: '[email protected]',
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:
// undefined = Let Playwright decide (usually CPU cores / 2).
// 1 = No parallelism (tests run sequentially).
// 4 = Force 4 processes.
// '100%' = Use all available CPU cores.
workers: process.env.CI ? '100%' : '80%',
/* 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',
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,
},
});