Skip to content

Commit

Permalink
filter: Add test for mixed strings and regex.
Browse files Browse the repository at this point in the history
  • Loading branch information
raineorshine committed Sep 12, 2023
1 parent b066c0b commit 3aaf995
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/initOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function parseFilterExpression(filterExpression: FilterPattern | undefined): Fil
Array.isArray(filterExpression) &&
(filterExpression.length === 0 || typeof filterExpression[0] === 'string')
) {
const filtered = (filterExpression as string[]).map(s => s.trim()).filter(x => x)
const filtered = filterExpression.map(s => (typeof s === 'string' ? s.trim() : s)).filter(x => x)
return filtered.length > 0 ? filtered : undefined
} else {
return filterExpression
Expand Down
19 changes: 19 additions & 0 deletions test/filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,25 @@ describe('filter', () => {
upgraded.should.have.property('fp-and-or')
})

it('filter with array of mixed strings and regex', async () => {
const upgraded = (await ncu({
packageData: {
dependencies: {
'fp-and-or': '0.1.0',
lodash: '2.0.0',
'lodash.map': '2.0.0',
'lodash.filter': '2.0.0',
},
},
filter: ['fp-and-or', /lodash\..*/],
})) as Index<string>
upgraded.should.deep.equal({
'fp-and-or': '99.9.9',
'lodash.map': '99.9.9',
'lodash.filter': '99.9.9',
})
})

it('filter with array of regex strings', async () => {
const upgraded = (await ncu({
packageData: {
Expand Down

0 comments on commit 3aaf995

Please sign in to comment.