From cff87ff22cce92da68a41710363eb510f4e7a61c Mon Sep 17 00:00:00 2001 From: Matt Travi Date: Tue, 30 Jul 2024 08:18:39 -0500 Subject: [PATCH] feat(vcs-host): provided the terminal-prompt to the vcs-host scaffolder --- src/prompts/terminal-prompt.js | 5 +++++ src/prompts/terminal-prompt.test.js | 20 ++++++++++++++++++++ src/vcs/host/scaffolder.js | 5 +++-- src/vcs/host/scaffolder.test.js | 3 ++- 4 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 src/prompts/terminal-prompt.js create mode 100644 src/prompts/terminal-prompt.test.js diff --git a/src/prompts/terminal-prompt.js b/src/prompts/terminal-prompt.js new file mode 100644 index 00000000..b4d26d54 --- /dev/null +++ b/src/prompts/terminal-prompt.js @@ -0,0 +1,5 @@ +import {prompt} from '@form8ion/overridable-prompts'; + +export default function ({questions, decisions}) { + return prompt(questions, decisions); +} diff --git a/src/prompts/terminal-prompt.test.js b/src/prompts/terminal-prompt.test.js new file mode 100644 index 00000000..72ea965f --- /dev/null +++ b/src/prompts/terminal-prompt.test.js @@ -0,0 +1,20 @@ +import {prompt as promptWithInquirer} from '@form8ion/overridable-prompts'; + +import {when} from 'jest-when'; +import {describe, it, vi, expect} from 'vitest'; +import any from '@travi/any'; + +import prompt from './terminal-prompt.js'; + +vi.mock('@form8ion/overridable-prompts'); + +describe('terminal prompt', () => { + it('should present the provided questions using inquirer', async () => { + const questions = any.listOf(any.simpleObject); + const decisions = any.simpleObject(); + const answers = any.simpleObject(); + when(promptWithInquirer).calledWith(questions, decisions).mockResolvedValue(answers); + + expect(await prompt({questions, decisions})).toEqual(answers); + }); +}); diff --git a/src/vcs/host/scaffolder.js b/src/vcs/host/scaffolder.js index 6ff29be8..2b584d5c 100644 --- a/src/vcs/host/scaffolder.js +++ b/src/vcs/host/scaffolder.js @@ -1,5 +1,6 @@ -import promptForVcsHostDetails from './prompt.js'; import {questionNames} from '../../prompts/question-names.js'; +import terminalPrompt from '../../prompts/terminal-prompt.js'; +import promptForVcsHostDetails from './prompt.js'; export default async function (hosts, visibility, decisions, options) { const { @@ -12,7 +13,7 @@ export default async function (hosts, visibility, decisions, options) { ); const host = lowercasedHosts[chosenHost.toLowerCase()]; - if (host) return host.scaffold({...options, owner}); + if (host) return host.scaffold({...options, owner}, {prompt: terminalPrompt}); return {vcs: {}}; } diff --git a/src/vcs/host/scaffolder.test.js b/src/vcs/host/scaffolder.test.js index 78bf376a..3d05a3d1 100644 --- a/src/vcs/host/scaffolder.test.js +++ b/src/vcs/host/scaffolder.test.js @@ -5,6 +5,7 @@ import {when} from 'jest-when'; import scaffoldVcsHost from './scaffolder.js'; import promptForVcsHostDetails from './prompt.js'; import {questionNames} from '../../prompts/question-names.js'; +import terminalPrompt from '../../prompts/terminal-prompt.js'; vi.mock('./prompt'); @@ -22,7 +23,7 @@ describe('vcs host scaffolder', () => { when(promptForVcsHostDetails) .calledWith(hostPlugins, visibility, decisions) .mockResolvedValue({[questionNames.REPO_HOST]: chosenHost, [questionNames.REPO_OWNER]: owner}); - when(chosenHostScaffolder).calledWith({...options, owner}).mockResolvedValue(results); + when(chosenHostScaffolder).calledWith({...options, owner}, {prompt: terminalPrompt}).mockResolvedValue(results); expect(await scaffoldVcsHost(hostPlugins, visibility, decisions, options)) .toEqual(results);