MCPcopy Create free account
hub / github.com/angular/dev-infra / buildMockDispatch

Function buildMockDispatch

github-actions/saucelabs/set-saucelabs-env.js:11118–11145  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11116 });
11117 }
11118 function mockDispatch(opts, handler) {
11119 const key = buildKey(opts);
11120 const mockDispatch2 = getMockDispatch(this[kDispatches], key);
11121 mockDispatch2.timesInvoked++;
11122 if (mockDispatch2.data.callback) {
11123 mockDispatch2.data = __spreadValues(__spreadValues({}, mockDispatch2.data), mockDispatch2.data.callback(opts));
11124 }
11125 const { data: { statusCode, data, headers, trailers, error }, delay, persist } = mockDispatch2;
11126 const { timesInvoked, times } = mockDispatch2;
11127 mockDispatch2.consumed = !persist && timesInvoked >= times;
11128 mockDispatch2.pending = timesInvoked < times;
11129 if (error !== null) {
11130 deleteMockDispatch(this[kDispatches], key);
11131 handler.onError(error);
11132 return true;
11133 }
11134 if (typeof delay === "number" && delay > 0) {
11135 setTimeout(() => {
11136 handleReply(this[kDispatches]);
11137 }, delay);
11138 } else {
11139 handleReply(this[kDispatches]);
11140 }
11141 function handleReply(mockDispatches, _data = data) {
11142 var _a, _b, _c, _d;
11143 const optsHeaders = Array.isArray(opts.headers) ? buildHeadersFromArray(opts.headers) : opts.headers;
11144 const body = typeof _data === "function" ? _data(__spreadProps(__spreadValues({}, opts), { headers: optsHeaders })) : _data;
11145 if (isPromise(body)) {
11146 body.then((newData) => handleReply(mockDispatches, newData));
11147 return;
11148 }

Callers

nothing calls this directly

Calls 1

checkNetConnectFunction · 0.70

Tested by

no test coverage detected