@@ -5,10 +5,12 @@ import { afterEach, beforeEach, describe, it } from 'node:test'
5
5
import mockFs from 'mock-fs'
6
6
import nock from 'nock'
7
7
8
+ import { normalizePath } from '@socketsecurity/registry/lib/path'
9
+
8
10
import { getPackageFiles } from './dist/path-resolve'
9
11
10
12
const testPath = __dirname
11
- const mockPath = path . join ( testPath , 'mock' )
13
+ const mockPath = normalizePath ( path . join ( testPath , 'mock' ) )
12
14
13
15
const globPatterns = {
14
16
general : {
@@ -88,10 +90,13 @@ describe('Path Resolve', () => {
88
90
[ `${ mockPath } /package.json` ] : '{}'
89
91
} )
90
92
91
- assert . deepEqual (
92
- await sortedGetPackageFiles ( mockPath , [ '.' ] , undefined , globPatterns ) ,
93
- [ `${ mockPath } /package.json` ]
93
+ const actual = await sortedGetPackageFiles (
94
+ mockPath ,
95
+ [ '.' ] ,
96
+ undefined ,
97
+ globPatterns
94
98
)
99
+ assert . deepEqual ( actual . map ( normalizePath ) , [ `${ mockPath } /package.json` ] )
95
100
} )
96
101
97
102
it ( 'should respect ignores from socket config' , async ( ) => {
@@ -102,24 +107,22 @@ describe('Path Resolve', () => {
102
107
[ `${ mockPath } /foo/package.json` ] : '{}'
103
108
} )
104
109
105
- assert . deepEqual (
106
- await sortedGetPackageFiles (
107
- mockPath ,
108
- [ '**/*' ] ,
109
- {
110
- version : 2 ,
111
- projectIgnorePaths : [ 'bar/*' , '!bar/package.json' ] ,
112
- issueRules : { } ,
113
- githubApp : { }
114
- } ,
115
- globPatterns
116
- ) ,
117
- [
118
- `${ mockPath } /bar/package.json` ,
119
- `${ mockPath } /foo/package-lock.json` ,
120
- `${ mockPath } /foo/package.json`
121
- ]
110
+ const actual = await sortedGetPackageFiles (
111
+ mockPath ,
112
+ [ '**/*' ] ,
113
+ {
114
+ version : 2 ,
115
+ projectIgnorePaths : [ 'bar/*' , '!bar/package.json' ] ,
116
+ issueRules : { } ,
117
+ githubApp : { }
118
+ } ,
119
+ globPatterns
122
120
)
121
+ assert . deepEqual ( actual . map ( normalizePath ) , [
122
+ `${ mockPath } /bar/package.json` ,
123
+ `${ mockPath } /foo/package-lock.json` ,
124
+ `${ mockPath } /foo/package.json`
125
+ ] )
123
126
} )
124
127
125
128
it ( 'should respect .gitignore' , async ( ) => {
@@ -131,19 +134,17 @@ describe('Path Resolve', () => {
131
134
[ `${ mockPath } /foo/package.json` ] : '{}'
132
135
} )
133
136
134
- assert . deepEqual (
135
- await sortedGetPackageFiles (
136
- mockPath ,
137
- [ '**/*' ] ,
138
- undefined ,
139
- globPatterns
140
- ) ,
141
- [
142
- `${ mockPath } /bar/package.json` ,
143
- `${ mockPath } /foo/package-lock.json` ,
144
- `${ mockPath } /foo/package.json`
145
- ]
137
+ const actual = await sortedGetPackageFiles (
138
+ mockPath ,
139
+ [ '**/*' ] ,
140
+ undefined ,
141
+ globPatterns
146
142
)
143
+ assert . deepEqual ( actual . map ( normalizePath ) , [
144
+ `${ mockPath } /bar/package.json` ,
145
+ `${ mockPath } /foo/package-lock.json` ,
146
+ `${ mockPath } /foo/package.json`
147
+ ] )
147
148
} )
148
149
149
150
it ( 'should always ignore some paths' , async ( ) => {
@@ -162,15 +163,16 @@ describe('Path Resolve', () => {
162
163
[ `${ mockPath } /foo/package.json` ] : '{}'
163
164
} )
164
165
165
- assert . deepEqual (
166
- await sortedGetPackageFiles (
167
- mockPath ,
168
- [ '**/*' ] ,
169
- undefined ,
170
- globPatterns
171
- ) ,
172
- [ `${ mockPath } /foo/package-lock.json` , `${ mockPath } /foo/package.json` ]
166
+ const actual = await sortedGetPackageFiles (
167
+ mockPath ,
168
+ [ '**/*' ] ,
169
+ undefined ,
170
+ globPatterns
173
171
)
172
+ assert . deepEqual ( actual . map ( normalizePath ) , [
173
+ `${ mockPath } /foo/package-lock.json` ,
174
+ `${ mockPath } /foo/package.json`
175
+ ] )
174
176
} )
175
177
176
178
it ( 'should ignore irrelevant matches' , async ( ) => {
@@ -181,15 +183,16 @@ describe('Path Resolve', () => {
181
183
[ `${ mockPath } /foo/random.json` ] : '{}'
182
184
} )
183
185
184
- assert . deepEqual (
185
- await sortedGetPackageFiles (
186
- mockPath ,
187
- [ '**/*' ] ,
188
- undefined ,
189
- globPatterns
190
- ) ,
191
- [ `${ mockPath } /foo/package-lock.json` , `${ mockPath } /foo/package.json` ]
186
+ const actual = await sortedGetPackageFiles (
187
+ mockPath ,
188
+ [ '**/*' ] ,
189
+ undefined ,
190
+ globPatterns
192
191
)
192
+ assert . deepEqual ( actual . map ( normalizePath ) , [
193
+ `${ mockPath } /foo/package-lock.json` ,
194
+ `${ mockPath } /foo/package.json`
195
+ ] )
193
196
} )
194
197
195
198
it ( 'should be lenient on oddities' , async ( ) => {
@@ -199,15 +202,13 @@ describe('Path Resolve', () => {
199
202
}
200
203
} )
201
204
202
- assert . deepEqual (
203
- await sortedGetPackageFiles (
204
- mockPath ,
205
- [ '**/*' ] ,
206
- undefined ,
207
- globPatterns
208
- ) ,
209
- [ ]
205
+ const actual = await sortedGetPackageFiles (
206
+ mockPath ,
207
+ [ '**/*' ] ,
208
+ undefined ,
209
+ globPatterns
210
210
)
211
+ assert . deepEqual ( actual . map ( normalizePath ) , [ ] )
211
212
} )
212
213
213
214
it ( 'should resolve package and lock file' , async ( ) => {
@@ -216,31 +217,30 @@ describe('Path Resolve', () => {
216
217
[ `${ mockPath } /package.json` ] : '{}'
217
218
} )
218
219
219
- assert . deepEqual (
220
- await sortedGetPackageFiles (
221
- mockPath ,
222
- [ '**/*' ] ,
223
- undefined ,
224
- globPatterns
225
- ) ,
226
- [ `${ mockPath } /package-lock.json` , `${ mockPath } /package.json` ]
220
+ const actual = await sortedGetPackageFiles (
221
+ mockPath ,
222
+ [ '**/*' ] ,
223
+ undefined ,
224
+ globPatterns
227
225
)
226
+ assert . deepEqual ( actual . map ( normalizePath ) , [
227
+ `${ mockPath } /package-lock.json` ,
228
+ `${ mockPath } /package.json`
229
+ ] )
228
230
} )
229
231
230
232
it ( 'should resolve package without lock file' , async ( ) => {
231
233
mockFs ( {
232
234
[ `${ mockPath } /package.json` ] : '{}'
233
235
} )
234
236
235
- assert . deepEqual (
236
- await sortedGetPackageFiles (
237
- mockPath ,
238
- [ '**/*' ] ,
239
- undefined ,
240
- globPatterns
241
- ) ,
242
- [ `${ mockPath } /package.json` ]
237
+ const actual = await sortedGetPackageFiles (
238
+ mockPath ,
239
+ [ '**/*' ] ,
240
+ undefined ,
241
+ globPatterns
243
242
)
243
+ assert . deepEqual ( actual . map ( normalizePath ) , [ `${ mockPath } /package.json` ] )
244
244
} )
245
245
246
246
it ( 'should support alternative lock files' , async ( ) => {
@@ -249,15 +249,16 @@ describe('Path Resolve', () => {
249
249
[ `${ mockPath } /package.json` ] : '{}'
250
250
} )
251
251
252
- assert . deepEqual (
253
- await sortedGetPackageFiles (
254
- mockPath ,
255
- [ '**/*' ] ,
256
- undefined ,
257
- globPatterns
258
- ) ,
259
- [ `${ mockPath } /package.json` , `${ mockPath } /yarn.lock` ]
252
+ const actual = await sortedGetPackageFiles (
253
+ mockPath ,
254
+ [ '**/*' ] ,
255
+ undefined ,
256
+ globPatterns
260
257
)
258
+ assert . deepEqual ( actual . map ( normalizePath ) , [
259
+ `${ mockPath } /package.json` ,
260
+ `${ mockPath } /yarn.lock`
261
+ ] )
261
262
} )
262
263
263
264
it ( 'should handle all variations' , async ( ) => {
@@ -271,23 +272,21 @@ describe('Path Resolve', () => {
271
272
[ `${ mockPath } /abc/package.json` ] : '{}'
272
273
} )
273
274
274
- assert . deepEqual (
275
- await sortedGetPackageFiles (
276
- mockPath ,
277
- [ '**/*' ] ,
278
- undefined ,
279
- globPatterns
280
- ) ,
281
- [
282
- `${ mockPath } /abc/package.json` ,
283
- `${ mockPath } /bar/package.json` ,
284
- `${ mockPath } /bar/yarn.lock` ,
285
- `${ mockPath } /foo/package-lock.json` ,
286
- `${ mockPath } /foo/package.json` ,
287
- `${ mockPath } /package-lock.json` ,
288
- `${ mockPath } /package.json`
289
- ]
275
+ const actual = await sortedGetPackageFiles (
276
+ mockPath ,
277
+ [ '**/*' ] ,
278
+ undefined ,
279
+ globPatterns
290
280
)
281
+ assert . deepEqual ( actual . map ( normalizePath ) , [
282
+ `${ mockPath } /abc/package.json` ,
283
+ `${ mockPath } /bar/package.json` ,
284
+ `${ mockPath } /bar/yarn.lock` ,
285
+ `${ mockPath } /foo/package-lock.json` ,
286
+ `${ mockPath } /foo/package.json` ,
287
+ `${ mockPath } /package-lock.json` ,
288
+ `${ mockPath } /package.json`
289
+ ] )
291
290
} )
292
291
} )
293
292
} )
0 commit comments