-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_browser_runtime_e2e.py
More file actions
91 lines (75 loc) · 2.39 KB
/
test_browser_runtime_e2e.py
File metadata and controls
91 lines (75 loc) · 2.39 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
#!/usr/bin/env python3
"""Browser runtime E2E check for render-cadence stability."""
from __future__ import annotations
import os
import subprocess
import sys
MAX_PLAYWRIGHT_ATTEMPTS = 2
def run_command(
command: list[str], env: dict[str, str], timeout: int
) -> subprocess.CompletedProcess[str]:
return subprocess.run(
command,
text=True,
capture_output=True,
env=env,
timeout=timeout,
check=False,
)
def main() -> int:
if os.getenv("PLAYWRIGHT_E2E_ENABLED", "0") != "1":
print('{"status":"skipped","reason":"PLAYWRIGHT_E2E_ENABLED!=1"}')
return 0
env = {
**os.environ,
"CI": os.getenv("CI", "1"),
"FRONTEND_E2E_URL": os.getenv("FRONTEND_E2E_URL", "http://127.0.0.1:4173"),
# Force a slower chart update cadence to make throttle validation deterministic.
"VITE_CHART_THROTTLE_MS": os.getenv("VITE_CHART_THROTTLE_MS", "1000"),
}
# Ensure playwright test runner dependency exists for the local config import.
deps = run_command(
["npm", "install", "--no-save", "@playwright/test@1.52.0"],
env=env,
timeout=600,
)
sys.stdout.write(deps.stdout)
sys.stderr.write(deps.stderr)
if deps.returncode != 0:
return deps.returncode
install = run_command(
["npx", "playwright", "install", "chromium"],
env=env,
timeout=900,
)
sys.stdout.write(install.stdout)
sys.stderr.write(install.stderr)
if install.returncode != 0:
return install.returncode
last_return_code = 1
for attempt in range(1, MAX_PLAYWRIGHT_ATTEMPTS + 1):
test = run_command(
[
"npx",
"playwright",
"test",
"tests/e2e/runtime-cadence.spec.js",
"--config",
"tests/e2e/playwright.config.js",
"--reporter=line",
],
env=env,
timeout=1200,
)
sys.stdout.write(test.stdout)
sys.stderr.write(test.stderr)
if test.returncode == 0:
return 0
last_return_code = test.returncode
if attempt < MAX_PLAYWRIGHT_ATTEMPTS:
print(
f"Playwright runtime-cadence attempt {attempt} failed; retrying once..."
)
return last_return_code
if __name__ == "__main__":
raise SystemExit(main())