mirror of
https://github.com/openclaw/openclaw.git
synced 2026-02-19 18:39:20 -05:00
test: dedupe fetch cleanup-throw signal harness
This commit is contained in:
@@ -31,6 +31,18 @@ function createForeignSignalHarness() {
|
||||
};
|
||||
}
|
||||
|
||||
function createThrowingCleanupSignalHarness(cleanupError: Error) {
|
||||
const removeEventListener = vi.fn(() => {
|
||||
throw cleanupError;
|
||||
});
|
||||
const fakeSignal = {
|
||||
aborted: false,
|
||||
addEventListener: (_event: string, _handler: () => void) => {},
|
||||
removeEventListener,
|
||||
} as unknown as AbortSignal;
|
||||
return { fakeSignal, removeEventListener };
|
||||
}
|
||||
|
||||
describe("wrapFetchWithAbortSignal", () => {
|
||||
it("adds duplex for requests with a body", async () => {
|
||||
let seenInit: RequestInit | undefined;
|
||||
@@ -122,15 +134,7 @@ describe("wrapFetchWithAbortSignal", () => {
|
||||
);
|
||||
const wrapped = wrapFetchWithAbortSignal(fetchImpl);
|
||||
|
||||
const removeEventListener = vi.fn(() => {
|
||||
throw cleanupError;
|
||||
});
|
||||
|
||||
const fakeSignal = {
|
||||
aborted: false,
|
||||
addEventListener: (_event: string, _handler: () => void) => {},
|
||||
removeEventListener,
|
||||
} as unknown as AbortSignal;
|
||||
const { fakeSignal, removeEventListener } = createThrowingCleanupSignalHarness(cleanupError);
|
||||
|
||||
await expect(wrapped("https://example.com", { signal: fakeSignal })).rejects.toBe(fetchError);
|
||||
expect(removeEventListener).toHaveBeenCalledOnce();
|
||||
@@ -146,15 +150,7 @@ describe("wrapFetchWithAbortSignal", () => {
|
||||
);
|
||||
const wrapped = wrapFetchWithAbortSignal(fetchImpl);
|
||||
|
||||
const removeEventListener = vi.fn(() => {
|
||||
throw cleanupError;
|
||||
});
|
||||
|
||||
const fakeSignal = {
|
||||
aborted: false,
|
||||
addEventListener: (_event: string, _handler: () => void) => {},
|
||||
removeEventListener,
|
||||
} as unknown as AbortSignal;
|
||||
const { fakeSignal, removeEventListener } = createThrowingCleanupSignalHarness(cleanupError);
|
||||
|
||||
expect(() => wrapped("https://example.com", { signal: fakeSignal })).toThrow(syncError);
|
||||
expect(removeEventListener).toHaveBeenCalledOnce();
|
||||
|
||||
Reference in New Issue
Block a user