@@ -5,10 +5,12 @@ import { afterEach, beforeEach, describe, it } from 'node:test'
55import mockFs from 'mock-fs'
66import nock from 'nock'
77
8+ import { normalizePath } from '@socketsecurity/registry/lib/path'
9+
810import { getPackageFiles } from './dist/path-resolve'
911
1012const testPath = __dirname
11- const mockPath = path . join ( testPath , 'mock' )
13+ const mockPath = normalizePath ( path . join ( testPath , 'mock' ) )
1214
1315const globPatterns = {
1416 general : {
@@ -88,10 +90,13 @@ describe('Path Resolve', () => {
8890 [ `${ mockPath } /package.json` ] : '{}'
8991 } )
9092
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
9498 )
99+ assert . deepEqual ( actual . map ( normalizePath ) , [ `${ mockPath } /package.json` ] )
95100 } )
96101
97102 it ( 'should respect ignores from socket config' , async ( ) => {
@@ -102,24 +107,22 @@ describe('Path Resolve', () => {
102107 [ `${ mockPath } /foo/package.json` ] : '{}'
103108 } )
104109
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
122120 )
121+ assert . deepEqual ( actual . map ( normalizePath ) , [
122+ `${ mockPath } /bar/package.json` ,
123+ `${ mockPath } /foo/package-lock.json` ,
124+ `${ mockPath } /foo/package.json`
125+ ] )
123126 } )
124127
125128 it ( 'should respect .gitignore' , async ( ) => {
@@ -131,19 +134,17 @@ describe('Path Resolve', () => {
131134 [ `${ mockPath } /foo/package.json` ] : '{}'
132135 } )
133136
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
146142 )
143+ assert . deepEqual ( actual . map ( normalizePath ) , [
144+ `${ mockPath } /bar/package.json` ,
145+ `${ mockPath } /foo/package-lock.json` ,
146+ `${ mockPath } /foo/package.json`
147+ ] )
147148 } )
148149
149150 it ( 'should always ignore some paths' , async ( ) => {
@@ -162,15 +163,16 @@ describe('Path Resolve', () => {
162163 [ `${ mockPath } /foo/package.json` ] : '{}'
163164 } )
164165
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
173171 )
172+ assert . deepEqual ( actual . map ( normalizePath ) , [
173+ `${ mockPath } /foo/package-lock.json` ,
174+ `${ mockPath } /foo/package.json`
175+ ] )
174176 } )
175177
176178 it ( 'should ignore irrelevant matches' , async ( ) => {
@@ -181,15 +183,16 @@ describe('Path Resolve', () => {
181183 [ `${ mockPath } /foo/random.json` ] : '{}'
182184 } )
183185
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
192191 )
192+ assert . deepEqual ( actual . map ( normalizePath ) , [
193+ `${ mockPath } /foo/package-lock.json` ,
194+ `${ mockPath } /foo/package.json`
195+ ] )
193196 } )
194197
195198 it ( 'should be lenient on oddities' , async ( ) => {
@@ -199,15 +202,13 @@ describe('Path Resolve', () => {
199202 }
200203 } )
201204
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
210210 )
211+ assert . deepEqual ( actual . map ( normalizePath ) , [ ] )
211212 } )
212213
213214 it ( 'should resolve package and lock file' , async ( ) => {
@@ -216,31 +217,30 @@ describe('Path Resolve', () => {
216217 [ `${ mockPath } /package.json` ] : '{}'
217218 } )
218219
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
227225 )
226+ assert . deepEqual ( actual . map ( normalizePath ) , [
227+ `${ mockPath } /package-lock.json` ,
228+ `${ mockPath } /package.json`
229+ ] )
228230 } )
229231
230232 it ( 'should resolve package without lock file' , async ( ) => {
231233 mockFs ( {
232234 [ `${ mockPath } /package.json` ] : '{}'
233235 } )
234236
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
243242 )
243+ assert . deepEqual ( actual . map ( normalizePath ) , [ `${ mockPath } /package.json` ] )
244244 } )
245245
246246 it ( 'should support alternative lock files' , async ( ) => {
@@ -249,15 +249,16 @@ describe('Path Resolve', () => {
249249 [ `${ mockPath } /package.json` ] : '{}'
250250 } )
251251
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
260257 )
258+ assert . deepEqual ( actual . map ( normalizePath ) , [
259+ `${ mockPath } /package.json` ,
260+ `${ mockPath } /yarn.lock`
261+ ] )
261262 } )
262263
263264 it ( 'should handle all variations' , async ( ) => {
@@ -271,23 +272,21 @@ describe('Path Resolve', () => {
271272 [ `${ mockPath } /abc/package.json` ] : '{}'
272273 } )
273274
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
290280 )
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+ ] )
291290 } )
292291 } )
293292} )
0 commit comments