MCPcopy Index your code
hub / github.com/nodejs/node / testRequest

Function testRequest

test/parallel/test-inspector-network-fetch.js:143–174  ·  view source on GitHub ↗
(url)

Source from the content-addressed store, hash-verified

141}
142
143async function testRequest(url) {
144 const requestWillBeSentFuture = once(session, 'Network.requestWillBeSent')
145 .then(([event]) => verifyRequestWillBeSent(event, { url, method: 'POST' }));
146
147 const responseReceivedFuture = once(session, 'Network.responseReceived')
148 .then(([event]) => verifyResponseReceived(event, { url }));
149
150 const loadingFinishedFuture = once(session, 'Network.loadingFinished')
151 .then(([event]) => verifyLoadingFinished(event));
152
153 await fetch(url, {
154 method: 'POST',
155 body: 'foobar',
156 headers: requestHeaders,
157 });
158
159 await requestWillBeSentFuture;
160 const responseReceived = await responseReceivedFuture;
161 const loadingFinished = await loadingFinishedFuture;
162 assert.ok(loadingFinished.timestamp >= responseReceived.timestamp);
163
164 const requestBody = await session.post('Network.getRequestPostData', {
165 requestId: responseReceived.requestId,
166 });
167 assert.strictEqual(requestBody.postData, 'foobar');
168
169 const responseBody = await session.post('Network.getResponseBody', {
170 requestId: responseReceived.requestId,
171 });
172 assert.strictEqual(responseBody.base64Encoded, false);
173 assert.strictEqual(responseBody.body, 'hello world\n');
174}
175
176async function testRequestError(url) {
177 const requestWillBeSentFuture = once(session, 'Network.requestWillBeSent')

Callers 1

testNetworkInspectionFunction · 0.70

Calls 8

fetchFunction · 0.85
onceFunction · 0.70
verifyRequestWillBeSentFunction · 0.70
verifyResponseReceivedFunction · 0.70
verifyLoadingFinishedFunction · 0.70
thenMethod · 0.45
okMethod · 0.45
postMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…