mirror of
https://github.com/langgenius/dify.git
synced 2026-01-19 11:45:05 +08:00
- Replace axios with Node.js native fetch API for HTTP requests - Update HttpClient to use fetch instead of axios instance - Convert axios-specific error handling to fetch-based error mapping - Update response type handling for streams, JSON, text, etc. - Remove axios from package.json dependencies - Update all test files to mock fetch instead of axios This change reduces external dependencies and uses the built-in fetch API available in Node.js 18+, which is already the minimum required version for this SDK.
30 lines
879 B
JavaScript
30 lines
879 B
JavaScript
import { vi } from "vitest";
|
|
import { HttpClient } from "../src/http/client";
|
|
|
|
export const createHttpClient = (configOverrides = {}) => {
|
|
const mockFetch = vi.fn();
|
|
global.fetch = mockFetch;
|
|
const client = new HttpClient({ apiKey: "test", ...configOverrides });
|
|
return { client, mockFetch };
|
|
};
|
|
|
|
export const createHttpClientWithSpies = (configOverrides = {}) => {
|
|
const { client, mockFetch } = createHttpClient(configOverrides);
|
|
const request = vi
|
|
.spyOn(client, "request")
|
|
.mockResolvedValue({ data: "ok", status: 200, headers: {} });
|
|
const requestStream = vi
|
|
.spyOn(client, "requestStream")
|
|
.mockResolvedValue({ data: null });
|
|
const requestBinaryStream = vi
|
|
.spyOn(client, "requestBinaryStream")
|
|
.mockResolvedValue({ data: null });
|
|
return {
|
|
client,
|
|
mockFetch,
|
|
request,
|
|
requestStream,
|
|
requestBinaryStream,
|
|
};
|
|
};
|