Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 


Quelle  runtime-fetch.test.ts

  Sprache: JAVA
 

Spracherkennung für: .ts vermutete Sprache: Unknown {[0] [0] [0]} [Methode: Schwerpunktbildung, einfache Gewichte, sechs Dimensionen]

import { afterEach, describe, expect, it, vi } from "vitest";
import { fetchWithRuntimeDispatcher } from "./runtime-fetch.js";
import { TEST_UNDICI_RUNTIME_DEPS_KEY } from "./undici-runtime.js";

class RuntimeFormData {
  readonly records: Array<{
    name: string;
    value: unknown;
    filename?: string;
  }> = [];

  append(name: string, value: unknown, filename?: string): void {
    this.records.push({
      name,
      value,
      ...(typeof filename === "string" ? { filename } : {}),
    });
  }

  *entries(): IterableIterator<[string, unknown]> {
    for (const record of this.records) {
      yield [record.name, record.value];
    }
  }

  get [Symbol.toStringTag](): string {
    return "FormData";
  }
}

class MockAgent {
  readonly __testStub = true;
}

class MockEnvHttpProxyAgent {
  readonly __testStub = true;
}

class MockProxyAgent {
  readonly __testStub = true;
}

afterEach(() => {
  Reflect.deleteProperty(globalThis as object, TEST_UNDICI_RUNTIME_DEPS_KEY);
});

describe("fetchWithRuntimeDispatcher", () => {
  it("normalizes global FormData bodies into the runtime FormData implementation", async () => {
    const runtimeFetch = vi.fn(async (_input: RequestInfo | URL, init?: RequestInit) => {
      // init.body was rebuilt as RuntimeFormData by normalizeRuntimeFormData;
      // BodyInit and RuntimeFormData live in separate type namespaces so a double cast is needed.
      const body = init?.body as unknown as RuntimeFormData;
      expect(body).toBeInstanceOf(RuntimeFormData);
      expect(body.records).toEqual(
        expect.arrayContaining([
          expect.objectContaining({
            name: "model",
            value: "gpt-4o-transcribe",
          }),
          expect.objectContaining({
            name: "file",
            filename: "clip.ogg",
          }),
        ]),
      );
      return new Response("ok", { status: 200 });
    });

    (globalThis as Record<string, unknown>)[TEST_UNDICI_RUNTIME_DEPS_KEY] = {
      Agent: MockAgent,
      EnvHttpProxyAgent: MockEnvHttpProxyAgent,
      FormData: RuntimeFormData,
      ProxyAgent: MockProxyAgent,
      fetch: runtimeFetch,
    };

    const form = new FormData();
    form.append("file", new Blob([new Uint8Array([1, 2, 3])], { type: "audio/ogg" }), "clip.ogg");
    form.append("model", "gpt-4o-transcribe");

    const response = await fetchWithRuntimeDispatcher("https://example.com/upload", {
      method: "POST",
      headers: {
        "content-length": "999",
        "content-type": "multipart/form-data; boundary=stale",
      },
      body: form,
    });

    expect(response.status).toBe(200);
    expect(runtimeFetch).toHaveBeenCalledTimes(1);
    const sentInit = runtimeFetch.mock.calls[0]?.[1] as RequestInit;
    const sentHeaders = new Headers(sentInit.headers);
    expect(sentHeaders.has("content-length")).toBe(false);
    expect(sentHeaders.has("content-type")).toBe(false);
  });
});

¤ Dauer der Verarbeitung: 0.25 Sekunden  (vorverarbeitet am  2026-04-27) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Produkte
     Quellcodebibliothek

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....

Besucherstatistik

Besucherstatistik

Monitoring

Montastic status badge