stoobly
    Preparing search index...

    Class Cypress

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    headers: Record<string, string> = {}
    urls: InterceptorUrl[] = []
    originalFetch:
        | (input: RequestInfo | URL, init?: RequestInit) => Promise<Response> & {
            (input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
            (input: string | Request | URL, init?: RequestInit): Promise<Response>;
        }
        | null = ...

    Type Declaration

    • (input: RequestInfo | URL, init?: RequestInit) => Promise<Response> & {
          (input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
          (input: string | Request | URL, init?: RequestInit): Promise<Response>;
      }
        • (input: RequestInfo | URL, init?: RequestInit): Promise<Response>
        • Parameters

          • input: RequestInfo | URL
          • Optionalinit: RequestInit

          Returns Promise<Response>

        • (input: RequestInfo | URL, init?: RequestInit): Promise<Response>
        • Parameters

          • input: RequestInfo | URL
          • Optionalinit: RequestInit

          Returns Promise<Response>

        • (input: string | Request | URL, init?: RequestInit): Promise<Response>
        • Parameters

          • input: string | Request | URL
          • Optionalinit: RequestInit

          Returns Promise<Response>

    • null
    originalXMLHttpRequestOpen:
        | {
            (method: string, url: string | URL): void;
            (
                method: string,
                url: string | URL,
                async: boolean,
                username?: string | null,
                password?: string | null,
            ): void;
        }
        | null = ...

    Type Declaration

    • {
          (method: string, url: string | URL): void;
          (
              method: string,
              url: string | URL,
              async: boolean,
              username?: string | null,
              password?: string | null,
          ): void;
      }
        • (method: string, url: string | URL): void
        • Sets the request method, request URL, and synchronous flag.

          Throws a "SyntaxError" DOMException if either method is not a valid method or url cannot be parsed.

          Throws a "SecurityError" DOMException if method is a case-insensitive match for CONNECT, TRACE, or TRACK.

          Throws an "InvalidAccessError" DOMException if async is false, current global object is a Window object, and the timeout attribute is not zero or the responseType attribute is not the empty string.

          MDN Reference

          Parameters

          • method: string
          • url: string | URL

          Returns void

        • (
              method: string,
              url: string | URL,
              async: boolean,
              username?: string | null,
              password?: string | null,
          ): void
        • Parameters

          • method: string
          • url: string | URL
          • async: boolean
          • Optionalusername: string | null
          • Optionalpassword: string | null

          Returns void

    • null

    Accessors

    • get urlsToVisit(): (string | RegExp)[]

      Returns (string | RegExp)[]

    Methods

    • Applies HTTP request interception to window.fetch and XMLHttpRequest.

      Behavior:

      • Restores any prior decorations to avoid duplicates, then applies fresh ones.
      • Normalizes and stores URL patterns from settings.urls if provided, otherwise uses constructor settings.urls.
      • Decorates fetch and XHR to inject Stoobly headers for allowed URLs.
      • Applies header-backed settings (mode, record policy/order/strategy, mock policy, scenario key/name) using a stable precedence: explicit settings > previously set fluent headers > constructor defaults.
      • Establishes/returns a session ID (explicit settings.sessionId > fluent .withSessionId() > constructor sessionId > auto-generated timestamp).

      Parameters:

      • settings (optional): Partial
        • urls?: (string | RegExp | InterceptorUrl)[] — URL filters to intercept
        • mode?: InterceptMode — proxy mode (mock, record, replay, test)
        • mock?: { openApiSpecificationPath?: string; policy?: MockPolicy; publicDirectoryPath?: string; responseFixturesPath?: string; }
        • record?: { order?: RecordOrder; policy?: RecordPolicy; strategy?: RecordStrategy }
        • test?: { openApiSpecificationPath?: string; policy?: TestPolicy; publicDirectoryPath?: string; responseFixturesPath?: string; }
        • scenarioKey?: string
        • scenarioName?: string
        • sessionId?: string

      Returns:

      • string — the current session ID

      Notes:

      • Use .enable() instead for clarity; enable() is an alias.

      Parameters

      Returns string | Promise<string>

      Use enable() instead. enable() is an alias provided for clarity.

    • Clears all HTTP request interceptors and resets the interceptor session state.

      Effects:

      • Restores the original window.fetch and XMLHttpRequest.prototype.open implementations.
      • Stops injecting Stoobly headers into subsequent requests.
      • Resets internal session state so a new session ID will be chosen on the next apply()/enable().

      Notes:

      • This does not mutate configured URLs or default headers you've set via the fluent API. Those will be reused on the next apply()/enable() call.

      Returns:

      • void

      Returns void

      Use disable() instead. disable() is an alias for clarity and consistency with enable().

    • Filters out the overwrite record order header after the first request to each URL pattern.

      The overwrite header (RECORD_ORDER and OVERWRITE_ID) should only be sent once per URL pattern in this.urls, not once per actual request URL. This method mutates the urlsToVisit array to track which patterns have already been visited.

      Implementation notes:

      • urlsToVisit is a copy of this.urls created when the interceptor is decorated
      • Each request removes its matching pattern from urlsToVisit
      • When urlsToVisit is empty or pattern not found, both RECORD_ORDER and OVERWRITE_ID are removed from subsequent requests

      Pattern matching:

      • String patterns: Direct equality check (url === urlPattern)
      • RegExp patterns: Pattern test against the actual URL

      Lifecycle safety:

      • For fetch/XHR: urlsToVisit is created once per decorate() call and shared across all intercepted requests. This is safe because restore() removes the interceptor and decorate() creates a fresh urlsToVisit.
      • For Playwright: urlsToVisit is created per decoratePlaywright() call. When withPage() is called with a different page (e.g., in beforeEach), the old handlers are cleaned up via restore() and new handlers with fresh urlsToVisit are created.
      • For Cypress: Same lifecycle as Playwright - decorateCypress() creates fresh urlsToVisit and restore() cleans up old interceptors.

      Example: this.urls = [{ pattern: //api/.+/ }, { pattern: 'https://example.com/exact' }]

      Request 1 to /api/users - matches first pattern, removes from urlsToVisit, includes headers Request 2 to /api/posts - pattern already removed, omits overwrite headers Request 3 to exact URL - matches second pattern, removes from urlsToVisit, includes headers Request 4 to exact URL - pattern already removed, omits overwrite headers

      Parameters

      • headers: Record<string, string>

        The headers object to potentially modify

      • url: string | RegExp

        The URL or URL pattern being requested (actual URL for fetch/XHR, pattern for Playwright/Cypress)

      • urlsToVisit: (string | RegExp)[]

        Mutable array of URL patterns that haven't been visited yet

      Returns void