mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-25 08:32:45 +00:00
test(cli): the doctor output test no longer runs every machine check (#8497)
* test(cli): the doctor output test prints rows without running every machine check * test(cli): call the row printer directly in the doctor output test
This commit is contained in:
@@ -1,43 +1,29 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { consumeCommandResult } from "../utils/commandResult.js";
|
||||
import { printDoctorOutcomes } from "./doctor.js";
|
||||
|
||||
const ESC = String.fromCharCode(27);
|
||||
const ODD = `od${ESC}[2Jd\x07`;
|
||||
const SHOWN = "od\\x1b[2Jd\\x07";
|
||||
|
||||
vi.mock("../browser/preflight.js", async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import("../browser/preflight.js")>()),
|
||||
runEnvironmentChecks: async () => ({
|
||||
outcomes: [
|
||||
{
|
||||
name: `Tool ${ODD}`,
|
||||
ok: false,
|
||||
level: "error",
|
||||
detail: `not found at ${ODD}\nsecond line`,
|
||||
hint: `install ${ODD}`,
|
||||
},
|
||||
],
|
||||
}),
|
||||
}));
|
||||
|
||||
const { default: doctorCommand } = await import("./doctor.js");
|
||||
|
||||
afterEach(() => {
|
||||
consumeCommandResult();
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
describe("doctor output", () => {
|
||||
// fails without the fix: a check's name, detail and hint are printed as the check returned them.
|
||||
it("shows control characters in a check row as text", async () => {
|
||||
it("shows control characters in a check row as text", () => {
|
||||
const said: string[] = [];
|
||||
vi.spyOn(console, "log").mockImplementation((...args: unknown[]) => {
|
||||
said.push(args.join(" "));
|
||||
});
|
||||
vi.spyOn(console, "error").mockImplementation(() => {});
|
||||
await Promise.resolve(
|
||||
doctorCommand.run?.({ args: { json: false }, rawArgs: [], cmd: doctorCommand } as never),
|
||||
).catch(() => undefined);
|
||||
printDoctorOutcomes([
|
||||
{
|
||||
name: `Tool ${ODD}`,
|
||||
ok: false,
|
||||
detail: `not found at ${ODD}\nsecond line`,
|
||||
hint: `install ${ODD}`,
|
||||
},
|
||||
]);
|
||||
const text = said.join("\n").replace(new RegExp(`${ESC}\\[[0-9;]*m`, "g"), "");
|
||||
expect(text).toContain(`Tool ${SHOWN}`);
|
||||
expect(text).toContain(`not found at ${SHOWN}\nsecond line`);
|
||||
|
||||
@@ -403,6 +403,32 @@ export function buildDoctorReport(outcomes: CheckOutcome[], options: { redact?:
|
||||
});
|
||||
}
|
||||
|
||||
export function printDoctorOutcomes(outcomes: CheckOutcome[]): void {
|
||||
const allOk = outcomes.every((o) => o.ok);
|
||||
console.log();
|
||||
console.log(c.bold("hyperframes doctor"));
|
||||
console.log();
|
||||
|
||||
for (const outcome of outcomes) {
|
||||
const icon = outcome.ok ? c.success("\u2713") : c.error("\u2717");
|
||||
const name = terminalText(outcome.name).padEnd(16);
|
||||
console.log(
|
||||
` ${icon} ${c.bold(name)} ${outcome.ok ? c.dim(terminalLines(outcome.detail)) : c.error(terminalLines(outcome.detail))}`,
|
||||
);
|
||||
if (!outcome.ok && outcome.hint) {
|
||||
console.log(` ${" ".repeat(19)}${c.accent(terminalLines(outcome.hint))}`);
|
||||
}
|
||||
}
|
||||
|
||||
console.log();
|
||||
if (allOk) {
|
||||
console.log(` ${c.success("\u25C7")} ${c.success("All checks passed")}`);
|
||||
} else {
|
||||
console.log(` ${c.warn("\u25C7")} ${c.warn("Some checks failed \u2014 see hints above")}`);
|
||||
}
|
||||
console.log();
|
||||
}
|
||||
|
||||
export default defineCommand({
|
||||
meta: { name: "doctor", description: "Check system dependencies and environment" },
|
||||
args: {
|
||||
@@ -466,8 +492,6 @@ export default defineCommand({
|
||||
...(result.hint ? { hint: result.hint } : {}),
|
||||
});
|
||||
}
|
||||
const allOk = outcomes.every((o) => o.ok);
|
||||
|
||||
if (args.json) {
|
||||
// Exit code intentionally reflects command success, not environment
|
||||
// health — `checkVersion` returns ok:false when an npm update is
|
||||
@@ -479,27 +503,6 @@ export default defineCommand({
|
||||
return;
|
||||
}
|
||||
|
||||
console.log();
|
||||
console.log(c.bold("hyperframes doctor"));
|
||||
console.log();
|
||||
|
||||
for (const outcome of outcomes) {
|
||||
const icon = outcome.ok ? c.success("\u2713") : c.error("\u2717");
|
||||
const name = terminalText(outcome.name).padEnd(16);
|
||||
console.log(
|
||||
` ${icon} ${c.bold(name)} ${outcome.ok ? c.dim(terminalLines(outcome.detail)) : c.error(terminalLines(outcome.detail))}`,
|
||||
);
|
||||
if (!outcome.ok && outcome.hint) {
|
||||
console.log(` ${" ".repeat(19)}${c.accent(terminalLines(outcome.hint))}`);
|
||||
}
|
||||
}
|
||||
|
||||
console.log();
|
||||
if (allOk) {
|
||||
console.log(` ${c.success("\u25C7")} ${c.success("All checks passed")}`);
|
||||
} else {
|
||||
console.log(` ${c.warn("\u25C7")} ${c.warn("Some checks failed \u2014 see hints above")}`);
|
||||
}
|
||||
console.log();
|
||||
printDoctorOutcomes(outcomes);
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user