mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-25 03:04:29 -04:00
refactor(test): simplify onboarding wizard scaffolding
This commit is contained in:
@@ -78,6 +78,38 @@ vi.mock("./onboarding.completion.js", () => ({
|
|||||||
setupOnboardingShellCompletion,
|
setupOnboardingShellCompletion,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
function createWizardPrompter(overrides?: Partial<WizardPrompter>): WizardPrompter {
|
||||||
|
return {
|
||||||
|
intro: vi.fn(async () => {}),
|
||||||
|
outro: vi.fn(async () => {}),
|
||||||
|
note: vi.fn(async () => {}),
|
||||||
|
select: vi.fn(async () => "quickstart"),
|
||||||
|
multiselect: vi.fn(async () => []),
|
||||||
|
text: vi.fn(async () => ""),
|
||||||
|
confirm: vi.fn(async () => false),
|
||||||
|
progress: vi.fn(() => ({ update: vi.fn(), stop: vi.fn() })),
|
||||||
|
...overrides,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function createRuntime(opts?: { throwsOnExit?: boolean }): RuntimeEnv {
|
||||||
|
if (opts?.throwsOnExit) {
|
||||||
|
return {
|
||||||
|
log: vi.fn(),
|
||||||
|
error: vi.fn(),
|
||||||
|
exit: vi.fn((code: number) => {
|
||||||
|
throw new Error(`exit:${code}`);
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
log: vi.fn(),
|
||||||
|
error: vi.fn(),
|
||||||
|
exit: vi.fn(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
describe("runOnboardingWizard", () => {
|
describe("runOnboardingWizard", () => {
|
||||||
it("exits when config is invalid", async () => {
|
it("exits when config is invalid", async () => {
|
||||||
readConfigFileSnapshot.mockResolvedValueOnce({
|
readConfigFileSnapshot.mockResolvedValueOnce({
|
||||||
@@ -92,24 +124,8 @@ describe("runOnboardingWizard", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const select: WizardPrompter["select"] = vi.fn(async () => "quickstart");
|
const select: WizardPrompter["select"] = vi.fn(async () => "quickstart");
|
||||||
const prompter: WizardPrompter = {
|
const prompter = createWizardPrompter({ select });
|
||||||
intro: vi.fn(async () => {}),
|
const runtime = createRuntime({ throwsOnExit: true });
|
||||||
outro: vi.fn(async () => {}),
|
|
||||||
note: vi.fn(async () => {}),
|
|
||||||
select,
|
|
||||||
multiselect: vi.fn(async () => []),
|
|
||||||
text: vi.fn(async () => ""),
|
|
||||||
confirm: vi.fn(async () => false),
|
|
||||||
progress: vi.fn(() => ({ update: vi.fn(), stop: vi.fn() })),
|
|
||||||
};
|
|
||||||
|
|
||||||
const runtime: RuntimeEnv = {
|
|
||||||
log: vi.fn(),
|
|
||||||
error: vi.fn(),
|
|
||||||
exit: vi.fn((code: number) => {
|
|
||||||
throw new Error(`exit:${code}`);
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
runOnboardingWizard(
|
runOnboardingWizard(
|
||||||
@@ -135,23 +151,8 @@ describe("runOnboardingWizard", () => {
|
|||||||
it("skips prompts and setup steps when flags are set", async () => {
|
it("skips prompts and setup steps when flags are set", async () => {
|
||||||
const select: WizardPrompter["select"] = vi.fn(async () => "quickstart");
|
const select: WizardPrompter["select"] = vi.fn(async () => "quickstart");
|
||||||
const multiselect: WizardPrompter["multiselect"] = vi.fn(async () => []);
|
const multiselect: WizardPrompter["multiselect"] = vi.fn(async () => []);
|
||||||
const prompter: WizardPrompter = {
|
const prompter = createWizardPrompter({ select, multiselect });
|
||||||
intro: vi.fn(async () => {}),
|
const runtime = createRuntime({ throwsOnExit: true });
|
||||||
outro: vi.fn(async () => {}),
|
|
||||||
note: vi.fn(async () => {}),
|
|
||||||
select,
|
|
||||||
multiselect,
|
|
||||||
text: vi.fn(async () => ""),
|
|
||||||
confirm: vi.fn(async () => false),
|
|
||||||
progress: vi.fn(() => ({ update: vi.fn(), stop: vi.fn() })),
|
|
||||||
};
|
|
||||||
const runtime: RuntimeEnv = {
|
|
||||||
log: vi.fn(),
|
|
||||||
error: vi.fn(),
|
|
||||||
exit: vi.fn((code: number) => {
|
|
||||||
throw new Error(`exit:${code}`);
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
|
|
||||||
await runOnboardingWizard(
|
await runOnboardingWizard(
|
||||||
{
|
{
|
||||||
@@ -194,24 +195,8 @@ describe("runOnboardingWizard", () => {
|
|||||||
return "quickstart";
|
return "quickstart";
|
||||||
});
|
});
|
||||||
|
|
||||||
const prompter: WizardPrompter = {
|
const prompter = createWizardPrompter({ select });
|
||||||
intro: vi.fn(async () => {}),
|
const runtime = createRuntime({ throwsOnExit: true });
|
||||||
outro: vi.fn(async () => {}),
|
|
||||||
note: vi.fn(async () => {}),
|
|
||||||
select,
|
|
||||||
multiselect: vi.fn(async () => []),
|
|
||||||
text: vi.fn(async () => ""),
|
|
||||||
confirm: vi.fn(async () => false),
|
|
||||||
progress: vi.fn(() => ({ update: vi.fn(), stop: vi.fn() })),
|
|
||||||
};
|
|
||||||
|
|
||||||
const runtime: RuntimeEnv = {
|
|
||||||
log: vi.fn(),
|
|
||||||
error: vi.fn(),
|
|
||||||
exit: vi.fn((code: number) => {
|
|
||||||
throw new Error(`exit:${code}`);
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
|
|
||||||
await runOnboardingWizard(
|
await runOnboardingWizard(
|
||||||
{
|
{
|
||||||
@@ -254,22 +239,8 @@ describe("runOnboardingWizard", () => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const note: WizardPrompter["note"] = vi.fn(async () => {});
|
const note: WizardPrompter["note"] = vi.fn(async () => {});
|
||||||
const prompter: WizardPrompter = {
|
const prompter = createWizardPrompter({ note });
|
||||||
intro: vi.fn(async () => {}),
|
const runtime = createRuntime();
|
||||||
outro: vi.fn(async () => {}),
|
|
||||||
note,
|
|
||||||
select: vi.fn(async () => "quickstart"),
|
|
||||||
multiselect: vi.fn(async () => []),
|
|
||||||
text: vi.fn(async () => ""),
|
|
||||||
confirm: vi.fn(async () => false),
|
|
||||||
progress: vi.fn(() => ({ update: vi.fn(), stop: vi.fn() })),
|
|
||||||
};
|
|
||||||
|
|
||||||
const runtime: RuntimeEnv = {
|
|
||||||
log: vi.fn(),
|
|
||||||
error: vi.fn(),
|
|
||||||
exit: vi.fn(),
|
|
||||||
};
|
|
||||||
|
|
||||||
await runOnboardingWizard(
|
await runOnboardingWizard(
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user