run.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. Cine Studio E2E runner.
  3. Starts a static server for the ArozOS web root, then runs each spec
  4. in its own Node process against it. Exits non-zero if any spec fails,
  5. so CI turns red on the first regression. The banner from each spec's
  6. final assertion is printed inline.
  7. */
  8. "use strict";
  9. const path = require("path");
  10. const fs = require("fs");
  11. const { spawn } = require("child_process");
  12. const staticServer = require("./lib/static-server");
  13. const WEB_ROOT = path.resolve(__dirname, "../../../src/web");
  14. const SPECS_DIR = path.join(__dirname, "specs");
  15. function runSpec(specPath, baseURL) {
  16. return new Promise(function (resolve) {
  17. const child = spawn(process.execPath, [specPath], {
  18. stdio: "inherit",
  19. env: Object.assign({}, process.env, { CS_BASE_URL: baseURL })
  20. });
  21. child.on("exit", function (code) { resolve(code || 0); });
  22. });
  23. }
  24. (async function () {
  25. if (!fs.existsSync(path.join(WEB_ROOT, "Cine Studio", "index.html"))) {
  26. console.error("Cannot find Cine Studio web app under " + WEB_ROOT);
  27. process.exit(1);
  28. }
  29. const specs = fs.readdirSync(SPECS_DIR)
  30. .filter(function (f) { return f.endsWith(".js"); })
  31. .sort();
  32. if (!specs.length) {
  33. console.error("No specs found in " + SPECS_DIR);
  34. process.exit(1);
  35. }
  36. const { server, baseURL } = await staticServer.start(WEB_ROOT, Number(process.env.WEB_PORT) || 8123);
  37. console.log("Serving " + WEB_ROOT + " at " + baseURL + "\n");
  38. let failures = 0;
  39. for (const spec of specs) {
  40. console.log("── " + spec + " ──────────────────────────────────");
  41. const code = await runSpec(path.join(SPECS_DIR, spec), baseURL);
  42. if (code !== 0) { failures++; console.log(" spec exited with code " + code); }
  43. console.log("");
  44. }
  45. server.close();
  46. if (failures) {
  47. console.error(failures + " of " + specs.length + " spec file(s) failed.");
  48. process.exit(1);
  49. }
  50. console.log("All " + specs.length + " spec file(s) passed.");
  51. })().catch(function (e) {
  52. console.error(e);
  53. process.exit(1);
  54. });