@@ -43,21 +43,21 @@ describe('CLASS: JsPackageManagerFactory', () => {
43
43
it ( 'ALL EXIST: when all package managers are ok, but only a `package-lock.json` file is found' , ( ) => {
44
44
spawnSyncMock . mockImplementation ( ( command ) => {
45
45
// Yarn is ok
46
- if ( command === 'yarn' ) {
46
+ if ( command === 'yarn --version ' ) {
47
47
return {
48
48
status : 0 ,
49
49
output : '1.22.4' ,
50
50
} ;
51
51
}
52
52
// NPM is ok
53
- if ( command === 'npm' ) {
53
+ if ( command === 'npm --version ' ) {
54
54
return {
55
55
status : 0 ,
56
56
output : '6.5.12' ,
57
57
} ;
58
58
}
59
59
// PNPM is ok
60
- if ( command === 'pnpm' ) {
60
+ if ( command === 'pnpm --version ' ) {
61
61
return {
62
62
status : 0 ,
63
63
output : '7.9.5' ,
@@ -70,7 +70,12 @@ describe('CLASS: JsPackageManagerFactory', () => {
70
70
} ) ;
71
71
72
72
// There is only a package-lock.json
73
- findUpSyncMock . mockImplementation ( ( ) => '/Users/johndoe/Documents/package-lock.json' ) ;
73
+ findUpSyncMock . mockImplementation ( ( filename ) => {
74
+ if ( typeof filename === 'string' && filename === 'package-lock.json' ) {
75
+ return '/Users/johndoe/Documents/package-lock.json' ;
76
+ }
77
+ return undefined ;
78
+ } ) ;
74
79
75
80
expect ( JsPackageManagerFactory . getPackageManager ( ) ) . toBeInstanceOf ( NPMProxy ) ;
76
81
} ) ;
@@ -91,21 +96,21 @@ describe('CLASS: JsPackageManagerFactory', () => {
91
96
it ( 'ALL EXIST: when all package managers are ok, but only a `pnpm-lock.yaml` file is found' , ( ) => {
92
97
spawnSyncMock . mockImplementation ( ( command ) => {
93
98
// Yarn is ok
94
- if ( command === 'yarn' ) {
99
+ if ( command === 'yarn --version ' ) {
95
100
return {
96
101
status : 0 ,
97
102
output : '1.22.4' ,
98
103
} ;
99
104
}
100
105
// NPM is ok
101
- if ( command === 'npm' ) {
106
+ if ( command === 'npm --version ' ) {
102
107
return {
103
108
status : 0 ,
104
109
output : '6.5.12' ,
105
110
} ;
106
111
}
107
112
// PNPM is ok
108
- if ( command === 'pnpm' ) {
113
+ if ( command === 'pnpm --version ' ) {
109
114
return {
110
115
status : 0 ,
111
116
output : '7.9.5' ,
@@ -114,11 +119,16 @@ describe('CLASS: JsPackageManagerFactory', () => {
114
119
// Unknown package manager is ko
115
120
return {
116
121
status : 1 ,
117
- } as any as any ;
122
+ } as any ;
118
123
} ) ;
119
124
120
125
// There is only a pnpm-lock.yaml
121
- findUpSyncMock . mockImplementation ( ( ) => '/Users/johndoe/Documents/pnpm-lock.yaml' ) ;
126
+ findUpSyncMock . mockImplementation ( ( filename ) => {
127
+ if ( typeof filename === 'string' && filename === 'pnpm-lock.yaml' ) {
128
+ return '/Users/johndoe/Documents/pnpm-lock.yaml' ;
129
+ }
130
+ return undefined ;
131
+ } ) ;
122
132
123
133
expect ( JsPackageManagerFactory . getPackageManager ( ) ) . toBeInstanceOf ( PNPMProxy ) ;
124
134
} ) ;
@@ -131,21 +141,21 @@ describe('CLASS: JsPackageManagerFactory', () => {
131
141
132
142
spawnSyncMock . mockImplementation ( ( command ) => {
133
143
// Yarn is ok
134
- if ( command === 'yarn' ) {
144
+ if ( command === 'yarn --version ' ) {
135
145
return {
136
146
status : 0 ,
137
147
output : '1.22.4' ,
138
148
} ;
139
149
}
140
150
// NPM is ok
141
- if ( command === 'npm' ) {
151
+ if ( command === 'npm --version ' ) {
142
152
return {
143
153
status : 0 ,
144
154
output : '6.5.12' ,
145
155
} ;
146
156
}
147
157
// PNPM is ok
148
- if ( command === 'pnpm' ) {
158
+ if ( command === 'pnpm --version ' ) {
149
159
return {
150
160
status : 0 ,
151
161
output : '7.9.5' ,
@@ -176,20 +186,20 @@ describe('CLASS: JsPackageManagerFactory', () => {
176
186
it ( 'when Yarn command is ok and a yarn.lock file is found' , ( ) => {
177
187
spawnSyncMock . mockImplementation ( ( command ) => {
178
188
// Yarn is ok
179
- if ( command === 'yarn' ) {
189
+ if ( command === 'yarn --version ' ) {
180
190
return {
181
191
status : 0 ,
182
192
output : '1.22.4' ,
183
193
} ;
184
194
}
185
195
// NPM is ko
186
- if ( command === 'npm' ) {
196
+ if ( command === 'npm --version ' ) {
187
197
return {
188
198
status : 1 ,
189
199
} ;
190
200
}
191
201
// PNPM is ko
192
- if ( command === 'pnpm' ) {
202
+ if ( command === 'pnpm --version ' ) {
193
203
return {
194
204
status : 1 ,
195
205
} ;
@@ -200,30 +210,35 @@ describe('CLASS: JsPackageManagerFactory', () => {
200
210
} as any ;
201
211
} ) ;
202
212
203
- // there is no lockfile
204
- findUpSyncMock . mockReturnValue ( 'yarn.lock' ) ;
213
+ // there is a yarn.lock file
214
+ findUpSyncMock . mockImplementation ( ( filename ) => {
215
+ if ( typeof filename === 'string' && filename === 'yarn.lock' ) {
216
+ return '/Users/johndoe/Documents/yarn.lock' ;
217
+ }
218
+ return undefined ;
219
+ } ) ;
205
220
206
221
expect ( JsPackageManagerFactory . getPackageManager ( ) ) . toBeInstanceOf ( Yarn1Proxy ) ;
207
222
} ) ;
208
223
209
224
it ( 'when Yarn command is ok, Yarn version is <2, NPM and PNPM are ok, there is a `yarn.lock` file' , ( ) => {
210
225
spawnSyncMock . mockImplementation ( ( command ) => {
211
226
// Yarn is ok
212
- if ( command === 'yarn' ) {
227
+ if ( command === 'yarn --version ' ) {
213
228
return {
214
229
status : 0 ,
215
230
output : '1.22.4' ,
216
231
} ;
217
232
}
218
233
// NPM is ok
219
- if ( command === 'npm' ) {
234
+ if ( command === 'npm --version ' ) {
220
235
return {
221
236
status : 0 ,
222
237
output : '6.5.12' ,
223
238
} ;
224
239
}
225
240
// PNPM is ok
226
- if ( command === 'pnpm' ) {
241
+ if ( command === 'pnpm --version ' ) {
227
242
return {
228
243
status : 0 ,
229
244
output : '7.9.5' ,
@@ -236,7 +251,12 @@ describe('CLASS: JsPackageManagerFactory', () => {
236
251
} ) ;
237
252
238
253
// There is a yarn.lock
239
- findUpSyncMock . mockImplementation ( ( ) => '/Users/johndoe/Documents/yarn.lock' ) ;
254
+ findUpSyncMock . mockImplementation ( ( filename ) => {
255
+ if ( typeof filename === 'string' && filename === 'yarn.lock' ) {
256
+ return '/Users/johndoe/Documents/yarn.lock' ;
257
+ }
258
+ return undefined ;
259
+ } ) ;
240
260
241
261
expect ( JsPackageManagerFactory . getPackageManager ( ) ) . toBeInstanceOf ( Yarn1Proxy ) ;
242
262
} ) ;
@@ -249,21 +269,21 @@ describe('CLASS: JsPackageManagerFactory', () => {
249
269
250
270
spawnSyncMock . mockImplementation ( ( command ) => {
251
271
// Yarn is ok
252
- if ( command === 'yarn' ) {
272
+ if ( command === 'yarn --version ' ) {
253
273
return {
254
274
status : 0 ,
255
275
output : '1.22.4' ,
256
276
} ;
257
277
}
258
278
// NPM is ok
259
- if ( command === 'npm' ) {
279
+ if ( command === 'npm --version ' ) {
260
280
return {
261
281
status : 0 ,
262
282
output : '6.5.12' ,
263
283
} ;
264
284
}
265
285
// PNPM is ok
266
- if ( command === 'pnpm' ) {
286
+ if ( command === 'pnpm --version ' ) {
267
287
return {
268
288
status : 0 ,
269
289
output : '7.9.5' ,
@@ -294,20 +314,20 @@ describe('CLASS: JsPackageManagerFactory', () => {
294
314
it ( 'ONLY YARN 2: when Yarn command is ok, Yarn version is >=2, NPM is ko, PNPM is ko, and a yarn.lock file is found' , ( ) => {
295
315
spawnSyncMock . mockImplementation ( ( command ) => {
296
316
// Yarn is ok
297
- if ( command === 'yarn' ) {
317
+ if ( command === 'yarn --version ' ) {
298
318
return {
299
319
status : 0 ,
300
320
output : '2.0.0-rc.33' ,
301
321
} ;
302
322
}
303
323
// NPM is ko
304
- if ( command === 'npm' ) {
324
+ if ( command === 'npm --version ' ) {
305
325
return {
306
326
status : 1 ,
307
327
} ;
308
328
}
309
329
// PNPM is ko
310
- if ( command === 'pnpm' ) {
330
+ if ( command === 'pnpm --version ' ) {
311
331
return {
312
332
status : 1 ,
313
333
} ;
@@ -318,36 +338,41 @@ describe('CLASS: JsPackageManagerFactory', () => {
318
338
} as any ;
319
339
} ) ;
320
340
321
- findUpSyncMock . mockImplementation ( ( ) => 'yarn.lock' ) ;
341
+ findUpSyncMock . mockImplementation ( ( filename ) => {
342
+ if ( typeof filename === 'string' && filename === 'yarn.lock' ) {
343
+ return '/Users/johndoe/Documents/yarn.lock' ;
344
+ }
345
+ return undefined ;
346
+ } ) ;
322
347
323
348
expect ( JsPackageManagerFactory . getPackageManager ( ) ) . toBeInstanceOf ( Yarn2Proxy ) ;
324
349
} ) ;
325
350
326
351
it ( 'when Yarn command is ok, Yarn version is >=2, NPM and PNPM are ok, there is a `yarn.lock` file' , ( ) => {
327
352
spawnSyncMock . mockImplementation ( ( command ) => {
328
353
// Yarn is ok
329
- if ( command === 'yarn' ) {
354
+ if ( command === 'yarn --version ' ) {
330
355
return {
331
356
status : 0 ,
332
357
output : '2.0.0-rc.33' ,
333
358
} ;
334
359
}
335
360
// NPM is ok
336
- if ( command === 'npm' ) {
361
+ if ( command === 'npm --version ' ) {
337
362
return {
338
363
status : 0 ,
339
364
output : '6.5.12' ,
340
365
} ;
341
366
}
342
367
// PNPM is ok
343
- if ( command === 'pnpm' ) {
368
+ if ( command === 'pnpm --version ' ) {
344
369
return {
345
370
status : 0 ,
346
371
output : '7.9.5' ,
347
372
} ;
348
373
}
349
374
350
- if ( command === 'bun' ) {
375
+ if ( command === 'bun --version ' ) {
351
376
return {
352
377
status : 0 ,
353
378
output : '1.0.0' ,
@@ -359,8 +384,13 @@ describe('CLASS: JsPackageManagerFactory', () => {
359
384
} as any ;
360
385
} ) ;
361
386
362
- // There is a yarn.lock
363
- findUpSyncMock . mockImplementation ( ( ) => '/Users/johndoe/Documents/bun.lockb' ) ;
387
+ // There is a bun.lockb
388
+ findUpSyncMock . mockImplementation ( ( filename ) => {
389
+ if ( typeof filename === 'string' && filename === 'bun.lockb' ) {
390
+ return '/Users/johndoe/Documents/bun.lockb' ;
391
+ }
392
+ return undefined ;
393
+ } ) ;
364
394
365
395
expect ( JsPackageManagerFactory . getPackageManager ( ) ) . toBeInstanceOf ( BUNProxy ) ;
366
396
} ) ;
0 commit comments