feat: add new plugins option
This commit is contained in:
@@ -33,6 +33,9 @@ test.serial('Pass options to semantic-release API', async t => {
|
||||
'https://github/com/owner/repo.git',
|
||||
'-t',
|
||||
`v\${version}`,
|
||||
'-p',
|
||||
'plugin1',
|
||||
'plugin2',
|
||||
'-e',
|
||||
'config1',
|
||||
'config2',
|
||||
@@ -68,6 +71,7 @@ test.serial('Pass options to semantic-release API', async t => {
|
||||
t.is(run.args[0][0].branch, 'master');
|
||||
t.is(run.args[0][0].repositoryUrl, 'https://github/com/owner/repo.git');
|
||||
t.is(run.args[0][0].tagFormat, `v\${version}`);
|
||||
t.deepEqual(run.args[0][0].plugins, ['plugin1', 'plugin2']);
|
||||
t.deepEqual(run.args[0][0].extends, ['config1', 'config2']);
|
||||
t.deepEqual(run.args[0][0].verifyConditions, ['condition1', 'condition2']);
|
||||
t.is(run.args[0][0].analyzeCommits, 'analyze');
|
||||
@@ -94,6 +98,9 @@ test.serial('Pass options to semantic-release API with alias arguments', async t
|
||||
'https://github/com/owner/repo.git',
|
||||
'--tag-format',
|
||||
`v\${version}`,
|
||||
'--plugins',
|
||||
'plugin1',
|
||||
'plugin2',
|
||||
'--extends',
|
||||
'config1',
|
||||
'config2',
|
||||
@@ -106,6 +113,7 @@ test.serial('Pass options to semantic-release API with alias arguments', async t
|
||||
t.is(run.args[0][0].branch, 'master');
|
||||
t.is(run.args[0][0].repositoryUrl, 'https://github/com/owner/repo.git');
|
||||
t.is(run.args[0][0].tagFormat, `v\${version}`);
|
||||
t.deepEqual(run.args[0][0].plugins, ['plugin1', 'plugin2']);
|
||||
t.deepEqual(run.args[0][0].extends, ['config1', 'config2']);
|
||||
t.is(run.args[0][0].dryRun, true);
|
||||
|
||||
@@ -151,6 +159,8 @@ test.serial('Do not set properties in option for which arg is not in command lin
|
||||
t.false('debug' in run.args[0][0]);
|
||||
t.false('r' in run.args[0][0]);
|
||||
t.false('t' in run.args[0][0]);
|
||||
t.false('p' in run.args[0][0]);
|
||||
t.false('e' in run.args[0][0]);
|
||||
});
|
||||
|
||||
test.serial('Set "noCi" options to "true" with "--no-ci"', async t => {
|
||||
|
||||
+30
-3
@@ -8,6 +8,13 @@ import {stub} from 'sinon';
|
||||
import yaml from 'js-yaml';
|
||||
import {gitRepo, gitCommits, gitShallowClone, gitAddConfig} from './helpers/git-utils';
|
||||
|
||||
const DEFAULT_PLUGINS = [
|
||||
'@semantic-release/commit-analyzer',
|
||||
'@semantic-release/release-notes-generator',
|
||||
'@semantic-release/npm',
|
||||
'@semantic-release/github',
|
||||
];
|
||||
|
||||
test.beforeEach(t => {
|
||||
t.context.plugins = stub().returns({});
|
||||
t.context.getConfig = proxyquire('../lib/get-config', {'./plugins': t.context.plugins});
|
||||
@@ -69,6 +76,7 @@ test('Read options from package.json', async t => {
|
||||
branch: 'test_branch',
|
||||
repositoryUrl: 'https://host.null/owner/module.git',
|
||||
tagFormat: `v\${version}`,
|
||||
plugins: false,
|
||||
};
|
||||
// Create package.json in repository root
|
||||
await outputJson(path.resolve(cwd, 'package.json'), {release: options});
|
||||
@@ -89,6 +97,7 @@ test('Read options from .releaserc.yml', async t => {
|
||||
branch: 'test_branch',
|
||||
repositoryUrl: 'https://host.null/owner/module.git',
|
||||
tagFormat: `v\${version}`,
|
||||
plugins: false,
|
||||
};
|
||||
// Create package.json in repository root
|
||||
await writeFile(path.resolve(cwd, '.releaserc.yml'), yaml.safeDump(options));
|
||||
@@ -109,6 +118,7 @@ test('Read options from .releaserc.json', async t => {
|
||||
branch: 'test_branch',
|
||||
repositoryUrl: 'https://host.null/owner/module.git',
|
||||
tagFormat: `v\${version}`,
|
||||
plugins: false,
|
||||
};
|
||||
// Create package.json in repository root
|
||||
await outputJson(path.resolve(cwd, '.releaserc.json'), options);
|
||||
@@ -129,6 +139,7 @@ test('Read options from .releaserc.js', async t => {
|
||||
branch: 'test_branch',
|
||||
repositoryUrl: 'https://host.null/owner/module.git',
|
||||
tagFormat: `v\${version}`,
|
||||
plugins: false,
|
||||
};
|
||||
// Create package.json in repository root
|
||||
await writeFile(path.resolve(cwd, '.releaserc.js'), `module.exports = ${JSON.stringify(options)}`);
|
||||
@@ -149,6 +160,7 @@ test('Read options from release.config.js', async t => {
|
||||
branch: 'test_branch',
|
||||
repositoryUrl: 'https://host.null/owner/module.git',
|
||||
tagFormat: `v\${version}`,
|
||||
plugins: false,
|
||||
};
|
||||
// Create package.json in repository root
|
||||
await writeFile(path.resolve(cwd, 'release.config.js'), `module.exports = ${JSON.stringify(options)}`);
|
||||
@@ -176,6 +188,7 @@ test('Prioritise CLI/API parameters over file configuration and git repo', async
|
||||
branch: 'branch_cli',
|
||||
repositoryUrl: 'http://cli-url.com/owner/package',
|
||||
tagFormat: `cli\${version}`,
|
||||
plugins: false,
|
||||
};
|
||||
const pkg = {release: pkgOptions, repository: 'git@host.null:owner/module.git'};
|
||||
// Create package.json in repository root
|
||||
@@ -199,6 +212,7 @@ test('Read configuration from file path in "extends"', async t => {
|
||||
branch: 'test_branch',
|
||||
repositoryUrl: 'https://host.null/owner/module.git',
|
||||
tagFormat: `v\${version}`,
|
||||
plugins: false,
|
||||
};
|
||||
// Create package.json and shareable.json in repository root
|
||||
await outputJson(path.resolve(cwd, 'package.json'), {release: pkgOptions});
|
||||
@@ -226,6 +240,7 @@ test('Read configuration from module path in "extends"', async t => {
|
||||
branch: 'test_branch',
|
||||
repositoryUrl: 'https://host.null/owner/module.git',
|
||||
tagFormat: `v\${version}`,
|
||||
plugins: false,
|
||||
};
|
||||
// Create package.json and shareable.json in repository root
|
||||
await outputJson(path.resolve(cwd, 'package.json'), {release: pkgOptions});
|
||||
@@ -259,6 +274,7 @@ test('Read configuration from an array of paths in "extends"', async t => {
|
||||
analyzeCommits: {path: 'analyzeCommits2', param: 'analyzeCommits_param2'},
|
||||
branch: 'test_branch',
|
||||
tagFormat: `v\${version}`,
|
||||
plugins: false,
|
||||
};
|
||||
// Create package.json and shareable.json in repository root
|
||||
await outputJson(path.resolve(cwd, 'package.json'), {release: pkgOptions});
|
||||
@@ -296,6 +312,7 @@ test('Prioritize configuration from config file over "extends"', async t => {
|
||||
branch: 'test_branch',
|
||||
repositoryUrl: 'https://host.null/owner/module.git',
|
||||
tagFormat: `v\${version}`,
|
||||
plugins: false,
|
||||
};
|
||||
// Create package.json and shareable.json in repository root
|
||||
await outputJson(path.resolve(cwd, 'package.json'), {release: pkgOptions});
|
||||
@@ -341,6 +358,7 @@ test('Prioritize configuration from cli/API options over "extends"', async t =>
|
||||
publish: [{path: 'publishShareable', param: 'publishShareable_param2'}],
|
||||
branch: 'test_branch2',
|
||||
tagFormat: `v\${version}`,
|
||||
plugins: false,
|
||||
};
|
||||
// Create package.json, shareable1.json and shareable2.json in repository root
|
||||
await outputJson(path.resolve(cwd, 'package.json'), {release: pkgOptions});
|
||||
@@ -366,11 +384,13 @@ test('Allow to unset properties defined in shareable config with "null"', async
|
||||
analyzeCommits: null,
|
||||
branch: 'test_branch',
|
||||
repositoryUrl: 'https://host.null/owner/module.git',
|
||||
plugins: null,
|
||||
};
|
||||
const options1 = {
|
||||
generateNotes: 'generateNotes',
|
||||
analyzeCommits: {path: 'analyzeCommits', param: 'analyzeCommits_param'},
|
||||
tagFormat: `v\${version}`,
|
||||
plugins: ['test-plugin'],
|
||||
};
|
||||
// Create package.json and shareable.json in repository root
|
||||
await outputJson(path.resolve(cwd, 'package.json'), {release: pkgOptions});
|
||||
@@ -378,19 +398,25 @@ test('Allow to unset properties defined in shareable config with "null"', async
|
||||
|
||||
const {options} = await t.context.getConfig({cwd});
|
||||
|
||||
// Verify the options contains the plugin config from shareable.json
|
||||
t.deepEqual(options, {...omit(options1, 'analyzeCommits'), ...omit(pkgOptions, ['extends', 'analyzeCommits'])});
|
||||
// Verify the plugins module is called with the plugin options from shareable.json
|
||||
// Verify the options contains the plugin config from shareable.json and the default `plugins`
|
||||
t.deepEqual(options, {
|
||||
...omit(options1, ['analyzeCommits']),
|
||||
...omit(pkgOptions, ['extends', 'analyzeCommits']),
|
||||
plugins: DEFAULT_PLUGINS,
|
||||
});
|
||||
// Verify the plugins module is called with the plugin options from shareable.json and the default `plugins`
|
||||
t.deepEqual(t.context.plugins.args[0][0], {
|
||||
options: {
|
||||
...omit(options1, 'analyzeCommits'),
|
||||
...omit(pkgOptions, ['extends', 'analyzeCommits']),
|
||||
plugins: DEFAULT_PLUGINS,
|
||||
},
|
||||
cwd,
|
||||
});
|
||||
t.deepEqual(t.context.plugins.args[0][1], {
|
||||
generateNotes: './shareable.json',
|
||||
analyzeCommits: './shareable.json',
|
||||
'test-plugin': './shareable.json',
|
||||
});
|
||||
});
|
||||
|
||||
@@ -407,6 +433,7 @@ test('Allow to unset properties defined in shareable config with "undefined"', a
|
||||
generateNotes: 'generateNotes',
|
||||
analyzeCommits: {path: 'analyzeCommits', param: 'analyzeCommits_param'},
|
||||
tagFormat: `v\${version}`,
|
||||
plugins: false,
|
||||
};
|
||||
// Create package.json and release.config.js in repository root
|
||||
await writeFile(path.resolve(cwd, 'release.config.js'), `module.exports = ${format(pkgOptions)}`);
|
||||
|
||||
@@ -64,6 +64,7 @@ test('Plugins are called with expected values', async t => {
|
||||
const config = {branch: 'master', repositoryUrl, globalOpt: 'global', tagFormat: `v\${version}`};
|
||||
const options = {
|
||||
...config,
|
||||
plugins: false,
|
||||
verifyConditions: [verifyConditions1, verifyConditions2],
|
||||
analyzeCommits,
|
||||
verifyRelease,
|
||||
@@ -359,6 +360,7 @@ test('Log all "verifyConditions" errors', async t => {
|
||||
const config = {branch: 'master', repositoryUrl, tagFormat: `v\${version}`};
|
||||
const options = {
|
||||
...config,
|
||||
plugins: false,
|
||||
verifyConditions: [stub().rejects(new AggregateError([error1, error2])), stub().rejects(error3)],
|
||||
fail,
|
||||
};
|
||||
|
||||
@@ -152,7 +152,7 @@ test('Wrap "publish" plugin in a function that validate the output of the plugin
|
||||
t.regex(error.details, /2/);
|
||||
});
|
||||
|
||||
test('Plugin is called with "pluginConfig" (omitting "path", adding global config) and input', async t => {
|
||||
test('Plugin is called with "pluginConfig" (with object definition) and input', async t => {
|
||||
const pluginFunction = stub().resolves();
|
||||
const pluginConf = {path: pluginFunction, conf: 'confValue'};
|
||||
const options = {global: 'globalValue'};
|
||||
@@ -167,6 +167,21 @@ test('Plugin is called with "pluginConfig" (omitting "path", adding global confi
|
||||
);
|
||||
});
|
||||
|
||||
test('Plugin is called with "pluginConfig" (with array definition) and input', async t => {
|
||||
const pluginFunction = stub().resolves();
|
||||
const pluginConf = [pluginFunction, {conf: 'confValue'}];
|
||||
const options = {global: 'globalValue'};
|
||||
const plugin = normalize({cwd, options, logger: t.context.logger}, '', pluginConf, {});
|
||||
await plugin({param: 'param'});
|
||||
|
||||
t.true(
|
||||
pluginFunction.calledWithMatch(
|
||||
{conf: 'confValue', global: 'globalValue'},
|
||||
{param: 'param', logger: t.context.logger}
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
test('Prevent plugins to modify "pluginConfig"', async t => {
|
||||
const pluginFunction = stub().callsFake(pluginConfig => {
|
||||
pluginConfig.conf.subConf = 'otherConf';
|
||||
|
||||
@@ -29,7 +29,7 @@ test('Export default plugins', t => {
|
||||
t.is(typeof plugins.fail, 'function');
|
||||
});
|
||||
|
||||
test('Export plugins based on config', t => {
|
||||
test('Export plugins based on steps config', t => {
|
||||
const plugins = getPlugins(
|
||||
{
|
||||
cwd,
|
||||
@@ -55,6 +55,88 @@ test('Export plugins based on config', t => {
|
||||
t.is(typeof plugins.fail, 'function');
|
||||
});
|
||||
|
||||
test('Export plugins based on "plugins" config (array)', async t => {
|
||||
const plugin1 = {verifyConditions: stub(), publish: stub()};
|
||||
const plugin2 = {verifyConditions: stub(), verifyRelease: stub()};
|
||||
const plugins = getPlugins(
|
||||
{cwd, logger: t.context.logger, options: {plugins: [plugin1, plugin2], verifyRelease: () => {}}},
|
||||
{}
|
||||
);
|
||||
|
||||
await plugins.verifyConditions({});
|
||||
t.true(plugin1.verifyConditions.calledOnce);
|
||||
t.true(plugin2.verifyConditions.calledOnce);
|
||||
|
||||
await plugins.publish({});
|
||||
t.true(plugin1.publish.calledOnce);
|
||||
|
||||
await plugins.verifyRelease({});
|
||||
t.true(plugin2.verifyRelease.notCalled);
|
||||
|
||||
// Verify the module returns a function for each plugin
|
||||
t.is(typeof plugins.verifyConditions, 'function');
|
||||
t.is(typeof plugins.analyzeCommits, 'function');
|
||||
t.is(typeof plugins.verifyRelease, 'function');
|
||||
t.is(typeof plugins.generateNotes, 'function');
|
||||
t.is(typeof plugins.prepare, 'function');
|
||||
t.is(typeof plugins.publish, 'function');
|
||||
t.is(typeof plugins.success, 'function');
|
||||
t.is(typeof plugins.fail, 'function');
|
||||
});
|
||||
|
||||
test('Export plugins based on "plugins" config (single definition)', async t => {
|
||||
const plugin1 = {verifyConditions: stub(), publish: stub()};
|
||||
const plugins = getPlugins({cwd, logger: t.context.logger, options: {plugins: plugin1}}, {});
|
||||
|
||||
await plugins.verifyConditions({});
|
||||
t.true(plugin1.verifyConditions.calledOnce);
|
||||
|
||||
await plugins.publish({});
|
||||
t.true(plugin1.publish.calledOnce);
|
||||
|
||||
// Verify the module returns a function for each plugin
|
||||
t.is(typeof plugins.verifyConditions, 'function');
|
||||
t.is(typeof plugins.analyzeCommits, 'function');
|
||||
t.is(typeof plugins.verifyRelease, 'function');
|
||||
t.is(typeof plugins.generateNotes, 'function');
|
||||
t.is(typeof plugins.prepare, 'function');
|
||||
t.is(typeof plugins.publish, 'function');
|
||||
t.is(typeof plugins.success, 'function');
|
||||
t.is(typeof plugins.fail, 'function');
|
||||
});
|
||||
|
||||
test('Merge global options, "plugins" options and sptep options', async t => {
|
||||
const plugin1 = [{verifyConditions: stub(), publish: stub()}, {pluginOpt1: 'plugin1'}];
|
||||
const plugin2 = [{verifyConditions: stub()}, {pluginOpt2: 'plugin2'}];
|
||||
const plugin3 = [stub(), {pluginOpt3: 'plugin3'}];
|
||||
const plugins = getPlugins(
|
||||
{
|
||||
cwd,
|
||||
logger: t.context.logger,
|
||||
options: {globalOpt: 'global', plugins: [plugin1, plugin2], verifyRelease: [plugin3]},
|
||||
},
|
||||
{}
|
||||
);
|
||||
|
||||
await plugins.verifyConditions({});
|
||||
t.deepEqual(plugin1[0].verifyConditions.args[0][0], {globalOpt: 'global', pluginOpt1: 'plugin1'});
|
||||
t.deepEqual(plugin2[0].verifyConditions.args[0][0], {globalOpt: 'global', pluginOpt2: 'plugin2'});
|
||||
|
||||
await plugins.publish({});
|
||||
t.deepEqual(plugin1[0].publish.args[0][0], {globalOpt: 'global', pluginOpt1: 'plugin1'});
|
||||
|
||||
await plugins.verifyRelease({});
|
||||
t.deepEqual(plugin3[0].args[0][0], {globalOpt: 'global', pluginOpt3: 'plugin3'});
|
||||
});
|
||||
|
||||
test('Unknown steps of plugins configured in "plugins" are ignored', t => {
|
||||
const plugin1 = {verifyConditions: () => {}, unknown: () => {}};
|
||||
const plugins = getPlugins({cwd, logger: t.context.logger, options: {plugins: [plugin1]}}, {});
|
||||
|
||||
t.is(typeof plugins.verifyConditions, 'function');
|
||||
t.is(plugins.unknown, undefined);
|
||||
});
|
||||
|
||||
test('Export plugins loaded from the dependency of a shareable config module', async t => {
|
||||
const cwd = tempy.directory();
|
||||
await copy(
|
||||
@@ -121,11 +203,23 @@ test('Export plugins loaded from the dependency of a shareable config file', asy
|
||||
test('Use default when only options are passed for a single plugin', t => {
|
||||
const analyzeCommits = {};
|
||||
const generateNotes = {};
|
||||
const publish = {};
|
||||
const success = () => {};
|
||||
const fail = [() => {}];
|
||||
|
||||
const plugins = getPlugins(
|
||||
{cwd, logger: t.context.logger, options: {analyzeCommits, generateNotes, success, fail}},
|
||||
{
|
||||
cwd,
|
||||
logger: t.context.logger,
|
||||
options: {
|
||||
plugins: ['@semantic-release/commit-analyzer', '@semantic-release/release-notes-generator'],
|
||||
analyzeCommits,
|
||||
generateNotes,
|
||||
publish,
|
||||
success,
|
||||
fail,
|
||||
},
|
||||
},
|
||||
{}
|
||||
);
|
||||
|
||||
@@ -159,14 +253,20 @@ test('Merge global options with plugin options', async t => {
|
||||
t.deepEqual(result.pluginConfig, {localOpt: 'local', globalOpt: 'global', otherOpt: 'locally-defined'});
|
||||
});
|
||||
|
||||
test('Throw an error if plugins configuration are invalid', t => {
|
||||
test('Throw an error for each invalid plugin configuration', t => {
|
||||
const errors = [
|
||||
...t.throws(() =>
|
||||
getPlugins(
|
||||
{
|
||||
cwd,
|
||||
logger: t.context.logger,
|
||||
options: {verifyConditions: {}, analyzeCommits: [], verifyRelease: [{}], generateNotes: [{path: null}]},
|
||||
options: {
|
||||
plugins: ['@semantic-release/commit-analyzer', '@semantic-release/release-notes-generator'],
|
||||
verifyConditions: 1,
|
||||
analyzeCommits: [],
|
||||
verifyRelease: [{}],
|
||||
generateNotes: [{path: null}],
|
||||
},
|
||||
},
|
||||
{}
|
||||
)
|
||||
@@ -182,3 +282,38 @@ test('Throw an error if plugins configuration are invalid', t => {
|
||||
t.is(errors[3].name, 'SemanticReleaseError');
|
||||
t.is(errors[3].code, 'EPLUGINCONF');
|
||||
});
|
||||
|
||||
test('Throw EPLUGINSCONF error if the "plugins" option contains an old plugin definition (returns a function)', t => {
|
||||
const errors = [
|
||||
...t.throws(() =>
|
||||
getPlugins(
|
||||
{
|
||||
cwd,
|
||||
logger: t.context.logger,
|
||||
options: {plugins: ['./test/fixtures/multi-plugin', './test/fixtures/plugin-noop', () => {}]},
|
||||
},
|
||||
{}
|
||||
)
|
||||
),
|
||||
];
|
||||
|
||||
t.is(errors[0].name, 'SemanticReleaseError');
|
||||
t.is(errors[0].code, 'EPLUGINSCONF');
|
||||
t.is(errors[1].name, 'SemanticReleaseError');
|
||||
t.is(errors[1].code, 'EPLUGINSCONF');
|
||||
});
|
||||
|
||||
test('Throw EPLUGINSCONF error for each invalid definition if the "plugins" option', t => {
|
||||
const errors = [
|
||||
...t.throws(() =>
|
||||
getPlugins({cwd, logger: t.context.logger, options: {plugins: [1, {path: 1}, [() => {}, {}, {}]]}}, {})
|
||||
),
|
||||
];
|
||||
|
||||
t.is(errors[0].name, 'SemanticReleaseError');
|
||||
t.is(errors[0].code, 'EPLUGINSCONF');
|
||||
t.is(errors[1].name, 'SemanticReleaseError');
|
||||
t.is(errors[1].code, 'EPLUGINSCONF');
|
||||
t.is(errors[2].name, 'SemanticReleaseError');
|
||||
t.is(errors[2].code, 'EPLUGINSCONF');
|
||||
});
|
||||
|
||||
+287
-39
@@ -1,58 +1,306 @@
|
||||
import test from 'ava';
|
||||
import {validateConfig} from '../../lib/plugins/utils';
|
||||
import {validatePlugin, validateStep, loadPlugin, parseConfig} from '../../lib/plugins/utils';
|
||||
|
||||
test('Validate multiple/optional plugin configuration', t => {
|
||||
test('validatePlugin', t => {
|
||||
const path = 'plugin-module';
|
||||
const options = {option1: 'value1', option2: 'value2'};
|
||||
|
||||
t.true(validatePlugin(path), 'String definition');
|
||||
t.true(validatePlugin({publish: () => {}}), 'Object definition');
|
||||
t.true(validatePlugin([path]), 'Array definition');
|
||||
t.true(validatePlugin([path, options]), 'Array definition with options');
|
||||
t.true(validatePlugin([{publish: () => {}}, options]), 'Array definition with options and path as object');
|
||||
t.true(validatePlugin({path}), 'Object with path definition');
|
||||
t.true(validatePlugin({path, ...options}), 'Object with path definition with options');
|
||||
t.true(
|
||||
validatePlugin({path: {publish: () => {}}, ...options}),
|
||||
'Object with path definition with options and path as object'
|
||||
);
|
||||
|
||||
t.false(validatePlugin(1), 'String definition, wrong path');
|
||||
t.false(validatePlugin([]), 'Array definition, missing path');
|
||||
t.false(validatePlugin([path, options, {}]), 'Array definition, additional parameter');
|
||||
t.false(validatePlugin([1]), 'Array definition, wrong path');
|
||||
t.false(validatePlugin([path, 1]), 'Array definition, wrong options');
|
||||
t.false(validatePlugin({path: 1}), 'Object definition, wrong path');
|
||||
});
|
||||
|
||||
test('validateStep: multiple/optional plugin configuration', t => {
|
||||
const type = {multiple: true, required: false};
|
||||
t.false(validateConfig(type, {}));
|
||||
t.false(validateConfig(type, {path: null}));
|
||||
|
||||
t.true(validateConfig(type, {path: 'plugin-path.js'}));
|
||||
t.true(validateConfig(type));
|
||||
t.true(validateConfig(type, 'plugin-path.js'));
|
||||
t.true(validateConfig(type, ['plugin-path.js']));
|
||||
t.true(validateConfig(type, () => {}));
|
||||
t.true(validateConfig(type, [{path: 'plugin-path.js'}, 'plugin-path.js', () => {}]));
|
||||
// Empty config
|
||||
t.true(validateStep(type));
|
||||
t.true(validateStep(type, []));
|
||||
|
||||
// Single value definition
|
||||
t.true(validateStep(type, 'plugin-path.js'));
|
||||
t.true(validateStep(type, () => {}));
|
||||
t.true(validateStep(type, ['plugin-path.js']));
|
||||
t.true(validateStep(type, [() => {}]));
|
||||
t.false(validateStep(type, {}));
|
||||
t.false(validateStep(type, [{}]));
|
||||
|
||||
// Array type definition
|
||||
t.true(validateStep(type, [['plugin-path.js']]));
|
||||
t.true(validateStep(type, [['plugin-path.js', {options: 'value'}]]));
|
||||
t.true(validateStep(type, [[() => {}, {options: 'value'}]]));
|
||||
t.false(validateStep(type, [['plugin-path.js', 1]]));
|
||||
|
||||
// Object type definition
|
||||
t.true(validateStep(type, {path: 'plugin-path.js'}));
|
||||
t.true(validateStep(type, {path: 'plugin-path.js', options: 'value'}));
|
||||
t.true(validateStep(type, {path: () => {}, options: 'value'}));
|
||||
t.false(validateStep(type, {path: null}));
|
||||
|
||||
// Considered as an Array of 2 definitions and not as one Array definition in case of a muliple plugin type
|
||||
t.false(validateStep(type, [() => {}, {options: 'value'}]));
|
||||
t.false(validateStep(type, ['plugin-path.js', {options: 'value'}]));
|
||||
|
||||
// Multiple definitions
|
||||
t.true(
|
||||
validateStep(type, [
|
||||
'plugin-path.js',
|
||||
() => {},
|
||||
['plugin-path.js'],
|
||||
['plugin-path.js', {options: 'value'}],
|
||||
[() => {}, {options: 'value'}],
|
||||
{path: 'plugin-path.js'},
|
||||
{path: 'plugin-path.js', options: 'value'},
|
||||
{path: () => {}, options: 'value'},
|
||||
])
|
||||
);
|
||||
t.false(
|
||||
validateStep(type, [
|
||||
'plugin-path.js',
|
||||
() => {},
|
||||
['plugin-path.js'],
|
||||
['plugin-path.js', 1],
|
||||
[() => {}, {options: 'value'}],
|
||||
{path: 'plugin-path.js'},
|
||||
{path: 'plugin-path.js', options: 'value'},
|
||||
{path: () => {}, options: 'value'},
|
||||
])
|
||||
);
|
||||
t.false(
|
||||
validateStep(type, [
|
||||
'plugin-path.js',
|
||||
{},
|
||||
['plugin-path.js'],
|
||||
['plugin-path.js', {options: 'value'}],
|
||||
[() => {}, {options: 'value'}],
|
||||
{path: 'plugin-path.js'},
|
||||
{path: 'plugin-path.js', options: 'value'},
|
||||
{path: () => {}, options: 'value'},
|
||||
])
|
||||
);
|
||||
t.false(
|
||||
validateStep(type, [
|
||||
'plugin-path.js',
|
||||
() => {},
|
||||
['plugin-path.js'],
|
||||
['plugin-path.js', {options: 'value'}],
|
||||
[() => {}, {options: 'value'}],
|
||||
{path: null},
|
||||
{path: 'plugin-path.js', options: 'value'},
|
||||
{path: () => {}, options: 'value'},
|
||||
])
|
||||
);
|
||||
});
|
||||
|
||||
test('Validate multiple/required plugin configuration', t => {
|
||||
test('validateStep: multiple/required plugin configuration', t => {
|
||||
const type = {multiple: true, required: true};
|
||||
t.false(validateConfig(type, {}));
|
||||
t.false(validateConfig(type, {path: null}));
|
||||
t.false(validateConfig(type));
|
||||
|
||||
t.true(validateConfig(type, {path: 'plugin-path.js'}));
|
||||
t.true(validateConfig(type, 'plugin-path.js'));
|
||||
t.true(validateConfig(type, ['plugin-path.js']));
|
||||
t.true(validateConfig(type, () => {}));
|
||||
t.true(validateConfig(type, [{path: 'plugin-path.js'}, 'plugin-path.js', () => {}]));
|
||||
// Empty config
|
||||
t.false(validateStep(type));
|
||||
t.false(validateStep(type, []));
|
||||
|
||||
// Single value definition
|
||||
t.true(validateStep(type, 'plugin-path.js'));
|
||||
t.true(validateStep(type, () => {}));
|
||||
t.true(validateStep(type, ['plugin-path.js']));
|
||||
t.true(validateStep(type, [() => {}]));
|
||||
t.false(validateStep(type, {}));
|
||||
t.false(validateStep(type, [{}]));
|
||||
|
||||
// Array type definition
|
||||
t.true(validateStep(type, [['plugin-path.js']]));
|
||||
t.true(validateStep(type, [['plugin-path.js', {options: 'value'}]]));
|
||||
t.true(validateStep(type, [[() => {}, {options: 'value'}]]));
|
||||
t.false(validateStep(type, [['plugin-path.js', 1]]));
|
||||
|
||||
// Object type definition
|
||||
t.true(validateStep(type, {path: 'plugin-path.js'}));
|
||||
t.true(validateStep(type, {path: 'plugin-path.js', options: 'value'}));
|
||||
t.true(validateStep(type, {path: () => {}, options: 'value'}));
|
||||
t.false(validateStep(type, {path: null}));
|
||||
|
||||
// Considered as an Array of 2 definitions and not as one Array definition in the case of a muliple plugin type
|
||||
t.false(validateStep(type, [() => {}, {options: 'value'}]));
|
||||
t.false(validateStep(type, ['plugin-path.js', {options: 'value'}]));
|
||||
|
||||
// Multiple definitions
|
||||
t.true(
|
||||
validateStep(type, [
|
||||
'plugin-path.js',
|
||||
() => {},
|
||||
['plugin-path.js'],
|
||||
['plugin-path.js', {options: 'value'}],
|
||||
[() => {}, {options: 'value'}],
|
||||
{path: 'plugin-path.js'},
|
||||
{path: 'plugin-path.js', options: 'value'},
|
||||
{path: () => {}, options: 'value'},
|
||||
])
|
||||
);
|
||||
t.false(
|
||||
validateStep(type, [
|
||||
'plugin-path.js',
|
||||
() => {},
|
||||
['plugin-path.js'],
|
||||
['plugin-path.js', 1],
|
||||
[() => {}, {options: 'value'}],
|
||||
{path: 'plugin-path.js'},
|
||||
{path: 'plugin-path.js', options: 'value'},
|
||||
{path: () => {}, options: 'value'},
|
||||
])
|
||||
);
|
||||
t.false(
|
||||
validateStep(type, [
|
||||
'plugin-path.js',
|
||||
{},
|
||||
['plugin-path.js'],
|
||||
['plugin-path.js', {options: 'value'}],
|
||||
[() => {}, {options: 'value'}],
|
||||
{path: 'plugin-path.js'},
|
||||
{path: 'plugin-path.js', options: 'value'},
|
||||
{path: () => {}, options: 'value'},
|
||||
])
|
||||
);
|
||||
t.false(
|
||||
validateStep(type, [
|
||||
'plugin-path.js',
|
||||
() => {},
|
||||
['plugin-path.js'],
|
||||
['plugin-path.js', {options: 'value'}],
|
||||
[() => {}, {options: 'value'}],
|
||||
{path: null},
|
||||
{path: 'plugin-path.js', options: 'value'},
|
||||
{path: () => {}, options: 'value'},
|
||||
])
|
||||
);
|
||||
});
|
||||
|
||||
test('Validate single/required plugin configuration', t => {
|
||||
test('validateStep: single/required plugin configuration', t => {
|
||||
const type = {multiple: false, required: true};
|
||||
|
||||
t.false(validateConfig(type, {}));
|
||||
t.false(validateConfig(type, {path: null}));
|
||||
t.false(validateConfig(type, []));
|
||||
t.false(validateConfig(type));
|
||||
t.false(validateConfig(type, [{path: 'plugin-path.js'}, 'plugin-path.js', () => {}]));
|
||||
// Empty config
|
||||
t.false(validateStep(type));
|
||||
t.false(validateStep(type, []));
|
||||
|
||||
t.true(validateConfig(type, {path: 'plugin-path.js'}));
|
||||
t.true(validateConfig(type, 'plugin-path.js'));
|
||||
t.true(validateConfig(type, ['plugin-path.js']));
|
||||
t.true(validateConfig(type, () => {}));
|
||||
// Single value definition
|
||||
t.true(validateStep(type, 'plugin-path.js'));
|
||||
t.true(validateStep(type, () => {}));
|
||||
t.true(validateStep(type, ['plugin-path.js']));
|
||||
t.true(validateStep(type, [() => {}]));
|
||||
t.false(validateStep(type, {}));
|
||||
t.false(validateStep(type, [{}]));
|
||||
|
||||
// Array type definition
|
||||
t.true(validateStep(type, [['plugin-path.js']]));
|
||||
t.true(validateStep(type, [['plugin-path.js', {options: 'value'}]]));
|
||||
t.true(validateStep(type, [[() => {}, {options: 'value'}]]));
|
||||
t.false(validateStep(type, [['plugin-path.js', 1]]));
|
||||
|
||||
// Object type definition
|
||||
t.true(validateStep(type, {path: 'plugin-path.js'}));
|
||||
t.true(validateStep(type, {path: 'plugin-path.js', options: 'value'}));
|
||||
t.true(validateStep(type, {path: () => {}, options: 'value'}));
|
||||
t.false(validateStep(type, {path: null}));
|
||||
|
||||
// Considered as one Array definition and not as an Array of 2 definitions in case of single plugin type
|
||||
t.true(validateStep(type, [() => {}, {options: 'value'}]));
|
||||
t.true(validateStep(type, ['plugin-path.js', {options: 'value'}]));
|
||||
|
||||
// Multiple definitions
|
||||
t.false(
|
||||
validateStep(type, [
|
||||
'plugin-path.js',
|
||||
() => {},
|
||||
['plugin-path.js'],
|
||||
['plugin-path.js', {options: 'value'}],
|
||||
[() => {}, {options: 'value'}],
|
||||
{path: 'plugin-path.js'},
|
||||
{path: 'plugin-path.js', options: 'value'},
|
||||
{path: () => {}, options: 'value'},
|
||||
])
|
||||
);
|
||||
});
|
||||
|
||||
test('Validate single/optional plugin configuration', t => {
|
||||
test('validateStep: single/optional plugin configuration', t => {
|
||||
const type = {multiple: false, required: false};
|
||||
|
||||
t.false(validateConfig(type, {}));
|
||||
t.false(validateConfig(type, {path: null}));
|
||||
t.false(validateConfig(type, [{path: 'plugin-path.js'}, 'plugin-path.js', () => {}]));
|
||||
// Empty config
|
||||
t.true(validateStep(type));
|
||||
t.true(validateStep(type, []));
|
||||
|
||||
t.true(validateConfig(type));
|
||||
t.true(validateConfig(type, []));
|
||||
t.true(validateConfig(type, {path: 'plugin-path.js'}));
|
||||
t.true(validateConfig(type, 'plugin-path.js'));
|
||||
t.true(validateConfig(type, ['plugin-path.js']));
|
||||
t.true(validateConfig(type, () => {}));
|
||||
// Single value definition
|
||||
t.true(validateStep(type, 'plugin-path.js'));
|
||||
t.true(validateStep(type, () => {}));
|
||||
t.true(validateStep(type, ['plugin-path.js']));
|
||||
t.true(validateStep(type, [() => {}]));
|
||||
t.false(validateStep(type, {}));
|
||||
t.false(validateStep(type, [{}]));
|
||||
|
||||
// Array type definition
|
||||
t.true(validateStep(type, [['plugin-path.js']]));
|
||||
t.true(validateStep(type, [['plugin-path.js', {options: 'value'}]]));
|
||||
t.true(validateStep(type, [[() => {}, {options: 'value'}]]));
|
||||
t.false(validateStep(type, [['plugin-path.js', 1]]));
|
||||
|
||||
// Object type definition
|
||||
t.true(validateStep(type, {path: 'plugin-path.js'}));
|
||||
t.true(validateStep(type, {path: 'plugin-path.js', options: 'value'}));
|
||||
t.true(validateStep(type, {path: () => {}, options: 'value'}));
|
||||
t.false(validateStep(type, {path: null}));
|
||||
|
||||
// Considered as one Array definition and not as an Array of 2 definitions in case of single plugin type
|
||||
t.true(validateStep(type, [() => {}, {options: 'value'}]));
|
||||
t.true(validateStep(type, ['plugin-path.js', {options: 'value'}]));
|
||||
|
||||
// Multiple definitions
|
||||
t.false(
|
||||
validateStep(type, [
|
||||
'plugin-path.js',
|
||||
() => {},
|
||||
['plugin-path.js'],
|
||||
['plugin-path.js', {options: 'value'}],
|
||||
[() => {}, {options: 'value'}],
|
||||
{path: 'plugin-path.js'},
|
||||
{path: 'plugin-path.js', options: 'value'},
|
||||
{path: () => {}, options: 'value'},
|
||||
])
|
||||
);
|
||||
});
|
||||
|
||||
test('loadPlugin', t => {
|
||||
const cwd = process.cwd();
|
||||
const func = () => {};
|
||||
|
||||
t.is(require('../fixtures/plugin-noop'), loadPlugin({cwd: './test/fixtures'}, './plugin-noop', {}), 'From cwd');
|
||||
t.is(
|
||||
require('../fixtures/plugin-noop'),
|
||||
loadPlugin({cwd}, './plugin-noop', {'./plugin-noop': './test/fixtures'}),
|
||||
'From a shareable config context'
|
||||
);
|
||||
t.is(func, loadPlugin({cwd}, func, {}), 'Defined as a function');
|
||||
});
|
||||
|
||||
test('parseConfig', t => {
|
||||
const path = 'plugin-module';
|
||||
const options = {option1: 'value1', option2: 'value2'};
|
||||
|
||||
t.deepEqual(parseConfig(path), [path, {}], 'String definition');
|
||||
t.deepEqual(parseConfig({path}), [path, {}], 'Object definition');
|
||||
t.deepEqual(parseConfig({path, ...options}), [path, options], 'Object definition with options');
|
||||
t.deepEqual(parseConfig([path]), [path, {}], 'Array definition');
|
||||
t.deepEqual(parseConfig([path, options]), [path, options], 'Array definition with options');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user