47 lines · 1.4 KB · TypeScript
RawDownload
// @vitest-environment nodeimport { mkdtempSync, rmSync, writeFileSync } from "node:fs";import os from "node:os";import path from "node:path";import { afterEach, describe, expect, it, vi } from "vitest"; const execFileAsyncMock = vi.fn();const accessMock = vi.fn(); vi.mock("node:child_process", () => ({	execFile: vi.fn(),})); vi.mock("node:util", () => ({	promisify: vi.fn(() => execFileAsyncMock),})); vi.mock("node:fs/promises", () => ({	access: accessMock,})); describe("bird command Effect boundary", () => {	afterEach(() => {		vi.resetModules();		execFileAsyncMock.mockReset();		accessMock.mockReset();		delete process.env.BIRDCLAW_BIRD_COMMAND;		delete process.env.BIRDCLAW_CONFIG;	}); 	it("returns a rejected promise instead of throwing synchronously on config parse failures", async () => {		const tempDir = mkdtempSync(path.join(os.tmpdir(), "birdclaw-command-"));		const configPath = path.join(tempDir, "config.json");		writeFileSync(configPath, "{bad json", "utf8");		process.env.BIRDCLAW_CONFIG = configPath;		const { runBirdCommand } = await import("./bird-command");		let promise: Promise<unknown> | undefined; 		expect(() => {			promise = runBirdCommand(["version"]);		}).not.toThrow();		await expect(promise).rejects.toThrow(/JSON/);		expect(execFileAsyncMock).not.toHaveBeenCalled(); 		rmSync(tempDir, { recursive: true, force: true });	});});

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t