|
| 1 | +import { describe, expect, test } from "vitest"; |
| 2 | +import { experimental_getWranglerCommands } from "../experimental-commands-api"; |
| 3 | + |
| 4 | +describe("experimental_getWranglerCommands", () => { |
| 5 | + test("returns command tree structure", () => { |
| 6 | + const commandTree = experimental_getWranglerCommands(); |
| 7 | + |
| 8 | + expect(commandTree).toBeDefined(); |
| 9 | + expect(commandTree.subtree).toBeInstanceOf(Map); |
| 10 | + }); |
| 11 | + |
| 12 | + test("includes expected commands with metadata", () => { |
| 13 | + const commandTree = experimental_getWranglerCommands(); |
| 14 | + |
| 15 | + expect(commandTree.subtree.has("docs")).toBe(true); |
| 16 | + expect(commandTree.subtree.has("init")).toBe(true); |
| 17 | + expect(commandTree.subtree.has("dev")).toBe(true); |
| 18 | + expect(commandTree.subtree.has("deploy")).toBe(true); |
| 19 | + |
| 20 | + const docsCommand = commandTree.subtree.get("docs"); |
| 21 | + expect(docsCommand?.definition?.metadata).toBeDefined(); |
| 22 | + expect(docsCommand?.definition?.metadata?.description).toBeDefined(); |
| 23 | + expect(docsCommand?.definition?.metadata?.status).toBeDefined(); |
| 24 | + }); |
| 25 | + |
| 26 | + test("includes nested commands", () => { |
| 27 | + const commandTree = experimental_getWranglerCommands(); |
| 28 | + |
| 29 | + const d1Command = commandTree.subtree.get("d1"); |
| 30 | + expect(d1Command?.subtree).toBeInstanceOf(Map); |
| 31 | + expect(d1Command?.subtree.has("list")).toBe(true); |
| 32 | + expect(d1Command?.subtree.has("create")).toBe(true); |
| 33 | + expect(d1Command?.subtree.has("delete")).toBe(true); |
| 34 | + }); |
| 35 | + |
| 36 | + test("includes command arguments and metadata", () => { |
| 37 | + const commandTree = experimental_getWranglerCommands(); |
| 38 | + |
| 39 | + const initCommand = commandTree.subtree.get("init"); |
| 40 | + expect(initCommand?.definition?.type).toBe("command"); |
| 41 | + if (initCommand?.definition?.type === "command") { |
| 42 | + expect(initCommand.definition.metadata).toBeDefined(); |
| 43 | + expect(initCommand.definition.metadata.description).toBeDefined(); |
| 44 | + expect(initCommand.definition.metadata.status).toBeDefined(); |
| 45 | + expect(initCommand.definition.metadata.owner).toBeDefined(); |
| 46 | + } |
| 47 | + }); |
| 48 | + |
| 49 | + test("includes namespace commands", () => { |
| 50 | + const commandTree = experimental_getWranglerCommands(); |
| 51 | + |
| 52 | + const kvCommand = commandTree.subtree.get("kv"); |
| 53 | + expect(kvCommand?.definition?.type).toBe("namespace"); |
| 54 | + expect(kvCommand?.subtree).toBeInstanceOf(Map); |
| 55 | + expect(kvCommand?.subtree.has("namespace")).toBe(true); |
| 56 | + expect(kvCommand?.subtree.has("key")).toBe(true); |
| 57 | + }); |
| 58 | + |
| 59 | + test("preserves command metadata properties", () => { |
| 60 | + const commandTree = experimental_getWranglerCommands(); |
| 61 | + |
| 62 | + const deployCommand = commandTree.subtree.get("deploy"); |
| 63 | + if (deployCommand?.definition?.type === "command") { |
| 64 | + const metadata = deployCommand.definition.metadata; |
| 65 | + expect(metadata.description).toBeDefined(); |
| 66 | + expect(metadata.status).toBeDefined(); |
| 67 | + expect(metadata.owner).toBeDefined(); |
| 68 | + expect(typeof metadata.description).toBe("string"); |
| 69 | + expect([ |
| 70 | + "experimental", |
| 71 | + "alpha", |
| 72 | + "private-beta", |
| 73 | + "open-beta", |
| 74 | + "stable", |
| 75 | + ]).toContain(metadata.status); |
| 76 | + } |
| 77 | + }); |
| 78 | +}); |
0 commit comments