Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core(config): throw an error if a filter is an empty array #15118

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.');
});
});
});