MCPcopy Create free account
hub / github.com/nodejs/node / constructor

Method constructor

deps/undici/src/lib/mock/mock-interceptor.js:61–93  ·  view source on GitHub ↗
(opts, mockDispatches)

Source from the content-addressed store, hash-verified

59 */
60class MockInterceptor {
61 constructor (opts, mockDispatches) {
62 if (typeof opts !== 'object') {
63 throw new InvalidArgumentError('opts must be an object')
64 }
65 if (typeof opts.path === 'undefined') {
66 throw new InvalidArgumentError('opts.path must be defined')
67 }
68 if (typeof opts.method === 'undefined') {
69 opts.method = 'GET'
70 }
71 // See https://github.com/nodejs/undici/issues/1245
72 // As per RFC 3986, clients are not supposed to send URI
73 // fragments to servers when they retrieve a document,
74 if (typeof opts.path === 'string') {
75 if (opts.query) {
76 opts.path = serializePathWithQuery(opts.path, opts.query)
77 } else {
78 // Matches https://github.com/nodejs/undici/blob/main/lib/web/fetch/index.js#L1811
79 const parsedURL = new URL(opts.path, 'data://')
80 opts.path = parsedURL.pathname + parsedURL.search
81 }
82 }
83 if (typeof opts.method === 'string') {
84 opts.method = opts.method.toUpperCase()
85 }
86
87 this[kDispatchKey] = buildKey(opts)
88 this[kDispatches] = mockDispatches
89 this[kIgnoreTrailingSlash] = opts.ignoreTrailingSlash ?? false
90 this[kDefaultHeaders] = {}
91 this[kDefaultTrailers] = {}
92 this[kContentLength] = false
93 }
94
95 createMockScopeDispatchData ({ statusCode, data, responseOptions }) {
96 const responseData = getResponseData(data)

Callers

nothing calls this directly

Calls 2

buildKeyFunction · 0.85
serializePathWithQueryFunction · 0.50

Tested by

no test coverage detected