2
0

command-integration.spec.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import * as path from "path"
  2. import { getCommands, getCommand, getCommandNames } from "../services/command/commands"
  3. describe("Command Integration Tests", () => {
  4. const testWorkspaceDir = path.join(__dirname, "../../")
  5. it("should discover command files in .roo/commands/", async () => {
  6. const commands = await getCommands(testWorkspaceDir)
  7. // Should be able to discover commands (may be empty in test environment)
  8. expect(Array.isArray(commands)).toBe(true)
  9. // If commands exist, verify they have valid properties
  10. commands.forEach((command) => {
  11. expect(command.name).toBeDefined()
  12. expect(typeof command.name).toBe("string")
  13. expect(command.source).toMatch(/^(project|global|built-in)$/)
  14. expect(command.content).toBeDefined()
  15. expect(typeof command.content).toBe("string")
  16. })
  17. })
  18. it("should return command names correctly", async () => {
  19. const commandNames = await getCommandNames(testWorkspaceDir)
  20. // Should return an array (may be empty in test environment)
  21. expect(Array.isArray(commandNames)).toBe(true)
  22. // If command names exist, they should be strings
  23. commandNames.forEach((name) => {
  24. expect(typeof name).toBe("string")
  25. expect(name.length).toBeGreaterThan(0)
  26. })
  27. })
  28. it("should load command content if commands exist", async () => {
  29. const commands = await getCommands(testWorkspaceDir)
  30. if (commands.length > 0) {
  31. const firstCommand = commands[0]
  32. const loadedCommand = await getCommand(testWorkspaceDir, firstCommand.name)
  33. expect(loadedCommand).toBeDefined()
  34. expect(loadedCommand?.name).toBe(firstCommand.name)
  35. expect(loadedCommand?.source).toMatch(/^(project|global|built-in)$/)
  36. expect(loadedCommand?.content).toBeDefined()
  37. expect(typeof loadedCommand?.content).toBe("string")
  38. }
  39. })
  40. it("should handle non-existent commands gracefully", async () => {
  41. const nonExistentCommand = await getCommand(testWorkspaceDir, "non-existent-command")
  42. expect(nonExistentCommand).toBeUndefined()
  43. })
  44. })