import { sleep } from "@hyper-fetch/testing"; import type { ResponseType } from "adapter"; import type { RequestInstance } from "request"; import type { ClientInstance, ResponseInterceptorType } from "client"; import type { HttpAdapterType } from "http-adapter"; import { xhrExtra } from "http-adapter"; export const interceptorCallback = (props?: { sleepTime?: number; callback: () => void; }): ResponseInterceptorType => { const { sleepTime, callback } = props || {}; return async ( response?: ResponseType, ): Promise> => { if (sleepTime) { await sleep(sleepTime); } callback?.(); return ( response || { data: null, error: null, success: true, status: 200, extra: xhrExtra, requestTimestamp: 0, responseTimestamp: 0, } ); }; }; export const middlewareCallback = (props?: { sleepTime?: number; callback: () => void }) => { const { sleepTime, callback } = props || {}; return async (request: RequestInstance): Promise => { if (sleepTime) { await sleep(sleepTime); } callback?.(); return request; }; };