-
-
Notifications
You must be signed in to change notification settings - Fork 304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
inject
function improvements
#100
Conversation
2bded82
to
bd2f34a
Compare
Thanks @pvdlg! I'll take a look at this over the weekend. Looks good |
Looks good to me. What do you think @lukeed? |
Hmm.. wouldn't this break/change the responses to select and multiselect prompts? Those should be Arrays, and if I'm not mistaken, this PR will treat all Arrays as a list to cycle through, rather than accepting it's answer in array-form. |
Yes indeed that would be problematic for multiselect as we would have no way to tell if an Array is a single answer with multiple values or multiple answers with a single value. The objective was to not make a breaking change, but I overlooked that particular case. prompts.inject(['answer1', ['multiple', 'multiselect', 'answers'], 'answer3']); Or do you have a preference for a different API? |
Sure, that could work! A lot of (deep) nested arrays can be visually confusing though, so we may want to explore a second parameter that toggles an |
That would be only one level of nested array, so not that deep. I don't really understand what you are suggesting...Can you provide an example of how that API would be used? |
Oh, sorry~! I typed that on the run, hence no code sample. I think I meant this: // Instead of:
prompts.inject({
text: 'foo', // regular
age: [5, new Error('Hit Ctrl+C'), 10], // must iterate
choice: [['one', 'two']], // this should be Array-type answer
confirm: true
]);
// Do this:
prompts.inject({
text: 'foo', // regular
choice: ['one', 'two'], // regular Array-type answer
confirm: true
});
prompts.inject({
age: [5, new Error('Hit Ctrl+C'), 10], // must iterate
}, true); //=> true == must iterate Doesn't really matter to me – as @pvdlg pointed out, it's only one extra level of depth/nesting, so that's not a big deal. This was just an idea |
Needing this functionality. Specifically to run the |
Sorry, I've been busy. @pvdlg is this ready for merge? |
@terkelg it depends. I tried to avoid making a breaking change, but as @lukeed mentioned there is a case where is a breaking change (multiselect prompts). So if we are ok with a breaking change we might simplify the API further. Instead of passing objects with the prompt type and the values we want we could just pass a list of value without having to specify the prompt type. For example with: prompts.inject(['abc', ['item1', 'item2', 'item3'], 10]); The fist prompt would receive It would up to the user to determine what prompt their test is supposed to call and inject the mock data accordingly. I think this solution is more simple both in terms of implementation and clarity for the end user, as specify the prompt id doesn't serve much purpose in the context of tests. Let me know if you'd like to make those changes. |
@pvdlg agree! Breaking changes are fine - let's keep it simple |
bd2f34a
to
e7eda77
Compare
@terkelg ok I updated the PR accordingly |
Thank you so much @pvdlg |
This PR provide 2 improvements to the inject function:
onSubmit
orformat
Here is an example of a prompt and it's associated test: