Skip to content

Commit

Permalink
feat(vcs-host): provided the terminal-prompt to the vcs-host scaffolder
Browse files Browse the repository at this point in the history
  • Loading branch information
travi committed Jul 30, 2024
1 parent 493d939 commit cff87ff
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/prompts/terminal-prompt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {prompt} from '@form8ion/overridable-prompts';

export default function ({questions, decisions}) {
return prompt(questions, decisions);
}
20 changes: 20 additions & 0 deletions src/prompts/terminal-prompt.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
5 changes: 3 additions & 2 deletions src/vcs/host/scaffolder.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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: {}};
}
3 changes: 2 additions & 1 deletion src/vcs/host/scaffolder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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);
Expand Down

0 comments on commit cff87ff

Please sign in to comment.