feat: support multiple plugins for the analyzeCommits step

In case multiple plugins with a `analyzeCommits` step are configured, all of them will be executed and the highest release type (`major` > `minor`, `patch`) will be used.
This commit is contained in:
Pierre Vanduynslager
2018-11-12 15:06:46 -05:00
parent 728ea34dda
commit 5180001ae6
9 changed files with 58 additions and 170 deletions
+10
View File
@@ -51,3 +51,13 @@ test('The "generateNotes" plugins output are concatenated with separator and sen
`Note 1: Exposing token ${SECRET_REPLACEMENT}${RELEASE_NOTES_SEPARATOR}Note 2: Exposing token ${SECRET_REPLACEMENT}`
);
});
test('The "analyzeCommits" plugins output are reduced to the highest release type', t => {
t.is(plugins.analyzeCommits.postprocess(['major', 'minor']), 'major');
t.is(plugins.analyzeCommits.postprocess(['', 'minor']), 'minor');
t.is(plugins.analyzeCommits.postprocess([undefined, 'patch']), 'patch');
t.is(plugins.analyzeCommits.postprocess([null, 'patch']), 'patch');
t.is(plugins.analyzeCommits.postprocess(['wrong_type', 'minor']), 'minor');
t.is(plugins.analyzeCommits.postprocess([]), undefined);
t.is(plugins.analyzeCommits.postprocess(['wrong_type']), undefined);
});
-20
View File
@@ -105,26 +105,6 @@ test('Export plugins based on "plugins" config (single definition)', async t =>
t.is(typeof plugins.fail, 'function');
});
test('Use only last definition of single plugin steps declared in "plugins" config', async t => {
const plugin1 = {analyzeCommits: stub()};
const plugin2 = {analyzeCommits: stub()};
const plugins = getPlugins({cwd, logger: t.context.logger, options: {plugins: [plugin1, plugin2]}}, {});
await plugins.analyzeCommits({commits: []});
t.true(plugin1.analyzeCommits.notCalled);
t.true(plugin2.analyzeCommits.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 step options', async t => {
const plugin1 = [{verifyConditions: stub(), publish: stub()}, {pluginOpt1: 'plugin1'}];
const plugin2 = [{verifyConditions: stub()}, {pluginOpt2: 'plugin2'}];
+3 -95
View File
@@ -25,7 +25,7 @@ test('validatePlugin', t => {
t.false(validatePlugin({path: 1}), 'Object definition, wrong path');
});
test('validateStep: multiple/optional plugin configuration', t => {
test('validateStep: optional plugin configuration', t => {
const type = {multiple: true, required: false};
// Empty config
@@ -107,8 +107,8 @@ test('validateStep: multiple/optional plugin configuration', t => {
);
});
test('validateStep: multiple/required plugin configuration', t => {
const type = {multiple: true, required: true};
test('validateStep: required plugin configuration', t => {
const type = {required: true};
// Empty config
t.false(validateStep(type));
@@ -189,98 +189,6 @@ test('validateStep: multiple/required plugin configuration', t => {
);
});
test('validateStep: single/required plugin configuration', t => {
const type = {multiple: false, required: true};
// 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 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('validateStep: single/optional plugin configuration', t => {
const type = {multiple: false, required: false};
// 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 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 = () => {};