Skip to content

FOLLOW-UP: fetch-mock tests don't cover XMLHttpRequest fallback (from PR #74) #77

@adnaan

Description

@adnaan

Context

This follow-up task was identified during the review of PR #74.

Source PR: #74
PR Title: feat: patterns example Session 4 (patterns #17-21) — dialogs, tabs & navigation
Suggested by: @claude[bot] (PR comments, rounds 9, 10, 11)

Task Description

TestTabs/Tab_Switch_Uses_WebSocket_Not_HTTP and TestSPANavigation/Same_Pathname_Step_Update_No_HTTP patch window.fetch and assert zero hits to verify the framework's __navigate__ in-band path doesn't fall back to HTTP. This works today because the LiveTemplate client uses fetch() for the cross-pathname HTTP path.

If the client library ever adds an XMLHttpRequest fallback (older browser support, retry path, etc.), these tests would give false positives — they'd report "0 HTTP hits" while XHR requests fired unobserved.

Suggested Fix

Patch XMLHttpRequest.prototype.open and XMLHttpRequest.prototype.send alongside window.fetch to count both paths:

window.__origXHROpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function(method, url, ...rest) {
    if (url && url.includes('/patterns/navigation/tabs')) window.__navHttpHits++;
    return window.__origXHROpen.call(this, method, url, ...rest);
};

Or, more robustly, use the Chrome DevTools Protocol's Network.requestWillBeSent event via chromedp's network domain rather than monkey-patching browser APIs.

Cross-Reference

This is a real concern only IF the client repo (github.com/livetemplate/client) adds an XHR path. Worth pinning to that change if/when it lands.


Auto-created by prmonitor from PR review comments.

Metadata

Metadata

Assignees

No one assigned

    Labels

    follow-upFollow-up task from PR reviewfrom-reviewIssue originated from PR review

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions