Files
vscode-cowriting-plugin/test/identity.test.ts
T
2026-06-10 23:00:03 -07:00

26 lines
904 B
TypeScript

import { describe, it, expect, beforeAll, afterAll } from "vitest";
import * as fs from "node:fs";
import * as os from "node:os";
import * as path from "node:path";
import { execFileSync } from "node:child_process";
import { gitUserEmail } from "../src/identity";
let repo: string;
beforeAll(() => {
repo = fs.mkdtempSync(path.join(os.tmpdir(), "cowriting-identity-"));
execFileSync("git", ["init"], { cwd: repo, stdio: "ignore" });
execFileSync("git", ["config", "user.email", "rung@example.org"], { cwd: repo });
});
afterAll(() => fs.rmSync(repo, { recursive: true, force: true }));
describe("gitUserEmail (F5 SLICE-2)", () => {
it("reads the workspace git config user.email", () => {
expect(gitUserEmail(repo)).toBe("rung@example.org");
});
it("fails open (undefined) when git cannot run there", () => {
expect(gitUserEmail("/nonexistent-dir-xyz")).toBeUndefined();
});
});