Skip to content

Commit 9654c00

Browse files
committed
fix(create-cli): pass default value to select prompt
1 parent 9a46285 commit 9654c00

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

packages/create-cli/src/lib/setup/prompts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ async function runPrompt(
9898
return select({
9999
message: descriptor.message,
100100
choices: [...descriptor.choices],
101+
default: descriptor.default,
101102
});
102103
case 'checkbox':
103104
return checkbox({

packages/create-cli/src/lib/setup/prompts.unit.test.ts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ vi.mock('@inquirer/prompts', () => ({
77
select: vi.fn(),
88
}));
99

10-
const { input: mockInput, checkbox: mockCheckbox } = vi.mocked(
11-
await import('@inquirer/prompts'),
12-
);
10+
const {
11+
input: mockInput,
12+
select: mockSelect,
13+
checkbox: mockCheckbox,
14+
} = vi.mocked(await import('@inquirer/prompts'));
1315

1416
describe('promptPluginOptions', () => {
1517
const descriptors: PluginPromptDescriptor[] = [
@@ -47,6 +49,30 @@ describe('promptPluginOptions', () => {
4749
expect(mockInput).toHaveBeenCalledOnce();
4850
});
4951

52+
it('should pass default to select prompt', async () => {
53+
mockSelect.mockResolvedValue('pnpm');
54+
55+
await promptPluginOptions(
56+
[
57+
{
58+
key: 'js-packages.packageManager',
59+
message: 'Package manager',
60+
type: 'select',
61+
choices: [
62+
{ name: 'npm', value: 'npm' },
63+
{ name: 'pnpm', value: 'pnpm' },
64+
],
65+
default: 'pnpm',
66+
},
67+
],
68+
{},
69+
);
70+
71+
expect(mockSelect).toHaveBeenCalledWith(
72+
expect.objectContaining({ default: 'pnpm' }),
73+
);
74+
});
75+
5076
it('should return checkbox values as array', async () => {
5177
mockCheckbox.mockResolvedValue(['json', 'csv']);
5278

0 commit comments

Comments
 (0)