Update test format (#821)

* Lint tests, format JSON

* Update test formatting

---------

Co-authored-by: philon- <philon-@users.noreply.github.com>
This commit is contained in:
Jeremy Gallant
2025-08-31 21:30:11 -04:00
committed by GitHub
co-authored by philon-
parent ee131c3681
commit 90cf136b8c
13 changed files with 124 additions and 93 deletions
+25 -7
View File
@@ -1,13 +1,23 @@
import { describe, vi, expect, it, beforeEach, afterEach, type MockInstance } from "vitest";
import {
afterEach,
beforeEach,
describe,
expect,
it,
type MockInstance,
vi,
} from "vitest";
import { runTransportContract } from "../../../tests/utils/transportContract";
import { TransportHTTP } from "./transport";
let abortTimeoutSpy: MockInstance | undefined;
beforeEach(() => {
abortTimeoutSpy = vi.spyOn(
abortTimeoutSpy = vi
.spyOn(
globalThis.AbortSignal as unknown as { timeout(ms: number): AbortSignal },
"timeout",
).mockImplementation((ms: number) => {
)
.mockImplementation((ms: number) => {
const ctrl = new AbortController();
const abort = () =>
ctrl.abort(new DOMException("Timeout reached", "TimeoutError"));
@@ -118,20 +128,28 @@ describe("TransportHTTP (contract)", () => {
vi.unstubAllGlobals();
},
create: async () => {
(globalThis as unknown as { __http: ReturnType<typeof stubFetch> }).__http = stubFetch();
(
globalThis as unknown as { __http: ReturnType<typeof stubFetch> }
).__http = stubFetch();
const transport = await TransportHTTP.create("127.0.0.1:80", false);
await tickNextTimer();
return transport;
},
pushIncoming: async (bytes) => {
(globalThis as unknown as { __http: ReturnType<typeof stubFetch> }).__http.pushIncoming(bytes);
(
globalThis as unknown as { __http: ReturnType<typeof stubFetch> }
).__http.pushIncoming(bytes);
await tickNextTimer();
},
assertLastWritten: (bytes) => {
(globalThis as unknown as { __http: ReturnType<typeof stubFetch> }).__http.assertLastWritten(bytes);
(
globalThis as unknown as { __http: ReturnType<typeof stubFetch> }
).__http.assertLastWritten(bytes);
},
triggerDisconnect: async () => {
(globalThis as unknown as { __http: ReturnType<typeof stubFetch> }).__http.forceReadErrorOnce();
(
globalThis as unknown as { __http: ReturnType<typeof stubFetch> }
).__http.forceReadErrorOnce();
await tickNextTimer();
},
});