Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: clarify
EPLUGINCONF
error message
The message now specify if the step is required and if it allows to configure multiple plugins.
- Loading branch information
Showing
8 changed files
with
116 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const {isString, isFunction, castArray} = require('lodash'); | ||
|
||
const validateSingleConfig = conf => { | ||
conf = castArray(conf); | ||
return conf.length === 1 && (isString(conf[0]) || isString(conf[0].path) || isFunction(conf[0])); | ||
}; | ||
|
||
const validateMultipleConfig = conf => castArray(conf).every(conf => validateSingleConfig(conf)); | ||
|
||
const validateConfig = ({multiple, required}, conf) => { | ||
conf = castArray(conf).filter(Boolean); | ||
if (required) { | ||
return Boolean(conf) && conf.length >= 1 && (multiple ? validateMultipleConfig : validateSingleConfig)(conf); | ||
} | ||
return conf.length === 0 || (multiple ? validateMultipleConfig : validateSingleConfig)(conf); | ||
}; | ||
|
||
module.exports = {validateConfig}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import test from 'ava'; | ||
import {validateConfig} from '../../lib/plugins/utils'; | ||
|
||
test('Validate 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', () => {}])); | ||
}); | ||
|
||
test('Validate 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', () => {}])); | ||
}); | ||
|
||
test('Validate 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', () => {}])); | ||
|
||
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, () => {})); | ||
}); | ||
|
||
test('Validate 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', () => {}])); | ||
|
||
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, () => {})); | ||
}); |