brackt/app/test/setup.ts
chrisp 0150fb7ab9
Some checks failed
🚀 Deploy / 🧪 Test (push) Failing after 2m56s
🚀 Deploy / ʦ🔍 Typecheck & Lint (push) Successful in 1m27s
🚀 Deploy / 🐳 Build (push) Has been skipped
🚀 Deploy / 🚀 Deploy (push) Has been skipped
sync racing standings (#80)
Co-authored-by: Claude <noreply@anthropic.com>
Reviewed-on: #80
2026-06-10 04:25:48 +00:00

53 lines
1.6 KiB
TypeScript

import '@testing-library/jest-dom';
import { cleanup } from '@testing-library/react';
import { afterEach, vi } from 'vitest';
// Radix UI / @floating-ui calls requestAnimationFrame for layout and
// positioning on every render (Popover, DropdownMenu, Checkbox focus rings,
// etc.). In jsdom those callbacks are deferred to a future tick, landing
// outside the current act() boundary. React queues the resulting state
// updates, which schedule more microtasks, and the act() settlement loop
// keeps running until Vitest's 5000ms hard timeout kills the test.
//
// Making rAF synchronous keeps every callback inside the current act() cycle
// so there are no pending tasks when the test finishes. This fixes the whole
// class of flaky timeouts without touching individual test files.
global.requestAnimationFrame = (cb: FrameRequestCallback): number => {
cb(performance.now());
return 0;
};
global.cancelAnimationFrame = (_id: number): void => {};
// Cleanup after each test
afterEach(() => {
cleanup();
});
// Mock environment variables
process.env.NODE_ENV = 'test';
// jsdom does not implement scrollTo on elements
HTMLElement.prototype.scrollTo = vi.fn();
// Mock BetterAuth
vi.mock('~/lib/auth.server', () => ({
auth: {
api: {
getSession: vi.fn(() => Promise.resolve({
user: { id: 'test-user-id', email: 'test@example.com', name: 'Test User' },
session: { userId: 'test-user-id' },
})),
},
},
}));
// Mock database context
vi.mock('~/database/context', () => ({
database: vi.fn(() => ({
query: {},
insert: vi.fn(),
update: vi.fn(),
delete: vi.fn(),
select: vi.fn(),
})),
}));