|
1 | 1 | import { describe, it, expect } from "bun:test"; |
2 | 2 | import { getFilesForTemplate } from "./init"; |
| 3 | +import { render, BLINK_COMMAND, makeTmpDir, KEY_CODES } from "./lib/terminal"; |
| 4 | +import { join } from "path"; |
| 5 | +import { readFile } from "fs/promises"; |
3 | 6 |
|
4 | 7 | const getFile = (files: Record<string, string>, filename: string): string => { |
5 | 8 | const fileContent = files[filename]; |
@@ -212,3 +215,43 @@ describe("getFilesForTemplate", () => { |
212 | 215 | }); |
213 | 216 | }); |
214 | 217 | }); |
| 218 | + |
| 219 | +describe("init command", () => { |
| 220 | + it("scratch template, happy path", async () => { |
| 221 | + await using tempDir = await makeTmpDir(); |
| 222 | + using term = render(`${BLINK_COMMAND} init`, { cwd: tempDir.path }); |
| 223 | + await term.waitUntil((screen) => screen.includes("Scratch")); |
| 224 | + // by default, the first option should be selected. Scratch is second in the list. |
| 225 | + expect(term.getScreen()).not.toContain("Basic agent with example tool"); |
| 226 | + term.write(KEY_CODES.DOWN); |
| 227 | + await term.waitUntil((screen) => |
| 228 | + screen.includes("Basic agent with example tool") |
| 229 | + ); |
| 230 | + term.write(KEY_CODES.ENTER); |
| 231 | + await term.waitUntil((screen) => |
| 232 | + screen.includes("Which AI provider do you want to use?") |
| 233 | + ); |
| 234 | + term.write(KEY_CODES.ENTER); |
| 235 | + await term.waitUntil((screen) => |
| 236 | + screen.includes("Enter your OpenAI API key:") |
| 237 | + ); |
| 238 | + term.write("sk-test-123"); |
| 239 | + term.write(KEY_CODES.ENTER); |
| 240 | + await term.waitUntil((screen) => |
| 241 | + screen.includes("What package manager do you want to use?") |
| 242 | + ); |
| 243 | + const screen = term.getScreen(); |
| 244 | + expect(screen).toContain("Bun"); |
| 245 | + expect(screen).toContain("NPM"); |
| 246 | + expect(screen).toContain("PNPM"); |
| 247 | + expect(screen).toContain("Yarn"); |
| 248 | + term.write(KEY_CODES.ENTER); |
| 249 | + await term.waitUntil((screen) => |
| 250 | + screen.includes("API key saved to .env.local") |
| 251 | + ); |
| 252 | + await term.waitUntil((screen) => screen.includes("To get started, run:")); |
| 253 | + const envFilePath = join(tempDir.path, ".env.local"); |
| 254 | + const envFileContent = await readFile(envFilePath, "utf-8"); |
| 255 | + expect(envFileContent.split("\n")).toContain("OPENAI_API_KEY=sk-test-123"); |
| 256 | + }); |
| 257 | +}); |
0 commit comments