feat(v2): better error message for invalid plugin config (#3979)

* test(v2): improve tests on validating plugins

* fix(v2): make schema for plugins stricter

* fix(v2): emit error if valid type of plugin is not found (#3934)
This commit is contained in:
Joel M 2020-12-31 23:33:24 +09:00 committed by GitHub
parent d5d6e2fba2
commit 869e118e4f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 107 additions and 5 deletions

View file

@ -88,14 +88,79 @@ describe('normalizeConfig', () => {
}).toThrowErrorMatchingSnapshot();
});
test('should throw error if plugins is not array', () => {
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']],
],
[
'should throw error if plugins is not an array of [string, object][] #2',
[[{}, 'example/path']],
],
[
'should throw error if plugins is not an array of [string, object][] #3',
[[{}, {}]],
],
])(`%s for the input of: %p`, (_message, plugins) => {
expect(() => {
normalizeConfig({
plugins: {},
plugins,
});
}).toThrowErrorMatchingSnapshot();
});
test.each([
['should accept [string] for plugins', ['plain/string']],
[
'should accept string[] for plugins',
['plain/string', 'another/plain/string/path'],
],
[
'should accept [string, object] for plugins',
[['plain/string', {it: 'should work'}]],
],
[
'should accept [string, object][] for plugins',
[
['plain/string', {it: 'should work'}],
['this/should/work', {too: 'yes'}],
],
],
[
'should accept ([string, object]|string)[] for plugins',
[
'plain/string',
['plain', {it: 'should work'}],
['this/should/work', {too: 'yes'}],
],
],
])(`%s for the input of: %p`, (_message, plugins) => {
expect(() => {
normalizeConfig({
plugins,
});
}).not.toThrowError();
});
test('should throw error if themes is not array', () => {
expect(() => {
normalizeConfig({