From 803de20dfe9618f64a3424f2d4a5e4839ecc930b Mon Sep 17 00:00:00 2001 From: simoleo89 Date: Sat, 16 May 2026 11:37:33 +0200 Subject: [PATCH] tests: flatten renderer mock to src/nitro-renderer.mock.ts (drop __mocks__/) The Jest-style __mocks__/ folder added one indirection for a single file. Move the stub to src/nitro-renderer.mock.ts at src/ root next to test-setup.ts, drop the folder, repoint the vitest alias, and update the lone test that imports the helpers directly (useDoorbellState). Same behaviour, one fewer directory. --- CLAUDE.md | 8 ++++---- docs/ARCHITECTURE.md | 4 ++-- src/common/error-boundary/WidgetErrorBoundary.test.tsx | 2 +- src/hooks/rooms/widgets/useDoorbellState.test.tsx | 2 +- .../nitro-renderer.ts => nitro-renderer.mock.ts} | 0 vitest.config.mts | 6 +++--- 6 files changed, 11 insertions(+), 11 deletions(-) rename src/{__mocks__/nitro-renderer.ts => nitro-renderer.mock.ts} (100%) diff --git a/CLAUDE.md b/CLAUDE.md index 61edd80..f184187 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -107,7 +107,7 @@ src/api/ → cross-cutting helpers (LocalizeText src/common/ → reusable UI primitives + error boundary src/state/ → Zustand stores (cross-feature only) src/**/*.test.{ts,tsx} → Vitest suites co-located next to their subject (e.g. `Foo.ts` + `Foo.test.ts`) -src/__mocks__/ → hand-written renderer-SDK stub for tests (aliased over `@nitrots/nitro-renderer`) +src/nitro-renderer.mock.ts → hand-written renderer-SDK stub for tests (aliased over `@nitrots/nitro-renderer`) src/test-setup.ts → Vitest setupFiles entry (jest-dom matchers, etc.) ``` @@ -263,7 +263,7 @@ into `configurePreviewServer` so `yarn preview` keeps working. | God-hook split (state + actions + shim) | `doorbell`, `poll`, `furni-chooser`, `user-chooser`, `friend-request`, `chat-input` | | God-hook split (`useBetween` singleton + state filter + actions filter + shim) | `wired-tools`, `translation`, `notification`, `friends`, `catalog` (three-way: `useCatalogData` / `useCatalogUiState` / `useCatalogActions` — all 48 consumers migrated, deprecated `useCatalog` shim removed) | | `WidgetErrorBoundary` | `RoomWidgetsView` umbrella + per-widget wrap on all 13 room widgets and all 20 furniture widgets (so a crash in one widget no longer takes down its siblings) | -| Vitest | 178/178 cases — pure helpers + 2 Zustand store suites (`navigatorRoomCreatorStore`, `wiredCreatorToolsUiStore`) + 2 component-/hook-level pilots (WidgetErrorBoundary, useDoorbellState) on top of the renderer-SDK mock at `src/__mocks__/nitro-renderer.ts`, 34 cases on the catalog pure helpers, 4 contract cases on the catalog filters. **Tests are co-located** under `src/`, alongside their subject. | +| Vitest | 178/178 cases — pure helpers + 2 Zustand store suites (`navigatorRoomCreatorStore`, `wiredCreatorToolsUiStore`) + 2 component-/hook-level pilots (WidgetErrorBoundary, useDoorbellState) on top of the renderer-SDK mock at `src/nitro-renderer.mock.ts`, 34 cases on the catalog pure helpers, 4 contract cases on the catalog filters. **Tests are co-located** under `src/`, alongside their subject. | | Form Actions | Login / Register / Forgot (LoginView.tsx) | | Cherry-picked from `duckietm` PR #126 | `UserAccountSettingsView` (reset password / email / username under user settings), plus the wear-badge popup `canShowWearButton` gating | @@ -272,7 +272,7 @@ into `configurePreviewServer` so `yarn preview` keeps working. | Split `useChatWidget` / `useAvatarInfoWidget` | Both state-driven via events with no clean imperative actions to extract — skip-motivated. Already touched today for the InfoStand listener move. | | Split `usePetPackageWidget` / `useWordQuizWidget` / `useChatCommandSelector` | Their "actions" mutate internal state or are tightly interdependent — skip-motivated. | | Hoist Wired Creator Tools **derived** state to the Zustand slice | UI-only flags are already hoisted (`useWiredCreatorToolsUiStore`). What's left is the event-driven derived state — `selectedFurni` / `selectedUser` / `monitorSnapshot` / `variableHighlightOverlays` — which can only move alongside their listener effects (multi-session refactor). | -| Widen the component / hook test coverage | Mock layer is in place (`src/__mocks__/nitro-renderer.ts`) and the first 2 pilots pass. Good follow-up targets: other `*State` hooks built on event reducers, `LoginView` Form Actions happy/error paths, OfferView with `useNitroQuery`. | +| Widen the component / hook test coverage | Mock layer is in place (`src/nitro-renderer.mock.ts`) and the first 2 pilots pass. Good follow-up targets: other `*State` hooks built on event reducers, `LoginView` Form Actions happy/error paths, OfferView with `useNitroQuery`. | ## Known open logic bugs @@ -336,7 +336,7 @@ Fix shapes documented; both are reasonable PRs on their own. `useCatalogUiState` / `useCatalogActions` in `src/hooks/catalog/useCatalog.ts` (all 48 consumers migrated; deprecated `useCatalog` shim removed) -- Renderer-SDK mock for Vitest: `src/__mocks__/nitro-renderer.ts` +- Renderer-SDK mock for Vitest: `src/nitro-renderer.mock.ts` (aliased over `@nitrots/nitro-renderer` via `vitest.config.mts`). Hosts the explicit `NitroLogger` mock, the `mockEventDispatcher` / `clearMockEventDispatcher` helpers used by hook tests, the diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 94e2f9d..fccb1be 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -580,7 +580,7 @@ empty-map / partial-bucket branches of the offer lookup). `DOORBELL`, dedup duplicates, remove on `RSDE_ACCEPTED` / `RSDE_REJECTED`, ignore stale events, unsubscribe on unmount. -- **Renderer-SDK mock at `src/__mocks__/nitro-renderer.ts`** — +- **Renderer-SDK mock at `src/nitro-renderer.mock.ts`** — `vitest.config.mts` aliases `@nitrots/nitro-renderer` over this file so jsdom-hosted tests never load Pixi or the message parser/composer registry. The mock exports: @@ -734,7 +734,7 @@ Remaining order of value/risk for the next contributor: each tab. A slice at `src/components/wired-tools/wiredToolsStore.ts` would make each tab subscribe to the keys it needs. 4. **Widen the component/hook Vitest coverage.** The renderer-SDK - mock layer is in place (`src/__mocks__/nitro-renderer.ts`) and the + mock layer is in place (`src/nitro-renderer.mock.ts`) and the first two pilots — `WidgetErrorBoundary` and `useDoorbellState` — pass. Good follow-up targets: other `*State` hooks built on event reducers (`useFurniChooserState`, `useUserChooserState`, diff --git a/src/common/error-boundary/WidgetErrorBoundary.test.tsx b/src/common/error-boundary/WidgetErrorBoundary.test.tsx index 4e76971..03725a6 100644 --- a/src/common/error-boundary/WidgetErrorBoundary.test.tsx +++ b/src/common/error-boundary/WidgetErrorBoundary.test.tsx @@ -7,7 +7,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import { WidgetErrorBoundary } from './WidgetErrorBoundary'; // `import { NitroLogger } from '@nitrots/nitro-renderer'` resolves to -// `src/__mocks__/nitro-renderer.ts` via the alias in vitest.config.mts. +// `src/nitro-renderer.mock.ts` via the alias in vitest.config.mts. // The SUT imports the same path, so both reach the same vi.fn instance. describe('WidgetErrorBoundary', () => diff --git a/src/hooks/rooms/widgets/useDoorbellState.test.tsx b/src/hooks/rooms/widgets/useDoorbellState.test.tsx index 407088d..9335dff 100644 --- a/src/hooks/rooms/widgets/useDoorbellState.test.tsx +++ b/src/hooks/rooms/widgets/useDoorbellState.test.tsx @@ -4,7 +4,7 @@ import { RoomSessionDoorbellEvent } from '@nitrots/nitro-renderer'; import { act, cleanup, renderHook } from '@testing-library/react'; import { afterEach, beforeEach, describe, expect, it } from 'vitest'; import { useDoorbellState } from './useDoorbellState'; -import { clearMockEventDispatcher, mockEventDispatcher } from '../../../__mocks__/nitro-renderer'; +import { clearMockEventDispatcher, mockEventDispatcher } from '../../../nitro-renderer.mock'; // Server push helper — mirrors the renderer wire by emitting the same // constants the SUT listens to. The real constructor takes a session diff --git a/src/__mocks__/nitro-renderer.ts b/src/nitro-renderer.mock.ts similarity index 100% rename from src/__mocks__/nitro-renderer.ts rename to src/nitro-renderer.mock.ts diff --git a/vitest.config.mts b/vitest.config.mts index 59c4208..428021f 100644 --- a/vitest.config.mts +++ b/vitest.config.mts @@ -8,8 +8,8 @@ import { resolve } from 'path'; * * Tests live next to their subject under `src/` (`foo.ts` + `foo.test.ts`). * The renderer SDK is aliased to a hand-written stub at - * `src/__mocks__/nitro-renderer.ts` so jsdom doesn't try to evaluate - * Pixi + the full message parser/composer registry at import time. + * `src/nitro-renderer.mock.ts` so jsdom doesn't try to evaluate Pixi + + * the full message parser/composer registry at import time. */ export default defineConfig({ test: { @@ -21,7 +21,7 @@ export default defineConfig({ }, resolve: { alias: { - '@nitrots/nitro-renderer': resolve(__dirname, 'src/__mocks__/nitro-renderer.ts'), + '@nitrots/nitro-renderer': resolve(__dirname, 'src/nitro-renderer.mock.ts'), '@': resolve(__dirname, 'src') } }