workflows.test.ts 1.2 KB

123456789101112131415161718192021222324252627282930
  1. import { readdirSync, readFileSync } from "node:fs";
  2. import { dirname, join } from "node:path";
  3. import { fileURLToPath } from "node:url";
  4. import { describe, expect, it } from "vitest";
  5. import { compileWorkflowScript } from "../src/index.js";
  6. import { diffAgainstMarkers, parseExpectedErrors } from "./helpers/markers.js";
  7. // Fixture-driven compiler tests: every tests/workflows/*.ts file is compiled;
  8. // trailing `// error` markers state the expected diagnostics (see helpers/markers.ts).
  9. const workflowsDir = join(dirname(fileURLToPath(import.meta.url)), "workflows");
  10. describe("workflow fixtures", () => {
  11. const fixtures = readdirSync(workflowsDir)
  12. .filter((name) => name.endsWith(".ts"))
  13. .sort();
  14. it("finds fixtures", () => {
  15. expect(fixtures.length).toBeGreaterThan(0);
  16. });
  17. for (const fixture of fixtures) {
  18. it(fixture, () => {
  19. const source = readFileSync(join(workflowsDir, fixture), "utf8");
  20. const expected = parseExpectedErrors(source);
  21. const result = compileWorkflowScript(source);
  22. expect(diffAgainstMarkers(expected, result.diagnostics)).toEqual([]);
  23. expect(result.ok).toBe(expected.size === 0);
  24. });
  25. }
  26. });