e2eSpecResolution.test.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
  2. import { tmpdir } from "node:os";
  3. import { dirname, join } from "node:path";
  4. import { describe, expect, it } from "vitest";
  5. import {
  6. assertNonEmptyE2EScheduledSpecFiles,
  7. resolveE2EScheduledSpecFiles,
  8. } from "./e2e/helpers/e2e-spec-resolution.js";
  9. function writeSpec(baseDir: string, relativePath: string): void {
  10. const path = join(baseDir, ...relativePath.split("/"));
  11. mkdirSync(dirname(path), { recursive: true });
  12. writeFileSync(path, "describe('x', () => {});\n");
  13. }
  14. function withFixture<T>(run: (baseDir: string) => T): T {
  15. const baseDir = mkdtempSync(join(tmpdir(), "zcode-e2e-spec-resolution-"));
  16. try {
  17. return run(baseDir);
  18. } finally {
  19. rmSync(baseDir, { recursive: true, force: true });
  20. }
  21. }
  22. describe("E2E spec scheduling resolution", () => {
  23. it("resolves the formal non-recursive conversation-session CI glob", () => {
  24. withFixture((baseDir) => {
  25. writeSpec(baseDir, "test/e2e/conversation-session/formal-a.test.ts");
  26. writeSpec(baseDir, "test/e2e/conversation-session/formal-b.test.ts");
  27. writeSpec(baseDir, "test/e2e/conversation-session/manual-review/pending/manual.test.ts");
  28. expect(
  29. resolveE2EScheduledSpecFiles({
  30. baseDir,
  31. specs: ["./test/e2e/conversation-session/*.test.ts"],
  32. exclude: [],
  33. }),
  34. ).toEqual([
  35. "test/e2e/conversation-session/formal-a.test.ts",
  36. "test/e2e/conversation-session/formal-b.test.ts",
  37. ]);
  38. });
  39. });
  40. it("resolves a formal desktop CI spec list with a domain-specific single spec", () => {
  41. withFixture((baseDir) => {
  42. writeSpec(baseDir, "test/e2e/conversation-session/formal.test.ts");
  43. writeSpec(baseDir, "test/e2e/workspace/files/workspace-file-tree-refresh.test.ts");
  44. expect(
  45. resolveE2EScheduledSpecFiles({
  46. baseDir,
  47. specs: [
  48. "./test/e2e/conversation-session/*.test.ts",
  49. "./test/e2e/workspace/files/workspace-file-tree-refresh.test.ts",
  50. ],
  51. exclude: [],
  52. }),
  53. ).toEqual([
  54. "test/e2e/conversation-session/formal.test.ts",
  55. "test/e2e/workspace/files/workspace-file-tree-refresh.test.ts",
  56. ]);
  57. });
  58. });
  59. it("applies recursive exclude globs before reporting scheduled specs", () => {
  60. withFixture((baseDir) => {
  61. writeSpec(baseDir, "test/e2e/conversation-session/formal.test.ts");
  62. writeSpec(baseDir, "test/e2e/conversation-session/manual-review/pending/manual.test.ts");
  63. expect(
  64. resolveE2EScheduledSpecFiles({
  65. baseDir,
  66. specs: ["./test/e2e/**/*.test.ts"],
  67. exclude: ["./test/e2e/conversation-session/manual-review/**/*.test.ts"],
  68. }),
  69. ).toEqual(["test/e2e/conversation-session/formal.test.ts"]);
  70. });
  71. });
  72. it("throws a pre-worker diagnostic when no spec files are scheduled", () => {
  73. withFixture((baseDir) => {
  74. expect(() =>
  75. assertNonEmptyE2EScheduledSpecFiles({
  76. baseDir,
  77. specs: ["./test/e2e/conversation-session/*.test.ts"],
  78. exclude: [],
  79. requestedSpecs: ["./test/e2e/conversation-session/*.test.ts"],
  80. envSpec: "./test/e2e/conversation-session/*.test.ts",
  81. argv: [
  82. "run",
  83. "wdio.conf.ts",
  84. "--",
  85. "--spec",
  86. "./test/e2e/conversation-session/*.test.ts",
  87. ],
  88. }),
  89. ).toThrow(/Desktop E2E has no scheduled spec files after applying excludes/);
  90. });
  91. });
  92. });