e30e75b5d4
Changesets / Create Version PR (push) Has been cancelled
Deploy Shadcn Registry / Deploy Production (push) Has been cancelled
Template Metrics / LOC + Bundle Size (push) Has been cancelled
Code Quality / Oxlint + Oxfmt (push) Has been cancelled
Code Quality / Template Sync (push) Has been cancelled
Code Quality / Build Changed Packages (push) Has been cancelled
Code Quality / Test Changed Packages (push) Has been cancelled
Deploy Expo Example / Deploy Production (push) Has been cancelled
Deploy Ink Example / Deploy Production (push) Has been cancelled
Python Tests / pytest (assistant-stream, 3.10) (push) Has been cancelled
Python Tests / pytest (assistant-stream, 3.12) (push) Has been cancelled
Python Tests / pytest (assistant-ui-sync-server-api, 3.10) (push) Has been cancelled
Python Tests / pytest (assistant-ui-sync-server-api, 3.12) (push) Has been cancelled
101 lines
2.8 KiB
TypeScript
101 lines
2.8 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import {
|
|
init,
|
|
createExistingProjectInitPlan,
|
|
isNonInteractiveShell,
|
|
} from "../../src/commands/init";
|
|
import { create } from "../../src/commands/create";
|
|
|
|
describe("init command", () => {
|
|
it("defaults --yes to false for interactive human flow", () => {
|
|
const yesOption = init.options.find((option) => option.long === "--yes");
|
|
expect(yesOption?.defaultValue).toBe(false);
|
|
});
|
|
|
|
it("accepts --preset as a hidden compatibility option", () => {
|
|
const presetOption = init.options.find(
|
|
(option) => option.long === "--preset",
|
|
);
|
|
expect(presetOption).toBeDefined();
|
|
expect((presetOption as { hidden?: boolean } | undefined)?.hidden).toBe(
|
|
true,
|
|
);
|
|
});
|
|
|
|
it("uses interactive add flow when --yes is not passed", () => {
|
|
const plan = createExistingProjectInitPlan({
|
|
yes: false,
|
|
overwrite: false,
|
|
registryUrl: "https://r.assistant-ui.com/chat/b/ai-sdk-quick-start/json",
|
|
});
|
|
|
|
expect(plan.initArgs).toBeNull();
|
|
expect(plan.addArgs).toEqual([
|
|
"shadcn@latest",
|
|
"add",
|
|
"https://r.assistant-ui.com/chat/b/ai-sdk-quick-start/json",
|
|
]);
|
|
});
|
|
|
|
it("uses non-interactive init+add flow when --yes is passed and config is missing", () => {
|
|
const plan = createExistingProjectInitPlan({
|
|
yes: true,
|
|
overwrite: true,
|
|
registryUrl: "https://example.com/registry.json",
|
|
});
|
|
|
|
expect(plan.initArgs).toEqual([
|
|
"shadcn@latest",
|
|
"init",
|
|
"--defaults",
|
|
"--yes",
|
|
]);
|
|
expect(plan.addArgs).toEqual([
|
|
"shadcn@latest",
|
|
"add",
|
|
"--yes",
|
|
"--overwrite",
|
|
"https://example.com/registry.json",
|
|
]);
|
|
});
|
|
|
|
it("detects non-interactive mode from stdin TTY only", () => {
|
|
expect(isNonInteractiveShell(false)).toBe(true);
|
|
expect(isNonInteractiveShell(true)).toBe(false);
|
|
});
|
|
|
|
it("delegates to create.parseAsync with correct args when no package.json exists", async () => {
|
|
const parseAsyncSpy = vi
|
|
.spyOn(create, "parseAsync")
|
|
.mockResolvedValue(create);
|
|
|
|
await init.parseAsync(["node", "init", "my-app", "--use-pnpm"], {
|
|
from: "node",
|
|
});
|
|
|
|
expect(parseAsyncSpy).toHaveBeenCalledWith(["my-app", "--use-pnpm"], {
|
|
from: "user",
|
|
});
|
|
|
|
parseAsyncSpy.mockRestore();
|
|
});
|
|
|
|
it("delegates to create.parseAsync with preset args", async () => {
|
|
const parseAsyncSpy = vi
|
|
.spyOn(create, "parseAsync")
|
|
.mockResolvedValue(create);
|
|
|
|
await init.parseAsync(
|
|
["node", "init", "--preset", "https://example.com/preset.json"],
|
|
{ from: "node" },
|
|
);
|
|
|
|
expect(parseAsyncSpy).toHaveBeenCalledWith(
|
|
["--preset", "https://example.com/preset.json"],
|
|
{ from: "user" },
|
|
);
|
|
|
|
parseAsyncSpy.mockRestore();
|
|
});
|
|
});
|