Fix hook timeout in admin.sports-seasons.$id test
Some checks failed
🚀 Deploy / 🧪 Test (pull_request) Failing after 3m39s
🚀 Deploy / ʦ🔍 Typecheck & Lint (pull_request) Successful in 1m39s
🚀 Deploy / 🐳 Build (pull_request) Has been skipped
🚀 Deploy / 🚀 Deploy (pull_request) Has been skipped

vi.resetModules() + multiple await import() in beforeEach forced full
module re-evaluation on every test, exceeding the 10s hook timeout in CI.
Replaced with static top-level imports — vi.mock() hoisting ensures mocks
are in place before the module under test is imported.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Chris Parsons 2026-06-09 22:13:49 -07:00
parent 7a1de6e151
commit 02daff1d1f

View file

@ -1,8 +1,13 @@
import { beforeEach, describe, expect, it, vi } from "vitest"; import { beforeEach, describe, expect, it, vi } from "vitest";
import type { RouterContextProvider } from "react-router"; import type { RouterContextProvider } from "react-router";
import { auth } from "~/lib/auth.server";
import { isUserAdmin } from "~/models/user";
import { findParticipantById, updateParticipant } from "~/models/season-participant";
import { upsertRegularSeasonStandings } from "~/models/regular-season-standings";
import { deletePendingStandingsMapping } from "~/models/pending-standings-mappings";
import { action } from "../admin.sports-seasons.$id";
const ctx = {} as unknown as RouterContextProvider; const ctx = {} as unknown as RouterContextProvider;
let action: any;
vi.mock("~/lib/auth.server", () => ({ vi.mock("~/lib/auth.server", () => ({
auth: { api: { getSession: vi.fn() } }, auth: { api: { getSession: vi.fn() } },
@ -70,32 +75,18 @@ function makeResolveRequest() {
} }
describe("admin.sports-seasons.$id action", () => { describe("admin.sports-seasons.$id action", () => {
beforeEach(async () => { beforeEach(() => {
vi.clearAllMocks(); vi.clearAllMocks();
vi.resetModules();
const { auth } = await import("~/lib/auth.server");
vi.mocked(auth.api.getSession).mockResolvedValue({ user: { id: "admin-1" } } as any); vi.mocked(auth.api.getSession).mockResolvedValue({ user: { id: "admin-1" } } as any);
const { isUserAdmin } = await import("~/models/user");
vi.mocked(isUserAdmin).mockResolvedValue(true); vi.mocked(isUserAdmin).mockResolvedValue(true);
const { findParticipantById, updateParticipant } = await import("~/models/season-participant");
vi.mocked(findParticipantById).mockResolvedValue({ vi.mocked(findParticipantById).mockResolvedValue({
id: "participant-7", id: "participant-7",
name: "Golden State Warriors", name: "Golden State Warriors",
sportsSeasonId: "season-1", sportsSeasonId: "season-1",
} as any); } as any);
vi.mocked(updateParticipant).mockResolvedValue({ id: "participant-7" } as any); vi.mocked(updateParticipant).mockResolvedValue({ id: "participant-7" } as any);
const { upsertRegularSeasonStandings } = await import("~/models/regular-season-standings");
vi.mocked(upsertRegularSeasonStandings).mockResolvedValue(undefined as never); vi.mocked(upsertRegularSeasonStandings).mockResolvedValue(undefined as never);
const { deletePendingStandingsMapping } = await import("~/models/pending-standings-mappings");
vi.mocked(deletePendingStandingsMapping).mockResolvedValue(undefined as never); vi.mocked(deletePendingStandingsMapping).mockResolvedValue(undefined as never);
const routeModule = await import("../admin.sports-seasons.$id");
action = routeModule.action;
}); });
it("returns the resolved API team and participant name after a mapping is confirmed", async () => { it("returns the resolved API team and participant name after a mapping is confirmed", async () => {
@ -114,7 +105,6 @@ describe("admin.sports-seasons.$id action", () => {
}); });
it("rejects a participant from a different sports season", async () => { it("rejects a participant from a different sports season", async () => {
const { findParticipantById, updateParticipant } = await import("~/models/season-participant");
vi.mocked(findParticipantById).mockResolvedValue({ vi.mocked(findParticipantById).mockResolvedValue({
id: "participant-7", id: "participant-7",
name: "Golden State Warriors", name: "Golden State Warriors",