fix(core): configValidation should allow inline theme functions (#6496)

This commit is contained in:
Sébastien Lorber 2022-01-28 17:49:25 +01:00 committed by GitHub
parent c99026c524
commit f5f598a921
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 175 additions and 24 deletions

View file

@ -117,6 +117,32 @@ describe('normalizeConfig', () => {
}).toThrowErrorMatchingSnapshot();
});
test.each([
['should throw error if themes is not array', {}],
[
"should throw error if themes is not a string and it's not an array #1",
[123],
],
[
'should throw error if themes is not an array of [string, object][] #1',
[['example/path', 'wrong parameter here']],
],
[
'should throw error if themes is not an array of [string, object][] #2',
[[{}, 'example/path']],
],
[
'should throw error if themes is not an array of [string, object][] #3',
[[{}, {}]],
],
])(`%s for the input of: %p`, (_message, themes) => {
expect(() => {
normalizeConfig({
themes,
});
}).toThrowErrorMatchingSnapshot();
});
test.each([
['should accept [string] for plugins', ['plain/string']],
[
@ -155,6 +181,44 @@ describe('normalizeConfig', () => {
}).not.toThrowError();
});
test.each([
['should accept [string] for themes', ['plain/string']],
[
'should accept string[] for themes',
['plain/string', 'another/plain/string/path'],
],
[
'should accept [string, object] for themes',
[['plain/string', {it: 'should work'}]],
],
[
'should accept [string, object][] for themes',
[
['plain/string', {it: 'should work'}],
['this/should/work', {too: 'yes'}],
],
],
[
'should accept ([string, object]|string)[] for themes',
[
'plain/string',
['plain', {it: 'should work'}],
['this/should/work', {too: 'yes'}],
],
],
['should accept function for theme', [function (_context, _options) {}]],
[
'should accept [function, object] for theme',
[[function (_context, _options) {}, {it: 'should work'}]],
],
])(`%s for the input of: %p`, (_message, themes) => {
expect(() => {
normalizeConfig({
themes,
});
}).not.toThrowError();
});
test('should throw error if themes is not array', () => {
expect(() => {
normalizeConfig({