45 lines
1.6 KiB
Python
45 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Render a per-frontend test table from vitest JSON reports for a Gitea job summary (#136).
|
|
|
|
Reads every *.json in the given directory (default: test-output), each written by an app's
|
|
`test` target (reporters: json, outputFile: {workspaceRoot}/test-output/{projectName}.json), and
|
|
prints a markdown table to stdout — one row per frontend app. The CI step redirects it into
|
|
$GITHUB_STEP_SUMMARY. Stdlib only.
|
|
"""
|
|
import glob
|
|
import json
|
|
import os
|
|
import sys
|
|
|
|
|
|
def main(results_dir):
|
|
rows = []
|
|
for path in sorted(glob.glob(os.path.join(results_dir, "*.json"))):
|
|
try:
|
|
with open(path) as fh:
|
|
d = json.load(fh)
|
|
except (OSError, ValueError):
|
|
continue
|
|
rows.append({
|
|
"name": os.path.splitext(os.path.basename(path))[0],
|
|
"passed": d.get("numPassedTests", 0),
|
|
"failed": d.get("numFailedTests", 0),
|
|
"skipped": d.get("numPendingTests", 0) + d.get("numTodoTests", 0),
|
|
"total": d.get("numTotalTests", 0),
|
|
"ok": d.get("success", False),
|
|
})
|
|
if not rows:
|
|
print("_No frontend test results found._")
|
|
return 0
|
|
print("## 🅰️ Frontend tests\n")
|
|
print("| Frontend | Result | Passed | Failed | Skipped | Total |")
|
|
print("| -------- | :----: | -----: | -----: | ------: | ----: |")
|
|
for r in rows:
|
|
status = "✅" if r["ok"] and not r["failed"] else "❌"
|
|
print(f"| {r['name']} | {status} | {r['passed']} | {r['failed']} | {r['skipped']} | {r['total']} |")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main(sys.argv[1] if len(sys.argv) > 1 else "test-output"))
|