Don't allow empty changed-files objects through

This commit is contained in:
Josh Dales
2023-03-20 17:30:29 -04:00
parent d0d3628020
commit 92990c0c57
2 changed files with 18 additions and 1 deletions

View File

@@ -159,6 +159,15 @@ describe('toChangedFilesMatchConfig', () => {
}); });
}); });
describe('but it has empty values', () => {
const config = {'changed-files': []};
it(`returns an empty object`, () => {
const result = toChangedFilesMatchConfig(config);
expect(result).toEqual<ChangedFilesMatchConfig>({});
});
});
describe('and there is an unknown value in the config', () => { describe('and there is an unknown value in the config', () => {
const config = {'changed-files': [{any: 'testing'}, {sneaky: 'test'}]}; const config = {'changed-files': [{any: 'testing'}, {sneaky: 'test'}]};

View File

@@ -54,7 +54,10 @@ export function toChangedFilesMatchConfig(
}; };
if (Array.isArray(changedFilesConfig)) { if (Array.isArray(changedFilesConfig)) {
if (changedFilesConfig.every(entry => typeof entry === 'string')) { if (
changedFilesConfig.length &&
changedFilesConfig.every(entry => typeof entry === 'string')
) {
changedFilesMatchConfig.changedFiles = { changedFilesMatchConfig.changedFiles = {
any: changedFilesConfig any: changedFilesConfig
}; };
@@ -80,6 +83,11 @@ export function toChangedFilesMatchConfig(
} }
} }
// If no items were added to `changedFiles` then return an empty object
if (!Object.keys(changedFilesMatchConfig.changedFiles).length) {
return {};
}
return changedFilesMatchConfig; return changedFilesMatchConfig;
} }