@@ -2,6 +2,7 @@ const os = require('node:os')
2
2
const fs = require ( 'node:fs' ) . promises
3
3
const fsSync = require ( 'node:fs' )
4
4
const path = require ( 'node:path' )
5
+ const npmFetch = require ( 'npm-registry-fetch' )
5
6
const tap = require ( 'tap' )
6
7
const mockLogs = require ( './mock-logs.js' )
7
8
const mockGlobals = require ( '@npmcli/mock-globals' )
@@ -449,8 +450,34 @@ function workspaceMock (t, opts) {
449
450
}
450
451
}
451
452
453
+ const mockNpmRegistryFetch = ( tags ) => {
454
+ const fetchOpts = { }
455
+ const getRequest = async ( url , opts ) => {
456
+ if ( fetchOpts [ url ] ) {
457
+ fetchOpts [ url ] . push ( opts )
458
+ } else {
459
+ fetchOpts [ url ] = [ opts ]
460
+ }
461
+ const find = ( { ...tags } ) [ url ]
462
+ if ( typeof find === 'function' ) {
463
+ return find ( )
464
+ }
465
+ return find
466
+ }
467
+ const nrf = async ( url , opts ) => {
468
+ return {
469
+ json : getRequest ( url , opts ) ,
470
+ }
471
+ }
472
+ const mock = Object . assign ( nrf , npmFetch , { json : getRequest } )
473
+ const mocks = { 'npm-registry-fetch' : mock }
474
+ const getOpts = ( url ) => fetchOpts [ url ]
475
+ return { mocks, mock, fetchOpts, getOpts }
476
+ }
477
+
452
478
module . exports = setupMockNpm
453
479
module . exports . load = setupMockNpm
454
480
module . exports . setGlobalNodeModules = setGlobalNodeModules
455
481
module . exports . loadNpmWithRegistry = loadNpmWithRegistry
456
482
module . exports . workspaceMock = workspaceMock
483
+ module . exports . mockNpmRegistryFetch = mockNpmRegistryFetch
0 commit comments