website refactor

This commit is contained in:
2026-01-17 22:55:03 +01:00
parent 64d9e7fd16
commit 69d4cce7f1
64 changed files with 1146 additions and 1014 deletions

View File

@@ -1,3 +1,4 @@
import { describe, test, expect, vi } from 'vitest';
import { createContainer, createTestContainer } from '../container';
import { LEAGUE_SERVICE_TOKEN, LOGGER_TOKEN } from '../tokens';
import { ContainerProvider } from '../providers/ContainerProvider';
@@ -18,32 +19,29 @@ describe('DI System', () => {
test('createTestContainer allows mocking', async () => {
const mockLeagueService = {
getAllLeagues: jest.fn().mockResolvedValue([{ id: '1', name: 'Test League' }]),
getAllLeagues: vi.fn().mockResolvedValue([{ id: '1', name: 'Test League' }]),
};
const overrides = new Map([
[LEAGUE_SERVICE_TOKEN, mockLeagueService],
]);
const container = createTestContainer(overrides);
// Wait for async rebind to complete
await new Promise(resolve => setTimeout(resolve, 10));
const container = await createTestContainer(overrides);
const service = container.get(LEAGUE_SERVICE_TOKEN);
expect(service.getAllLeagues).toBeDefined();
});
test('useInject hook works with ContainerProvider', () => {
test('useInject hook works with ContainerProvider', async () => {
const mockLeagueService = {
getAllLeagues: jest.fn().mockResolvedValue([{ id: '1', name: 'Test League' }]),
getAllLeagues: vi.fn().mockResolvedValue([{ id: '1', name: 'Test League' }]),
};
const overrides = new Map([
[LEAGUE_SERVICE_TOKEN, mockLeagueService],
]);
const container = createTestContainer(overrides);
const container = await createTestContainer(overrides);
const { result } = renderHook(() => useInject(LEAGUE_SERVICE_TOKEN), {
wrapper: ({ children }) => (

View File

@@ -41,16 +41,16 @@ export function createContainer(): Container {
/**
* Creates a container for testing with mock overrides
*/
export function createTestContainer(overrides: Map<symbol, any> = new Map()): Container {
export async function createTestContainer(overrides: Map<symbol, any> = new Map()): Promise<Container> {
const container = createContainer();
// Apply mock overrides using rebind
Array.from(overrides.entries()).forEach(([token, mockInstance]) => {
container.rebind(token).then(bind => bind.toConstantValue(mockInstance));
const promises = Array.from(overrides.entries()).map(([token, mockInstance]) => {
return container.rebind(token).then(bind => bind.toConstantValue(mockInstance));
});
// Return container immediately, mocks will be available after promises resolve
// For synchronous testing, users can bind directly before loading modules
await Promise.all(promises);
return container;
}