forked from raineorshine/npm-check-updates
/
filter.test.ts
171 lines (156 loc) · 4.98 KB
/
filter.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import chai from 'chai'
import fs from 'fs/promises'
import path from 'path'
import ncu from '../src'
import { Index } from '../src/types/IndexType'
chai.should()
process.env.NCU_TESTS = 'true'
describe('filter', () => {
it('filter by package name with one arg', async () => {
const upgraded = (await ncu({
packageData: await fs.readFile(path.join(__dirname, './ncu/package2.json'), 'utf-8'),
filter: ['lodash.map'],
})) as Index<string>
upgraded.should.have.property('lodash.map')
upgraded.should.not.have.property('lodash.filter')
})
it('filter by package name with multiple args', async () => {
const upgraded = (await ncu({
packageData: await fs.readFile(path.join(__dirname, './ncu/package2.json'), 'utf-8'),
filter: ['lodash.map', 'lodash.filter'],
})) as Index<string>
upgraded.should.have.property('lodash.map')
upgraded.should.have.property('lodash.filter')
})
it('filter with wildcard', async () => {
const upgraded = (await ncu({
packageData: {
dependencies: {
lodash: '2.0.0',
'lodash.map': '2.0.0',
'lodash.filter': '2.0.0',
},
},
filter: ['lodash.*'],
})) as Index<string>
upgraded.should.have.property('lodash.map')
upgraded.should.have.property('lodash.filter')
})
it('filter with wildcard for scoped package', async () => {
// eslint-disable-next-line jsdoc/require-jsdoc
const withFilter = (filter: string[]) =>
ncu({
packageData: {
dependencies: {
vite: '1.0.0',
'@vitejs/plugin-react': '1.0.0',
'@vitejs/plugin-vue': '1.0.0',
},
},
filter,
}) as Promise<Index<string>>
{
const upgraded = await withFilter(['vite'])
upgraded.should.have.property('vite')
upgraded.should.not.have.property('@vitejs/plugin-react')
upgraded.should.not.have.property('@vitejs/plugin-vue')
}
{
const upgraded = await withFilter(['@vite*'])
upgraded.should.not.have.property('vite')
upgraded.should.have.property('@vitejs/plugin-react')
upgraded.should.have.property('@vitejs/plugin-vue')
}
{
const upgraded = await withFilter(['*vite*'])
upgraded.should.have.property('vite')
upgraded.should.have.property('@vitejs/plugin-react')
upgraded.should.have.property('@vitejs/plugin-vue')
}
{
const upgraded = await withFilter(['*vite*/*react*'])
upgraded.should.not.have.property('vite')
upgraded.should.have.property('@vitejs/plugin-react')
upgraded.should.not.have.property('@vitejs/plugin-vue')
}
{
const upgraded = await withFilter(['*vite*vue*'])
upgraded.should.not.have.property('vite')
upgraded.should.not.have.property('@vitejs/plugin-react')
upgraded.should.have.property('@vitejs/plugin-vue')
}
})
it('filter with negated wildcard', async () => {
const upgraded = (await ncu({
packageData: {
dependencies: {
lodash: '2.0.0',
'lodash.map': '2.0.0',
'lodash.filter': '2.0.0',
},
},
filter: ['!lodash.*'],
})) as Index<string>
upgraded.should.have.property('lodash')
})
it('filter with regex string', async () => {
const upgraded = (await ncu({
packageData: {
dependencies: {
lodash: '2.0.0',
'lodash.map': '2.0.0',
'lodash.filter': '2.0.0',
},
},
filter: '/lodash\\..*/',
})) as Index<string>
upgraded.should.have.property('lodash.map')
upgraded.should.have.property('lodash.filter')
})
it('filter with array of strings', async () => {
const upgraded = (await ncu({
packageData: {
dependencies: {
lodash: '2.0.0',
'lodash.map': '2.0.0',
'lodash.filter': '2.0.0',
},
},
filter: ['lodash.map', 'lodash.filter'],
})) as Index<string>
upgraded.should.have.property('lodash.map')
upgraded.should.have.property('lodash.filter')
})
it('filter with array of 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: [/lodash\..*/, /fp.*/],
})) as Index<string>
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({
packageData: {
dependencies: {
'fp-and-or': '0.1.0',
lodash: '2.0.0',
'lodash.map': '2.0.0',
'lodash.filter': '2.0.0',
},
},
filter: ['/lodash\\..*/', '/fp.*/'],
})) as Index<string>
upgraded.should.have.property('lodash.map')
upgraded.should.have.property('lodash.filter')
upgraded.should.have.property('fp-and-or')
})
})