diff --git a/core/config/filters.js b/core/config/filters.js index bd33d10edcf9..c6fa3cfcf759 100644 --- a/core/config/filters.js +++ b/core/config/filters.js @@ -287,6 +287,12 @@ function filterConfigByGatherMode(resolvedConfig, mode) { */ function filterConfigByExplicitFilters(resolvedConfig, filters) { const {onlyAudits, onlyCategories, skipAudits} = filters; + if (onlyAudits && !onlyAudits.length) { + throw new Error(`onlyAudits cannot be an empty array.`); + } + if (onlyCategories && !onlyCategories.length) { + throw new Error(`onlyCategories cannot be an empty array.`); + } warnOnUnknownOnlyCategories(resolvedConfig.categories, onlyCategories); diff --git a/core/test/config/filters-test.js b/core/test/config/filters-test.js index d46ea3f05133..aef68a95d020 100644 --- a/core/test/config/filters-test.js +++ b/core/test/config/filters-test.js @@ -634,5 +634,31 @@ describe('Fraggle Rock Config Filtering', () => { artifacts: [{id: 'Snapshot'}, {id: 'Timespan'}], }); }); + + it('should not allow to pass an empty array to onlyAudits', () => { + resolvedConfig = { + ...resolvedConfig, + }; + expect(() => { + filters.filterConfigByExplicitFilters(resolvedConfig, { + onlyAudits: [], + onlyCategories: null, + skipAudits: null, + }); + }).toThrow('onlyAudits cannot be an empty array.'); + }); + + it('should not allow to pass an empty array to onlyCategories', () => { + resolvedConfig = { + ...resolvedConfig, + }; + expect(() => { + filters.filterConfigByExplicitFilters(resolvedConfig, { + onlyAudits: null, + onlyCategories: [], + skipAudits: null, + }); + }).toThrow('onlyCategories cannot be an empty array.'); + }); }); });