Skip to content

Commit

Permalink
fix(plugins): actually call the proper scaffold function from the dep…
Browse files Browse the repository at this point in the history
…endency-updater plugin
  • Loading branch information
travi committed Jul 25, 2024
1 parent df49ff0 commit 0f92d93
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/dependency-updater/scaffolder.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {questionNames} from '../prompts/question-names.js';
import {promptForDependencyUpdaterChoice} from './prompt.js';

export default async function (scaffolders, decisions, options) {
if (!Object.keys(scaffolders).length) return undefined;
export default async function (plugins, decisions, options) {
if (!Object.keys(plugins).length) return undefined;

const scaffolderDetails = scaffolders[
(await promptForDependencyUpdaterChoice(scaffolders, decisions))[questionNames.DEPENDENCY_UPDATER]
const plugin = plugins[
(await promptForDependencyUpdaterChoice(plugins, decisions))[questionNames.DEPENDENCY_UPDATER]
];

if (scaffolderDetails) return scaffolderDetails.scaffolder(options);
if (plugin) return plugin.scaffold(options);

return undefined;
}
6 changes: 3 additions & 3 deletions src/dependency-updater/scaffolder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ describe('dependency-updater scaffolder', () => {
const options = any.simpleObject();
const chosenUpdater = any.word();
const chosenUpdaterScaffolder = vi.fn();
const scaffolders = {...any.simpleObject(), [chosenUpdater]: {scaffolder: chosenUpdaterScaffolder}};
const plugins = {...any.simpleObject(), [chosenUpdater]: {scaffold: chosenUpdaterScaffolder}};
const scaffolderResult = any.simpleObject();
when(prompt.promptForDependencyUpdaterChoice)
.calledWith(scaffolders, decisions)
.calledWith(plugins, decisions)
.mockResolvedValue({[questionNames.DEPENDENCY_UPDATER]: chosenUpdater});
when(chosenUpdaterScaffolder).calledWith(options).mockResolvedValue(scaffolderResult);

expect(await scaffoldUpdater(scaffolders, decisions, options)).toEqual(scaffolderResult);
expect(await scaffoldUpdater(plugins, decisions, options)).toEqual(scaffolderResult);
});

it('should not present a prompt if no updaters are registered', async () => {
Expand Down
6 changes: 3 additions & 3 deletions test/integration/features/step_definitions/common-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ When(/^the project is scaffolded$/, async function () {

await scaffold({
plugins: {
...this.updaterScaffolderDetails && {
...this.updatePlugin && {
dependencyUpdaters: {
[chosenUpdater]: {...this.updaterScaffolderDetails, scaffold: this.updaterScaffolderDetails.scaffolder}
[chosenUpdater]: this.updatePlugin
}
},
languages: {
Expand Down Expand Up @@ -92,7 +92,7 @@ When(/^the project is scaffolded$/, async function () {
[questionNames.GIT_REPO]: repoShouldBeCreated ?? false,
...repoShouldBeCreated && {[questionNames.REPO_HOST]: vcsHost},
[questionNames.PROJECT_LANGUAGE]: chosenLanguage,
...this.updaterScaffolderDetails && {[questionNames.DEPENDENCY_UPDATER]: chosenUpdater}
...this.updatePlugin && {[questionNames.DEPENDENCY_UPDATER]: chosenUpdater}
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ After(function () {
});

Given('a dependency updater can be chosen', async function () {
this.updaterScaffolderDetails = {scaffolder: foo => updaterScaffolder(foo)};
this.updatePlugin = {scaffold: foo => updaterScaffolder(foo)};
});

Then('the dependency updater was executed', async function () {
Expand Down

0 comments on commit 0f92d93

Please sign in to comment.