(opts, handler)
| 11072 | }); |
| 11073 | } |
| 11074 | function mockDispatch(opts, handler) { |
| 11075 | const key = buildKey(opts); |
| 11076 | const mockDispatch2 = getMockDispatch(this[kDispatches], key); |
| 11077 | mockDispatch2.timesInvoked++; |
| 11078 | if (mockDispatch2.data.callback) { |
| 11079 | mockDispatch2.data = __spreadValues(__spreadValues({}, mockDispatch2.data), mockDispatch2.data.callback(opts)); |
| 11080 | } |
| 11081 | const { data: { statusCode, data, headers, trailers, error }, delay, persist } = mockDispatch2; |
| 11082 | const { timesInvoked, times } = mockDispatch2; |
| 11083 | mockDispatch2.consumed = !persist && timesInvoked >= times; |
| 11084 | mockDispatch2.pending = timesInvoked < times; |
| 11085 | if (error !== null) { |
| 11086 | deleteMockDispatch(this[kDispatches], key); |
| 11087 | handler.onError(error); |
| 11088 | return true; |
| 11089 | } |
| 11090 | if (typeof delay === "number" && delay > 0) { |
| 11091 | setTimeout(() => { |
| 11092 | handleReply(this[kDispatches]); |
| 11093 | }, delay); |
| 11094 | } else { |
| 11095 | handleReply(this[kDispatches]); |
| 11096 | } |
| 11097 | function handleReply(mockDispatches, _data = data) { |
| 11098 | var _a, _b, _c, _d; |
| 11099 | const optsHeaders = Array.isArray(opts.headers) ? buildHeadersFromArray(opts.headers) : opts.headers; |
| 11100 | const body = typeof _data === "function" ? _data(__spreadProps(__spreadValues({}, opts), { headers: optsHeaders })) : _data; |
| 11101 | if (isPromise(body)) { |
| 11102 | body.then((newData) => handleReply(mockDispatches, newData)); |
| 11103 | return; |
| 11104 | } |
| 11105 | const responseData = getResponseData(body); |
| 11106 | const responseHeaders = generateKeyValues(headers); |
| 11107 | const responseTrailers = generateKeyValues(trailers); |
| 11108 | (_a = handler.onConnect) == null ? void 0 : _a.call(handler, (err) => handler.onError(err), null); |
| 11109 | (_b = handler.onHeaders) == null ? void 0 : _b.call(handler, statusCode, responseHeaders, resume, getStatusText(statusCode)); |
| 11110 | (_c = handler.onData) == null ? void 0 : _c.call(handler, Buffer.from(responseData)); |
| 11111 | (_d = handler.onComplete) == null ? void 0 : _d.call(handler, responseTrailers); |
| 11112 | deleteMockDispatch(mockDispatches, key); |
| 11113 | } |
| 11114 | function resume() { |
| 11115 | } |
| 11116 | return true; |
| 11117 | } |
| 11118 | function buildMockDispatch() { |
| 11119 | const agent = this[kMockAgent]; |
| 11120 | const origin = this[kOrigin]; |
nothing calls this directly
no test coverage detected