Fix hook timeout in admin.sports-seasons.$id test
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:
parent
7a1de6e151
commit
02daff1d1f
1 changed files with 7 additions and 17 deletions
|
|
@ -1,8 +1,13 @@
|
|||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
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;
|
||||
let action: any;
|
||||
|
||||
vi.mock("~/lib/auth.server", () => ({
|
||||
auth: { api: { getSession: vi.fn() } },
|
||||
|
|
@ -70,32 +75,18 @@ function makeResolveRequest() {
|
|||
}
|
||||
|
||||
describe("admin.sports-seasons.$id action", () => {
|
||||
beforeEach(async () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
vi.resetModules();
|
||||
|
||||
const { auth } = await import("~/lib/auth.server");
|
||||
vi.mocked(auth.api.getSession).mockResolvedValue({ user: { id: "admin-1" } } as any);
|
||||
|
||||
const { isUserAdmin } = await import("~/models/user");
|
||||
vi.mocked(isUserAdmin).mockResolvedValue(true);
|
||||
|
||||
const { findParticipantById, updateParticipant } = await import("~/models/season-participant");
|
||||
vi.mocked(findParticipantById).mockResolvedValue({
|
||||
id: "participant-7",
|
||||
name: "Golden State Warriors",
|
||||
sportsSeasonId: "season-1",
|
||||
} 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);
|
||||
|
||||
const { deletePendingStandingsMapping } = await import("~/models/pending-standings-mappings");
|
||||
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 () => {
|
||||
|
|
@ -114,7 +105,6 @@ describe("admin.sports-seasons.$id action", () => {
|
|||
});
|
||||
|
||||
it("rejects a participant from a different sports season", async () => {
|
||||
const { findParticipantById, updateParticipant } = await import("~/models/season-participant");
|
||||
vi.mocked(findParticipantById).mockResolvedValue({
|
||||
id: "participant-7",
|
||||
name: "Golden State Warriors",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue