onNetworkRequestEnd function ✓ 100.0%
Last updated: 2026-03-05T11:49:57.418Z
Metrics
LOC: 49
Complexity: 6
Params: 4
Coverage: 100.0% (15/15 lines, 0x executed)
Signature
onNetworkRequestEnd(
url: string,
method: string,
status: number,
): : void
Source Code
function onNetworkRequestEnd(
url: string,
method: string,
status: number,
): void {
pendingNetworkRequests = Math.max(0, pendingNetworkRequests - 1);
lastNetworkActivityTimestamp = now();
// Store response for HTTP assertion generation
capturedResponses.push({ url, method, status, timestamp: now() });
// Add a visible assert step for state-changing requests (POST/PUT/PATCH/DELETE)
// so the user can see AJAX calls in the recording panel and assertions are generated.
// GET/HEAD/OPTIONS are read-only and typically numerous (assets, analytics), we skip them.
if (!["GET", "HEAD", "OPTIONS"].includes(method)) {
addStep({
type: "assert",
timestamp: now(),
url,
value: method,
label: `HTTP ${method} → ${status}`,
assertion: {
type: "response-ok",
// assertionLine() in generators reads url from assertion.selector
selector: url,
expected: String(status),
description: `${method} ${url} → ${status}`,
},
});
}
if (pendingNetworkRequests === 0) {
networkIdleTimer = setTimeout(() => {
if (!session || session.status !== "recording") return;
// Only insert network idle step if last user action was recent
// (indicates the network activity was triggered by user interaction)
const timeSinceLastAction = now() - lastActionTimestamp;
if (timeSinceLastAction < 10_000) {
addStep({
type: "wait-for-network-idle",
timestamp: now(),
label: "Wait for network requests to complete",
waitTimeout: 10_000,
});
}
}, NETWORK_IDLE_THRESHOLD_MS);
}
}
Impact (Incoming)
| Source | Type |
|---|---|
| startNetworkMonitoring | calls |