CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-xmlhttprequest

XMLHttpRequest for Node.js that emulates the browser XMLHttpRequest object

Overall
score

75%

Overview
Eval results
Files

task.mdevals/scenario-3/

Request Lifecycle Tracker

Implement an async HTTP helper that relies on the dependency's lifecycle notifications to expose how a request progresses from start to completion.

Capabilities

Records lifecycle transitions

  • For an async GET to http://localhost:4000/ping that responds with status 200 and body "pong", capture each state code from the first transition after starting the request through completion in order [1, 2, 3, 4], and include that log in the resolved result. @test

Emits state-change notifications

  • When a callback is provided, call it on every state change with the latest numeric state and the cumulative state log; a successful GET triggers four callbacks. @test

Completion-driven result

  • Resolve the returned promise only when the completion notification fires, and return an object containing status (200), body ("pong"), and the full state log; do not resolve on intermediate state changes. @test

Abort halts lifecycle

  • If an abort is triggered after the request has started but before completion, stop further lifecycle notifications, reject with the states recorded so far, and return no body text. @test

Implementation

@generates

API

/**
 * Starts an async HTTP GET request to the given URL.
 * @param {string} url
 * @param {(state: number, log: number[]) => void} [onStateChange] optional observer for lifecycle transitions
 * @returns {Promise<{ status: number, body: string, states: number[] }>} resolves when the request finishes, rejects if aborted
 */
export function trackLifecycle(url, onStateChange);

/**
 * Aborts the in-flight request started by trackLifecycle, if any.
 */
export function abortActive();

Dependencies { .dependencies }

xmlhttprequest { .dependency }

Use the dependency-provided evented HTTP client to drive lifecycle tracking.

Install with Tessl CLI

npx tessl i tessl/npm-xmlhttprequest

tile.json