run.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. ArozOS E2E runner.
  3. Orchestrates two Playwright suites:
  4. static specs/ Cine Studio front-end specs, served by a
  5. plain static file server (no Go involved).
  6. system specs-system/ Full-stack critical-path specs (auth,
  7. desktop, file explorer, system settings,
  8. user management) driven against a real
  9. ArozOS server booted from the Go binary.
  10. Each spec runs in its own Node process; the runner exits non-zero if
  11. any spec fails, so CI turns red on the first regression.
  12. Env:
  13. E2E_SUITE which suite(s) to run: "static", "system" or "all"
  14. (default "all")
  15. WEB_PORT port for the static server (default 8123)
  16. AROZ_PORT port for the ArozOS test instance (default 8126)
  17. AROZOS_BIN prebuilt arozos binary (default src/arozos, built with
  18. `go build` when missing)
  19. */
  20. "use strict";
  21. const path = require("path");
  22. const fs = require("fs");
  23. const { spawn } = require("child_process");
  24. const staticServer = require("./lib/static-server");
  25. const arozosServer = require("./lib/arozos-server");
  26. const WEB_ROOT = path.resolve(__dirname, "../../../src/web");
  27. const STATIC_SPECS_DIR = path.join(__dirname, "specs");
  28. const SYSTEM_SPECS_DIR = path.join(__dirname, "specs-system");
  29. function runSpec(specPath, extraEnv) {
  30. return new Promise(function (resolve) {
  31. const child = spawn(process.execPath, [specPath], {
  32. stdio: "inherit",
  33. env: Object.assign({}, process.env, extraEnv)
  34. });
  35. child.on("exit", function (code) { resolve(code || 0); });
  36. });
  37. }
  38. function listSpecs(dir) {
  39. if (!fs.existsSync(dir)) { return []; }
  40. return fs.readdirSync(dir)
  41. .filter(function (f) { return f.endsWith(".js"); })
  42. .sort()
  43. .map(function (f) { return path.join(dir, f); });
  44. }
  45. async function runSuite(title, specs, extraEnv) {
  46. let failures = 0;
  47. for (const spec of specs) {
  48. console.log("── [" + title + "] " + path.basename(spec) + " ──────────────────────────");
  49. const code = await runSpec(spec, extraEnv);
  50. if (code !== 0) { failures++; console.log(" spec exited with code " + code); }
  51. console.log("");
  52. }
  53. return failures;
  54. }
  55. (async function () {
  56. const suite = (process.env.E2E_SUITE || "all").toLowerCase();
  57. let totalSpecs = 0;
  58. let totalFailures = 0;
  59. // ── Static suite (Cine Studio) ──
  60. if (suite === "all" || suite === "static") {
  61. if (!fs.existsSync(path.join(WEB_ROOT, "Cine Studio", "index.html"))) {
  62. console.error("Cannot find Cine Studio web app under " + WEB_ROOT);
  63. process.exit(1);
  64. }
  65. const specs = listSpecs(STATIC_SPECS_DIR);
  66. totalSpecs += specs.length;
  67. const { server, baseURL } = await staticServer.start(WEB_ROOT, Number(process.env.WEB_PORT) || 8123);
  68. console.log("Serving " + WEB_ROOT + " at " + baseURL + " (static suite)\n");
  69. totalFailures += await runSuite("static", specs, { CS_BASE_URL: baseURL });
  70. server.close();
  71. }
  72. // ── System suite (real ArozOS server) ──
  73. if (suite === "all" || suite === "system") {
  74. const specs = listSpecs(SYSTEM_SPECS_DIR);
  75. totalSpecs += specs.length;
  76. if (specs.length) {
  77. console.log("Booting ArozOS test instance (system suite)...");
  78. const srv = await arozosServer.start({});
  79. console.log("ArozOS test instance ready at " + srv.baseURL + "\n");
  80. try {
  81. totalFailures += await runSuite("system", specs, {
  82. AROZ_BASE_URL: srv.baseURL,
  83. AROZ_ADMIN_USER: srv.admin.username,
  84. AROZ_ADMIN_PASS: srv.admin.password
  85. });
  86. } finally {
  87. await srv.stop();
  88. }
  89. }
  90. }
  91. if (totalFailures) {
  92. console.error(totalFailures + " of " + totalSpecs + " spec file(s) failed.");
  93. process.exit(1);
  94. }
  95. console.log("All " + totalSpecs + " spec file(s) passed.");
  96. })().catch(function (e) {
  97. console.error(e);
  98. process.exit(1);
  99. });