Skip to content

Commit

Permalink
composeFilter: support arrays of any of the supported top level types.
Browse files Browse the repository at this point in the history
…Fixes #847.
  • Loading branch information
raineorshine committed Mar 9, 2021
1 parent 26e0162 commit 4016efa
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/versionmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ function composeFilter(filterPattern) {
}
// array
else if (Array.isArray(filterPattern)) {
predicate = s => filterPattern.includes(s)
predicate = s => filterPattern.some(subpattern => composeFilter(subpattern)(s))
}
// raw RegExp
else if (filterPattern instanceof RegExp) {
Expand Down
64 changes: 64 additions & 0 deletions test/filter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,68 @@ describe('filter', () => {
upgraded.should.have.property('lodash')
})

it('filter with regex string', async () => {
const upgraded = await ncu.run({
packageData: JSON.stringify({
dependencies: {
lodash: '2.0.0',
'lodash.map': '2.0.0',
'lodash.filter': '2.0.0'
}
}),
filter: '/lodash\\..*/'
})
upgraded.should.have.property('lodash.map')
upgraded.should.have.property('lodash.filter')
})

it('filter with array of strings', async () => {
const upgraded = await ncu.run({
packageData: JSON.stringify({
dependencies: {
lodash: '2.0.0',
'lodash.map': '2.0.0',
'lodash.filter': '2.0.0'
}
}),
filter: ['lodash.map', 'lodash.filter']
})
upgraded.should.have.property('lodash.map')
upgraded.should.have.property('lodash.filter')
})

it('filter with array of regex', async () => {
const upgraded = await ncu.run({
packageData: JSON.stringify({
dependencies: {
'fp-and-or': '0.1.0',
lodash: '2.0.0',
'lodash.map': '2.0.0',
'lodash.filter': '2.0.0'
}
}),
filter: [/lodash\..*/, /fp.*/]
})
upgraded.should.have.property('lodash.map')
upgraded.should.have.property('lodash.filter')
upgraded.should.have.property('fp-and-or')
})

it('filter with array of regex strings', async () => {
const upgraded = await ncu.run({
packageData: JSON.stringify({
dependencies: {
'fp-and-or': '0.1.0',
lodash: '2.0.0',
'lodash.map': '2.0.0',
'lodash.filter': '2.0.0'
}
}),
filter: ['/lodash\\..*/', '/fp.*/']
})
upgraded.should.have.property('lodash.map')
upgraded.should.have.property('lodash.filter')
upgraded.should.have.property('fp-and-or')
})

})

0 comments on commit 4016efa

Please sign in to comment.