feat(v2): allow config plugins as function or [function,options] (#4618)

* feat : update PluginSchema validation

* feat : update plugin init functionality

* test : add and update tests

* fix : tests

* refactor : init.ts

* test : update test

* docs : add functional plugin docs

* fix little issues

* refactor : refactor code

* minor refactors

* simplify initPlugins code

* simplify initPlugin + add custom validation error message

* fix snapshots

* improve function plugin doc

Co-authored-by: slorber <lorber.sebastien@gmail.com>
This commit is contained in:
besemuna 2021-05-15 17:33:05 +00:00 committed by GitHub
parent e092910627
commit 69be003e12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 460 additions and 124 deletions

View file

@ -90,24 +90,10 @@ describe('normalizeConfig', () => {
test.each([
['should throw error if plugins is not array', {}],
[
'should throw error if plugins is not array',
function () {
console.log('noop');
},
],
[
"should throw error if plugins is not a string and it's not an array #1",
[123],
],
[
"should throw error if plugins is not a string and it's not an array #2",
[
function () {
console.log('noop');
},
],
],
[
'should throw error if plugins is not an array of [string, object][] #1',
[['example/path', 'wrong parameter here']],
@ -153,6 +139,11 @@ describe('normalizeConfig', () => {
['this/should/work', {too: 'yes'}],
],
],
['should accept function for plugin', [function (_context, _options) {}]],
[
'should accept [function, object] for plugin',
[[function (_context, _options) {}, {it: 'should work'}]],
],
])(`%s for the input of: %p`, (_message, plugins) => {
expect(() => {
normalizeConfig({