e2eWindowTargetBinding.test.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import { readFileSync } from "node:fs";
  2. import { describe, expect, it } from "vitest";
  3. import { collectE2EWebDriverPageHandleCandidates } from "./e2e/helpers/e2e-window-target.js";
  4. describe("desktop e2e window target binding", () => {
  5. it("only admits page targets owned by the current ChromeDriver handle table", () => {
  6. expect(
  7. collectE2EWebDriverPageHandleCandidates(
  8. ["app-error-handle", "renderer-handle"],
  9. [
  10. {
  11. id: "app-error-handle",
  12. type: "app",
  13. url: "chrome-error://chromewebdata/",
  14. },
  15. {
  16. id: "renderer-handle",
  17. type: "page",
  18. url: "file:///repo/packages/desktop/out/renderer/index.html",
  19. },
  20. {
  21. id: "stale-cdp-target",
  22. type: "page",
  23. url: "file:///repo/packages/desktop/out/renderer/index.html",
  24. },
  25. ],
  26. ),
  27. ).toEqual([
  28. {
  29. handle: "renderer-handle",
  30. targetUrl: "file:///repo/packages/desktop/out/renderer/index.html",
  31. },
  32. ]);
  33. });
  34. it("does not promote a CDP-only page target to a WebDriver handle", () => {
  35. expect(
  36. collectE2EWebDriverPageHandleCandidates(
  37. ["app-error-handle"],
  38. [
  39. {
  40. id: "renderer-target",
  41. type: "page",
  42. url: "file:///repo/packages/desktop/out/renderer/index.html",
  43. },
  44. ],
  45. ),
  46. ).toEqual([]);
  47. });
  48. it("configures ChromeDriver to exclude Electron's chrome-error app target", () => {
  49. const wdioSource = readFileSync(new URL("../wdio.conf.ts", import.meta.url), "utf8");
  50. expect(wdioSource).toMatch(/windowTypes:\s*\["page"\]/u);
  51. expect(wdioSource).not.toMatch(/windowTypes:\s*\[[^\]]*"app"/u);
  52. });
  53. it("registers renderer preflight as a real Mocha root hook after service setup", () => {
  54. const wdioSource = readFileSync(new URL("../wdio.conf.ts", import.meta.url), "utf8");
  55. const beforeStart = wdioSource.indexOf("\n async before(");
  56. const beforeTestStart = wdioSource.indexOf("\n async beforeTest(");
  57. expect(beforeStart).toBeGreaterThan(-1);
  58. expect(beforeTestStart).toBeGreaterThan(beforeStart);
  59. const beforeSource = wdioSource.slice(beforeStart, beforeTestStart);
  60. expect(beforeSource).toContain("currentE2EWorkerSpecs = specs");
  61. expect(beforeSource).not.toContain("runE2ERendererBridgePreflight");
  62. expect(beforeSource).not.toMatch(/\bbrowser\./u);
  63. expect(wdioSource).not.toContain("\n async beforeSuite(");
  64. expect(wdioSource).toContain("rootHooks: createE2ERendererBridgeRootHooks(");
  65. expect(wdioSource).toMatch(/measureE2ELifecyclePhase\(\s*"before-suite"/u);
  66. expect(wdioSource).toContain("runE2ERendererBridgePreflight(currentE2EWorkerSpecs)");
  67. });
  68. it("surfaces renderer preflight failure without reloading inside the worker hook", () => {
  69. const wdioSource = readFileSync(new URL("../wdio.conf.ts", import.meta.url), "utf8");
  70. const preflightStart = wdioSource.indexOf("async function runE2ERendererBridgePreflight");
  71. const preflightEnd = wdioSource.indexOf(
  72. "async function waitForE2ERendererBridgePreflight",
  73. preflightStart,
  74. );
  75. expect(preflightStart).toBeGreaterThan(-1);
  76. expect(preflightEnd).toBeGreaterThan(preflightStart);
  77. const preflightSource = wdioSource.slice(preflightStart, preflightEnd);
  78. expect(preflightSource).not.toContain("browser.reloadSession()");
  79. expect(preflightSource.match(/waitForE2ERendererBridgePreflight\(\)/gu)).toHaveLength(1);
  80. });
  81. });