Skip to content

Commit

Permalink
core(config): Throw an error if an onlyX filter is an empty array (#1)
Browse files Browse the repository at this point in the history
* throw error if an onlyX filter is an empty array

* added tests to onlyX filters throwing error on empty array
  • Loading branch information
OronW committed May 27, 2023
1 parent e7a6d39 commit 0d07e2a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions core/config/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
26 changes: 26 additions & 0 deletions core/test/config/filters-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
});
});
});

0 comments on commit 0d07e2a

Please sign in to comment.