harness.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. Shared harness for the Cine Studio E2E specs.
  3. Each spec is a standalone runnable Node script (so it works both via
  4. `node run.js` and directly, e.g. `CS_BASE_URL=... node specs/functional.js`).
  5. The harness centralizes browser launch, app navigation and the
  6. pass/fail reporting helpers.
  7. Env:
  8. CS_BASE_URL base URL the app is served from (default :8123)
  9. PW_CHROMIUM_PATH optional explicit Chromium binary; otherwise
  10. Playwright resolves its own installed browser
  11. */
  12. "use strict";
  13. const { chromium } = require("playwright");
  14. const BASE = process.env.CS_BASE_URL || "http://127.0.0.1:8123";
  15. const APP_URL = BASE + "/Cine%20Studio/index.html";
  16. function ok(msg) { console.log(" PASS: " + msg); }
  17. function fail(msg) {
  18. console.error(" FAIL: " + msg);
  19. process.exit(1);
  20. }
  21. function launch() {
  22. return chromium.launch({
  23. // Undefined lets Playwright resolve its installed browser (CI);
  24. // set PW_CHROMIUM_PATH to point at a preinstalled binary locally.
  25. executablePath: process.env.PW_CHROMIUM_PATH || undefined,
  26. args: ["--autoplay-policy=no-user-gesture-required"]
  27. });
  28. }
  29. // Open the app and wait until the editor global (CS) has booted.
  30. async function openApp(browser, viewport) {
  31. const page = await browser.newPage({ viewport: viewport || { width: 1280, height: 853 } });
  32. page.on("pageerror", function (e) { console.log(" [pageerror] " + e.message); });
  33. await page.goto(APP_URL, { waitUntil: "networkidle" });
  34. await page.waitForFunction(function () { return window.CS && CS.project; });
  35. return page;
  36. }
  37. // Wrap a spec body: run it, report a banner, exit non-zero on throw.
  38. function run(name, body) {
  39. (async function () {
  40. const browser = await launch();
  41. try {
  42. const page = await openApp(browser);
  43. await body(page, browser);
  44. console.log("ALL " + name + " TESTS PASSED");
  45. } finally {
  46. await browser.close();
  47. }
  48. })().catch(function (e) {
  49. console.error(e);
  50. process.exit(1);
  51. });
  52. }
  53. module.exports = { BASE, APP_URL, ok, fail, launch, openApp, run };