Skip to content

Commit

Permalink
feat(plugins): allow dependencyUpdaters to be passed under a new `plu…
Browse files Browse the repository at this point in the history
…gins` property
  • Loading branch information
travi committed Jul 21, 2024
1 parent a29630b commit f0e0fe0
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
}
},
"dependencies": {
"@form8ion/core": "^4.3.0",
"@form8ion/core": "^4.4.0",
"@form8ion/execa-wrapper": "^1.0.0",
"@form8ion/git": "^1.2.0",
"@form8ion/overridable-prompts": "^1.1.0",
Expand Down
6 changes: 4 additions & 2 deletions src/options-validator.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {validateOptions} from '@form8ion/core';
import {validateOptions, form8ionPlugin} from '@form8ion/core';
import joi from 'joi';

import languagePluginsSchema from './language/schema.js';
Expand All @@ -11,6 +11,8 @@ export function validate(options) {
languages: languagePluginsSchema,
vcsHosts: vcsHostPluginsSchema,
decisions: decisionsSchema,
dependencyUpdaters: dependencyUpdaterPluginsSchema
dependencyUpdaters: dependencyUpdaterPluginsSchema,
plugins: joi.object({dependencyUpdaters: joi.object().pattern(joi.string(), form8ionPlugin)})
// plugins: joi.object({dependencyUpdaters: joi.object().pattern(form8ionPlugin)})
}), options) || {};
}
14 changes: 12 additions & 2 deletions src/options-validator.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import joi from 'joi';
import {validateOptions} from '@form8ion/core';
import {validateOptions, form8ionPlugin} from '@form8ion/core';

import {describe, expect, it, beforeEach, afterEach, vi} from 'vitest';
import any from '@travi/any';
Expand All @@ -16,6 +16,7 @@ vi.mock('@form8ion/core');
describe('options validator', () => {
beforeEach(() => {
vi.spyOn(joi, 'object');
vi.spyOn(joi, 'string');
});

afterEach(() => {
Expand All @@ -24,13 +25,22 @@ describe('options validator', () => {

it('should build the full schema and call the base validator', () => {
const options = any.simpleObject();
const pluginsSchema = any.simpleObject();
const pluginMapSchema = any.simpleObject();
const fullSchema = any.simpleObject();
const validatedOptions = any.simpleObject();
const joiPattern = vi.fn();
const stringSchema = any.simpleObject();
joi.string.mockReturnValue(stringSchema);
when(joiPattern).calledWith(stringSchema, form8ionPlugin).mockReturnValue(pluginMapSchema);
when(joi.object).calledWith().mockReturnValue({pattern: joiPattern});
when(joi.object).calledWith({dependencyUpdaters: pluginMapSchema}).mockReturnValue(pluginsSchema);
when(joi.object).calledWith({
languages: languagePluginsSchema,
vcsHosts: vcsHostPluginsSchema,
decisions: decisionsSchema,
dependencyUpdaters: dependencyUpdaterPluginsSchema
dependencyUpdaters: dependencyUpdaterPluginsSchema,
plugins: pluginsSchema
}).mockReturnValue(fullSchema);
when(validateOptions).calledWith(fullSchema, options).mockReturnValue(validatedOptions);

Expand Down
7 changes: 7 additions & 0 deletions test/integration/features/step_definitions/common-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ When(/^the project is scaffolded$/, async function () {
}
}
},
plugins: {
...this.updaterScaffolderDetails && {
dependencyUpdaters: {
[chosenUpdater]: {...this.updaterScaffolderDetails, scaffold: this.updaterScaffolderDetails.scaffolder}
}
}
},
...this.updaterScaffolderDetails && {dependencyUpdaters: {[chosenUpdater]: this.updaterScaffolderDetails}},
...vcsHost && {
vcsHosts: {
Expand Down

0 comments on commit f0e0fe0

Please sign in to comment.