Skip to content

Commit 9654c00

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

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

‎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
returnselect({
9999
message: descriptor.message,
100100
choices: [...descriptor.choices],
101+
default: descriptor.default,
101102
});
102103
case'checkbox':
103104
returncheckbox({

‎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-
awaitimport('@inquirer/prompts'),
12-
);
10+
const{
11+
input: mockInput,
12+
select: mockSelect,
13+
checkbox: mockCheckbox,
14+
}=vi.mocked(awaitimport('@inquirer/prompts'));
1315

1416
describe('promptPluginOptions',()=>{
1517
constdescriptors: 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+
awaitpromptPluginOptions(
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)