From 3e383973661fcded5462fb77f9f192e63cf7a99e Mon Sep 17 00:00:00 2001 From: David Montero Date: Thu, 28 May 2026 19:26:21 +0200 Subject: [PATCH] test(frontend): fix 2 test-mock bugs that blocked the deploy gate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. multi-board-integration.test.ts — PinManager mock was missing hardResetPinStates(). Upstream commit d64eebc (fix(stop): reset CPU to PC=0) added that method to PinManager and useSimulatorStore.stopBoard calls it, but this test's vi.mock factory never exposed it. Result: "TypeError: getBoardPinManager(...)?.hardResetPinStates is not a function" even though the optional chain looks safe — the chain only short-circuits on null/undefined, not on a non-function property. 2. vitest.config.ts — was missing the @velxio alias that vite.config.ts defines. defineConfig from vitest/config does NOT auto-inherit from vite.config.ts; the alias has to be re-declared. Without it, overlay tests importing @velxio/store/useEditorStore failed with "Cannot find package '@velxio/...'" even though the build (which DOES inherit the alias) resolves them fine. Verified: full set of 3 previously-failing tests now pass cleanly (multi-board-integration: 43 passed, snapshot: 0, pinIntrospection: 10). 🤖 Generated with Claude Code Co-Authored-By: Claude Opus 4.7 --- .../src/__tests__/multi-board-integration.test.ts | 5 +++++ frontend/vitest.config.ts | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/frontend/src/__tests__/multi-board-integration.test.ts b/frontend/src/__tests__/multi-board-integration.test.ts index 42e26c1b..e0f433cd 100644 --- a/frontend/src/__tests__/multi-board-integration.test.ts +++ b/frontend/src/__tests__/multi-board-integration.test.ts @@ -49,6 +49,11 @@ vi.mock('../simulation/PinManager', () => ({ this.onPinChange = vi.fn().mockReturnValue(() => {}); this.getListenersCount = vi.fn().mockReturnValue(0); this.resetPinStates = vi.fn(); + // Added by upstream commit d64eebc (Stop semantics): the simulator + // store's stopBoard() invokes hardResetPinStates on the active pin + // manager. The mock has to expose it or test calls explode with + // "is not a function" even though the optional chain looks safe. + this.hardResetPinStates = vi.fn(); }), })); diff --git a/frontend/vitest.config.ts b/frontend/vitest.config.ts index f7c97fba..cc41fdab 100644 --- a/frontend/vitest.config.ts +++ b/frontend/vitest.config.ts @@ -1,4 +1,5 @@ import { defineConfig } from 'vitest/config'; +import path from 'path'; /** * Vitest configuration — split out from `vite.config.ts` (Phase 1d-tests J). @@ -15,8 +16,19 @@ import { defineConfig } from 'vitest/config'; * isolation, state leaks between tests sharing the same worker. * - Coverage excludes the WASM bundle (large binary, irrelevant lcov) * and the test files themselves. + * + * - `resolve.alias` mirrors `vite.config.ts` — vitest's defineConfig + * does NOT auto-inherit from vite.config.ts, so the @velxio alias + * used by overlay tests (e.g. pro/.../snapshot.test.ts importing + * `@velxio/store/useEditorStore`) must be declared here too or + * test files explode with "Cannot find package '@velxio/...'". */ export default defineConfig({ + resolve: { + alias: { + '@velxio': path.resolve(__dirname, 'src'), + }, + }, // Allow vitest to import test files / sources from outside this // project root - specifically `../../pro/frontend/src/pro/...` for // velxio-prod overlay tests. Without this, Vite's fs sandbox blocks