-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplaywright.config.ts
More file actions
149 lines (138 loc) · 4.92 KB
/
playwright.config.ts
File metadata and controls
149 lines (138 loc) · 4.92 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
import { defineConfig, devices } from '@playwright/test';
/**
* Playwright E2E configuration for wallet stack
*
* Environment Variables:
* - FRONTEND_URL: URL of the wallet-frontend (default: http://localhost:3000)
* - BACKEND_URL: URL of the go-wallet-backend (default: http://localhost:8080)
* - ENGINE_URL: URL of the wallet engine for WebSocket (defaults to BACKEND_URL)
* - ADMIN_URL: URL of the go-wallet-backend admin API (default: http://localhost:8081)
* - TRANSPORT_MODE: Transport to test - 'auto' | 'websocket' | 'http' (default: auto)
* - START_SERVERS: Set to 'true' to auto-start both servers (default: false)
* - FRONTEND_PATH: Path to wallet-frontend repo (for auto-start)
* - BACKEND_PATH: Path to go-wallet-backend repo (for auto-start)
*
* Transport modes:
* - auto: Use best available (WebSocket if supported, else HTTP)
* - websocket: Force WebSocket only (tests skip if unavailable)
* - http: Force HTTP only (even if WebSocket is available)
*
* Running with specific transport:
* TRANSPORT_MODE=http npm test
* TRANSPORT_MODE=websocket npm test
* make test-http
* make test-ws
*
* Running all transport modes:
* make test-all-transports
*
* Example usage:
* # Test against already running servers
* FRONTEND_URL=http://localhost:3000 BACKEND_URL=http://localhost:8080 npm test
*
* # Auto-start servers from local repos
* START_SERVERS=true FRONTEND_PATH=../wallet-frontend BACKEND_PATH=../go-wallet-backend npm test
*/
const FRONTEND_URL = process.env.FRONTEND_URL || 'http://localhost:3000';
const BACKEND_URL = process.env.BACKEND_URL || 'http://localhost:8080';
const ENGINE_URL = process.env.ENGINE_URL || BACKEND_URL;
const ADMIN_URL = process.env.ADMIN_URL || 'http://localhost:8081';
const TRANSPORT_MODE = process.env.TRANSPORT_MODE || 'auto';
const START_SERVERS = process.env.START_SERVERS === 'true';
const FRONTEND_PATH = process.env.FRONTEND_PATH || '../wallet-frontend';
const BACKEND_PATH = process.env.BACKEND_PATH || '../go-wallet-backend';
// Map transport mode to VITE_TRANSPORT_PREFERENCE
function getViteTransportPreference(mode: string): string {
switch (mode.toLowerCase()) {
case 'websocket':
return 'websocket';
case 'http':
return 'http';
case 'auto':
default:
return 'websocket,http';
}
}
// Extract hostname from FRONTEND_URL for RPID
const frontendHostname = new URL(FRONTEND_URL).hostname;
export default defineConfig({
testDir: './specs',
fullyParallel: false, // WebAuthn tests need serial execution
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: 1, // Single worker for WebAuthn session consistency
reporter: [
['html', { open: 'never' }],
['list'],
],
use: {
baseURL: FRONTEND_URL,
trace: 'on-first-retry',
screenshot: 'only-on-failure',
video: 'retain-on-failure',
// Each test gets a clean browser context - no localStorage/cookies from previous tests
storageState: undefined,
},
// Global test timeout
timeout: 60000,
// Expect assertions timeout
expect: {
timeout: 10000,
},
projects: [
{
name: 'chromium',
use: {
...devices['Desktop Chrome'],
},
},
],
// Conditionally start servers if START_SERVERS=true
...(START_SERVERS && {
webServer: [
{
// Start go-wallet-backend first
command: `cd ${BACKEND_PATH} && go run ./cmd/server`,
url: `${BACKEND_URL}/status`,
reuseExistingServer: !process.env.CI,
timeout: 120000,
env: {
WALLET_JWT_SECRET: 'test-secret-for-e2e-testing-minimum-32-chars',
WALLET_SERVER_WEBAUTHN_DISPLAY_NAME: 'Wallet E2E Test',
WALLET_SERVER_RP_ID: frontendHostname,
WALLET_SERVER_RP_ORIGIN: FRONTEND_URL,
WALLET_SERVER_ENABLE_CREDENTIAL_REGISTRATION: 'true',
WALLET_SERVER_REQUIRE_USER_VERIFICATION: 'true',
WALLET_SERVER_TIMEOUT: '60000',
WALLET_SERVER_ATTESTATION: 'none',
WALLET_SERVER_PORT: new URL(BACKEND_URL).port || '8080',
WALLET_LOG_LEVEL: 'info',
// Enable all roles (including engine for WebSocket support)
WALLET_ROLES: 'all',
},
},
{
// Then start the frontend
command: `cd ${FRONTEND_PATH} && npm run start -- --host`,
url: FRONTEND_URL,
reuseExistingServer: !process.env.CI,
timeout: 120000,
env: {
VITE_WALLET_BACKEND_URL: BACKEND_URL,
VITE_WALLET_ENGINE_URL: ENGINE_URL,
VITE_WEBAUTHN_RPID: frontendHostname,
VITE_LOGIN_WITH_PASSWORD: 'false',
// Transport preference based on TRANSPORT_MODE
VITE_TRANSPORT_PREFERENCE: getViteTransportPreference(TRANSPORT_MODE),
},
},
],
}),
});
// Export URLs and config for use in test files
export const config = {
frontendUrl: FRONTEND_URL,
backendUrl: BACKEND_URL,
engineUrl: ENGINE_URL,
transportMode: TRANSPORT_MODE,
};