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.
This commit is contained in:
simoleo89
2026-05-16 11:37:33 +02:00
parent 8b4308af16
commit 803de20dfe
6 changed files with 11 additions and 11 deletions
+4 -4
View File
@@ -107,7 +107,7 @@ src/api/ → cross-cutting helpers (LocalizeText
src/common/ → reusable UI primitives + error boundary src/common/ → reusable UI primitives + error boundary
src/state/ → Zustand stores (cross-feature only) 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/**/*.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.) 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 (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) | | 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) | | `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) | | 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 | | 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 `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. | | 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). | | 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 ## Known open logic bugs
@@ -336,7 +336,7 @@ Fix shapes documented; both are reasonable PRs on their own.
`useCatalogUiState` / `useCatalogActions` in `useCatalogUiState` / `useCatalogActions` in
`src/hooks/catalog/useCatalog.ts` (all 48 consumers migrated; `src/hooks/catalog/useCatalog.ts` (all 48 consumers migrated;
deprecated `useCatalog` shim removed) 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`). (aliased over `@nitrots/nitro-renderer` via `vitest.config.mts`).
Hosts the explicit `NitroLogger` mock, the `mockEventDispatcher` / Hosts the explicit `NitroLogger` mock, the `mockEventDispatcher` /
`clearMockEventDispatcher` helpers used by hook tests, the `clearMockEventDispatcher` helpers used by hook tests, the
+2 -2
View File
@@ -580,7 +580,7 @@ empty-map / partial-bucket branches of the offer lookup).
`DOORBELL`, dedup duplicates, remove on `RSDE_ACCEPTED` / `DOORBELL`, dedup duplicates, remove on `RSDE_ACCEPTED` /
`RSDE_REJECTED`, ignore stale events, unsubscribe on unmount. `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 `vitest.config.mts` aliases `@nitrots/nitro-renderer` over this file
so jsdom-hosted tests never load Pixi or the message so jsdom-hosted tests never load Pixi or the message
parser/composer registry. The mock exports: 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` each tab. A slice at `src/components/wired-tools/wiredToolsStore.ts`
would make each tab subscribe to the keys it needs. would make each tab subscribe to the keys it needs.
4. **Widen the component/hook Vitest coverage.** The renderer-SDK 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` first two pilots — `WidgetErrorBoundary` and `useDoorbellState`
pass. Good follow-up targets: other `*State` hooks built on event pass. Good follow-up targets: other `*State` hooks built on event
reducers (`useFurniChooserState`, `useUserChooserState`, reducers (`useFurniChooserState`, `useUserChooserState`,
@@ -7,7 +7,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { WidgetErrorBoundary } from './WidgetErrorBoundary'; import { WidgetErrorBoundary } from './WidgetErrorBoundary';
// `import { NitroLogger } from '@nitrots/nitro-renderer'` resolves to // `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. // The SUT imports the same path, so both reach the same vi.fn instance.
describe('WidgetErrorBoundary', () => describe('WidgetErrorBoundary', () =>
@@ -4,7 +4,7 @@ import { RoomSessionDoorbellEvent } from '@nitrots/nitro-renderer';
import { act, cleanup, renderHook } from '@testing-library/react'; import { act, cleanup, renderHook } from '@testing-library/react';
import { afterEach, beforeEach, describe, expect, it } from 'vitest'; import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import { useDoorbellState } from './useDoorbellState'; 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 // Server push helper — mirrors the renderer wire by emitting the same
// constants the SUT listens to. The real constructor takes a session // constants the SUT listens to. The real constructor takes a session
+3 -3
View File
@@ -8,8 +8,8 @@ import { resolve } from 'path';
* *
* Tests live next to their subject under `src/` (`foo.ts` + `foo.test.ts`). * Tests live next to their subject under `src/` (`foo.ts` + `foo.test.ts`).
* The renderer SDK is aliased to a hand-written stub at * The renderer SDK is aliased to a hand-written stub at
* `src/__mocks__/nitro-renderer.ts` so jsdom doesn't try to evaluate * `src/nitro-renderer.mock.ts` so jsdom doesn't try to evaluate Pixi +
* Pixi + the full message parser/composer registry at import time. * the full message parser/composer registry at import time.
*/ */
export default defineConfig({ export default defineConfig({
test: { test: {
@@ -21,7 +21,7 @@ export default defineConfig({
}, },
resolve: { resolve: {
alias: { alias: {
'@nitrots/nitro-renderer': resolve(__dirname, 'src/__mocks__/nitro-renderer.ts'), '@nitrots/nitro-renderer': resolve(__dirname, 'src/nitro-renderer.mock.ts'),
'@': resolve(__dirname, 'src') '@': resolve(__dirname, 'src')
} }
} }