Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
850823e1f5 |
@@ -10,9 +10,6 @@ import { server } from "@/test/server";
|
|||||||
|
|
||||||
import { useScreenSync } from "../index";
|
import { useScreenSync } from "../index";
|
||||||
|
|
||||||
const TRANSPORT_ATTEMPTS = 3;
|
|
||||||
const TRANSPORT_RECOVERY_MS = 3000;
|
|
||||||
|
|
||||||
function auth() {
|
function auth() {
|
||||||
configureAuthClient({
|
configureAuthClient({
|
||||||
accessToken: () => "synthetic",
|
accessToken: () => "synthetic",
|
||||||
@@ -31,13 +28,11 @@ describe("read-only screen synchronization", () => {
|
|||||||
gets += 1;
|
gets += 1;
|
||||||
syncModes.push(new URL(request.url).searchParams.get("sync"));
|
syncModes.push(new URL(request.url).searchParams.get("sync"));
|
||||||
|
|
||||||
// The transport retries a transient read twice (1 s, 2 s) on its own.
|
return gets === 1
|
||||||
return gets <= TRANSPORT_ATTEMPTS
|
|
||||||
? HttpResponse.json({ code: "TBANK_UNAVAILABLE" }, { status: 503 })
|
? HttpResponse.json({ code: "TBANK_UNAVAILABLE" }, { status: 503 })
|
||||||
: HttpResponse.json(resource([]));
|
: HttpResponse.json(resource([]));
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
vi.useFakeTimers();
|
|
||||||
|
|
||||||
const { result } = renderHook(
|
const { result } = renderHook(
|
||||||
() => {
|
() => {
|
||||||
@@ -51,26 +46,12 @@ describe("read-only screen synchronization", () => {
|
|||||||
{ wrapper: createQueryWrapper().wrapper },
|
{ wrapper: createQueryWrapper().wrapper },
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
await waitFor(() => expect(gets).toBe(1));
|
||||||
// Exhaust the transport back-off so the query settles in error.
|
await act(async () => result.current.sync.retry());
|
||||||
await vi.waitFor(async () => {
|
await waitFor(() => expect(result.current.accounts.data).toEqual([]));
|
||||||
await act(() => vi.advanceTimersByTimeAsync(TRANSPORT_RECOVERY_MS));
|
|
||||||
expect(result.current.sync.transportError).toBe(true);
|
|
||||||
});
|
|
||||||
expect(gets).toBe(TRANSPORT_ATTEMPTS);
|
|
||||||
|
|
||||||
await act(async () => result.current.sync.retry());
|
expect(gets).toBe(2);
|
||||||
await vi.waitFor(async () => {
|
expect(syncModes).toEqual([null, null]);
|
||||||
await act(() => vi.advanceTimersByTimeAsync(0));
|
|
||||||
expect(result.current.accounts.data).toEqual([]);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
vi.useRealTimers();
|
|
||||||
}
|
|
||||||
|
|
||||||
expect(gets).toBe(TRANSPORT_ATTEMPTS + 1);
|
|
||||||
expect(syncModes).toEqual(Array.from({ length: gets }, () => null));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("refreshes the currently open resources together", async () => {
|
it("refreshes the currently open resources together", async () => {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import "@testing-library/jest-dom/vitest";
|
import "@testing-library/jest-dom/vitest";
|
||||||
import { cleanup, configure } from "@testing-library/react";
|
import { cleanup, configure } from "@testing-library/react";
|
||||||
import { MotionGlobalConfig } from "motion/react";
|
|
||||||
import { afterAll, afterEach, beforeAll, vi } from "vitest";
|
import { afterAll, afterEach, beforeAll, vi } from "vitest";
|
||||||
|
|
||||||
import { configureAuthClient } from "@/shared/api";
|
import { configureAuthClient } from "@/shared/api";
|
||||||
@@ -11,9 +10,6 @@ import { server } from "./server";
|
|||||||
// Allow async UI updates on the slower CI runner; local waits stay unchanged.
|
// Allow async UI updates on the slower CI runner; local waits stay unchanged.
|
||||||
if (process.env.CI) configure({ asyncUtilTimeout: 5000 });
|
if (process.env.CI) configure({ asyncUtilTimeout: 5000 });
|
||||||
|
|
||||||
// Route fades start at opacity 0; under load toBeVisible can catch that frame.
|
|
||||||
MotionGlobalConfig.skipAnimations = true;
|
|
||||||
|
|
||||||
beforeAll(() => server.listen({ onUnhandledRequest: "error" }));
|
beforeAll(() => server.listen({ onUnhandledRequest: "error" }));
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
cleanup();
|
cleanup();
|
||||||
|
|||||||
Reference in New Issue
Block a user