This repository has been archived by the owner on Apr 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 56
feat: Prompt Bypass supports Object choice values #209
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,52 +6,56 @@ const plop = nodePlop(); | |
|
||
const prompts = [{ | ||
type:'list', | ||
name:'list', message:'listMsg', | ||
name:'list', | ||
message:'listMsg', | ||
choices: [ | ||
'eh', | ||
{key: 'b', value:'bee'}, | ||
{name: 'c', value: 'see'}, | ||
{value: 'd'}, | ||
{name: 'e'} | ||
{name: 'e'}, | ||
{key: 'f', name: 'ff', value: { prop: 'value'}} | ||
] | ||
}]; | ||
|
||
test('verify good bypass input', function (t) { | ||
const [, byValue] = promptBypass(prompts, ['eh'], plop); | ||
t.is(byValue.list, 'eh'); | ||
|
||
const [, byKey] = promptBypass(prompts, ['b'], plop); | ||
t.is(byKey.list, 'bee'); | ||
|
||
const [, byName] = promptBypass(prompts, ['c'], plop); | ||
t.is(byName.list, 'see'); | ||
|
||
const [, byValueProp] = promptBypass(prompts, ['d'], plop); | ||
t.is(byValueProp.list, 'd'); | ||
|
||
const [, byNameNoValue] = promptBypass(prompts, ['e'], plop); | ||
t.is(byNameNoValue.list, 'e'); | ||
|
||
const [, byIndexValue] = promptBypass(prompts, ['0'], plop); | ||
t.is(byIndexValue.list, 'eh'); | ||
|
||
const [, byIndexKey] = promptBypass(prompts, ['1'], plop); | ||
t.is(byIndexKey.list, 'bee'); | ||
|
||
const [, byIndexName] = promptBypass(prompts, ['2'], plop); | ||
t.is(byIndexName.list, 'see'); | ||
|
||
const [, byIndexValueProp] = promptBypass(prompts, ['3'], plop); | ||
t.is(byIndexValueProp.list, 'd'); | ||
|
||
const [, byIndexNameNoValue] = promptBypass(prompts, ['4'], plop); | ||
t.is(byIndexNameNoValue.list, 'e'); | ||
|
||
const [, byIndexNumber] = promptBypass(prompts, [4], plop); | ||
t.is(byIndexNumber.list, 'e'); | ||
// answer is string | ||
[ | ||
{ bypassValue: 'eh', expectedAnswer: 'eh' }, // by value | ||
{ bypassValue: 'b', expectedAnswer: 'bee' }, // by key | ||
{ bypassValue: 'c', expectedAnswer: 'see' }, // by name | ||
{ bypassValue: 'd', expectedAnswer: 'd' }, // by value prop | ||
{ bypassValue: 'e', expectedAnswer: 'e' }, // by name, no value | ||
{ bypassValue: '0', expectedAnswer: 'eh' }, // by index - value | ||
{ bypassValue: '1', expectedAnswer: 'bee' }, // by index - key | ||
{ bypassValue: '2', expectedAnswer: 'see' }, // by index - name | ||
{ bypassValue: '3', expectedAnswer: 'd' }, // by index - value prop | ||
{ bypassValue: '4', expectedAnswer: 'e' }, // by index - name, no value | ||
{ bypassValue: 4, expectedAnswer: 'e' }, // by index number | ||
].forEach(testCase => { | ||
const [, value] = promptBypass(prompts, [testCase.bypassValue], plop); | ||
t.is(value.list, testCase.expectedAnswer); | ||
}); | ||
|
||
// answer is object | ||
const objValue = { prop: 'value' }; | ||
[ | ||
{ bypassValue: 'f', expectedAnswer: objValue }, // by key | ||
{ bypassValue: 'ff', expectedAnswer: objValue }, // by name | ||
{ bypassValue: '5', expectedAnswer: objValue }, // by index | ||
{ bypassValue: 5, expectedAnswer: objValue }, // by index number | ||
].forEach(testCase => { | ||
const [, value] = promptBypass(prompts, [testCase.bypassValue], plop); | ||
t.deepEqual(value.list, testCase.expectedAnswer); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I deeply appreciate you having added unit tests for this functionality! However, can we revert the migration of tests to use IMO it makes tests easier to immediately grok and less potential to need to debug the tests later on |
||
}); | ||
|
||
test('verify bad bypass input', function (t) { | ||
t.throws(() => promptBypass(prompts, ['asdf'], plop)); | ||
t.throws(() => promptBypass(prompts, ['5'], plop)); | ||
[ | ||
'asdf', | ||
'6', | ||
6, | ||
].forEach(bypassValue => { | ||
t.throws(() => promptBypass(prompts, [bypassValue], plop)); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally find this logic a bit hard to parse in terms of early-return (despite understanding
some
usage).I think I'd rather move this back to using logical ORs. What do you think of this?