auth.test.ts 1.0 KB

123456789101112131415161718192021222324252627282930
  1. import { describe, expect, test } from "bun:test"
  2. import path from "node:path"
  3. describe("auth command", () => {
  4. test("registers login", async () => {
  5. const [auth, login] = await Promise.all([cli(["auth", "--help"]), cli(["auth", "login", "--help"])])
  6. expect(auth.exitCode).toBe(0)
  7. expect(auth.stdout).toContain("login")
  8. expect(auth.stdout).toContain("Log in to a well-known authentication provider")
  9. expect(auth.stdout).not.toContain("connect")
  10. expect(login.exitCode).toBe(0)
  11. expect(login.stdout).toContain("opencode auth login [flags] <url>")
  12. expect(login.stdout).toContain("Well-known provider URL")
  13. })
  14. })
  15. async function cli(args: string[]) {
  16. const child = Bun.spawn([process.execPath, "run", "src/index.ts", ...args], {
  17. cwd: path.join(import.meta.dir, ".."),
  18. stdout: "pipe",
  19. stderr: "pipe",
  20. })
  21. const [stdout, stderr, exitCode] = await Promise.all([
  22. new Response(child.stdout).text(),
  23. new Response(child.stderr).text(),
  24. child.exited,
  25. ])
  26. return { stdout, stderr, exitCode }
  27. }