Skip to content

Commit

Permalink
fix: keep unknown properties from predefinedProperties
Browse files Browse the repository at this point in the history
  • Loading branch information
3cp committed Jun 6, 2022
1 parent 648de22 commit 915a543
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/run-questionnaire.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async function run(questions, {
await ask(questions[i]);
}

return [properties, pickedFeatures, notDefaultFeatures];
return [{...predefinedProperties, ...properties}, pickedFeatures, notDefaultFeatures];
}

async function textPrompt(question, {predefinedProperties, unattended, _debug}) {
Expand Down
28 changes: 27 additions & 1 deletion test/run-questionnaire.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,19 @@ test('run runs through questionnaire in unattended mode with preselectedFeatures
]);
});

test('run runs through questionnaire in unattended mode with preselectedFeatures and predefinedProperties, and keeps unknown properties', async t => {
const result = await run(questions, {
unattended: true,
preselectedFeatures: ['postcss'],
predefinedProperties: {name: 'new-app', foo: 'bar'}
});
t.deepEqual(result, [
{name: 'new-app', description: '', foo: 'bar'},
['webpack', 'postcss'],
['postcss']
]);
});

test('run runs through questionnaire', async t => {
let result = await run(questions, {_debug: ['new-app', 2, [1, 2]]});
t.deepEqual(result, [
Expand Down Expand Up @@ -265,6 +278,19 @@ test('run runs through questionnaire with preselectedFeatures and predefinedProp
]);
});

test('run runs through questionnaire with preselectedFeatures and predefinedProperties, and keeps unknown properties', async t => {
const result = await run(questions, {
preselectedFeatures: ['postcss'],
predefinedProperties: {name: 'new-app', foo: 'bar'},
_debug: [2]
});
t.deepEqual(result, [
{name: 'new-app', foo: 'bar'},
['dumber', 'postcss'],
['dumber', 'postcss']
]);
});

test('run rejects missing name/choices', async t => {
await t.throwsAsync(async () => run([{}], {}));
});
Expand All @@ -289,4 +315,4 @@ test('run rejects multi-select with missing value', async t => {
{value: 'sass', selected: true}
]
}], {}));
});
});

0 comments on commit 915a543

Please sign in to comment.