import * as path from "node:path"; import { fileURLToPath } from "node:url"; import { describe, expect, it } from "vitest"; import { discoverCapabilities } from "./discover.js"; const EXAMPLES = fileURLToPath(new URL("../../examples/", import.meta.url)); const FIXTURES = fileURLToPath(new URL("../../test/fixtures/", import.meta.url)); describe("discoverCapabilities", () => { it("discovers custom block declaration files as build-only capabilities", async () => { expect(await discoverCapabilities(path.join(FIXTURES, "custom-block"))).toContainEqual({ type: "custom_block", tag: "custom_block", runtime: "build", key: "hello", sourcePath: path.join("src", "customBlocks", "hello.ts"), }); }); it("discovers workflow files", async () => { await expect(discoverCapabilities(path.join(EXAMPLES, "workflow"))).resolves.toEqual([ { type: "workflow", tag: "workflow", runtime: "worker", key: "onPageCreated", sourcePath: path.join("src", "workflows", "onPageCreated.ts"), }, { type: "workflow", tag: "workflow", runtime: "worker", key: "prepareReleases", sourcePath: path.join("src", "workflows", "prepareReleases.ts"), }, { type: "workflow", tag: "workflow", runtime: "worker", key: "shipReleases", sourcePath: path.join("src", "workflows", "shipReleases.ts"), }, ]); }); it("discovers sync files", async () => { await expect(discoverCapabilities(path.join(EXAMPLES, "sync"))).resolves.toEqual([ { type: "sync", tag: "sync", runtime: "worker", key: "issues", sourcePath: path.join("src", "syncs", "issues.ts"), }, { type: "sync", tag: "sync", runtime: "worker", key: "notionAsCodeIssues", sourcePath: path.join("src", "syncs", "notionAsCodeIssues.ts"), }, ]); }); it("returns nothing when no capability directory exists", async () => { expect(await discoverCapabilities(path.join(FIXTURES, "empty"))).toEqual([]); }); });