velxio/frontend/vitest.config.ts

91 lines
3.7 KiB
TypeScript
Raw Normal View History

test(sim): Phase 1d-tests J + C — vitest.config.ts + components-metadata integrity J: vitest.config.ts split out from inline `test:` block in vite.config.ts. CI workflows can now reference vitest.config.ts directly; test settings no longer pulled into vite build deps. Settings: testTimeout 30s, hookTimeout 30s, forks pool with singleFork:false (per-file worker isolation for the NgSpiceNodeAdapter singleton), coverage excludes `src/simulation/spice/wasm/**` (irrelevant lcov bytes). C: components-metadata-integrity.test.ts — 11 sub-tests, all live checks against the real `public/components-metadata.json` + every examples-*.ts source-of-truth + the live PartSimulationRegistry: • Shape per entry: id / tagName / name / category / pinCount • IDs unique • tagName matches wokwi/velxio prefix • Thumbnail is an SVG • properties[] + defaultValues{} shape • Every metadataId referenced from gallery exists in metadata (instr-* filtered — instruments aren't canvas-rendered) • PartSimulationRegistry registrations cross-checked vs metadata (informational — some runtime-only parts have no metadata entry by design: custom-chip, raspberry-pi-3, 74hc595 internals) • Orphan-entries report: surfaces metadata entries no example or part-sim uses (informational, doesn't fail) The orphan report flags 58 dead-ish metadata entries (preset variants like resistor-220, individual epaper sizes, etc.) for later cleanup conversation. Not an error. `PartSimulationRegistry.listRegisteredParts()` exposed for the test to enumerate without duplicating the list. 1472 tests pass (was 1461 — +11 new metadata sub-tests). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-16 03:58:12 +07:00
import { defineConfig } from 'vitest/config';
import path from 'path';
test(sim): Phase 1d-tests J + C — vitest.config.ts + components-metadata integrity J: vitest.config.ts split out from inline `test:` block in vite.config.ts. CI workflows can now reference vitest.config.ts directly; test settings no longer pulled into vite build deps. Settings: testTimeout 30s, hookTimeout 30s, forks pool with singleFork:false (per-file worker isolation for the NgSpiceNodeAdapter singleton), coverage excludes `src/simulation/spice/wasm/**` (irrelevant lcov bytes). C: components-metadata-integrity.test.ts — 11 sub-tests, all live checks against the real `public/components-metadata.json` + every examples-*.ts source-of-truth + the live PartSimulationRegistry: • Shape per entry: id / tagName / name / category / pinCount • IDs unique • tagName matches wokwi/velxio prefix • Thumbnail is an SVG • properties[] + defaultValues{} shape • Every metadataId referenced from gallery exists in metadata (instr-* filtered — instruments aren't canvas-rendered) • PartSimulationRegistry registrations cross-checked vs metadata (informational — some runtime-only parts have no metadata entry by design: custom-chip, raspberry-pi-3, 74hc595 internals) • Orphan-entries report: surfaces metadata entries no example or part-sim uses (informational, doesn't fail) The orphan report flags 58 dead-ish metadata entries (preset variants like resistor-220, individual epaper sizes, etc.) for later cleanup conversation. Not an error. `PartSimulationRegistry.listRegisteredParts()` exposed for the test to enumerate without duplicating the list. 1472 tests pass (was 1461 — +11 new metadata sub-tests). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-16 03:58:12 +07:00
/**
* Vitest configuration split out from `vite.config.ts` (Phase 1d-tests J).
*
* `vite.config.ts` no longer owns the `test:` block; vitest auto-loads
* this file and CI workflows can reference it directly. Defaults below
* tune for the velxio test suite:
*
* - 30 s test timeout: smoke tests iterating 200+ examples need
* headroom; per-test individual asserts are still fast.
* - `forks` pool with `singleFork: false` so each test file runs in
* its own Node worker. The NgSpiceNodeAdapter is a process-wide
* singleton (emscripten module can't reinitialise); without per-file
* 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/...'".
* - `@pro` likewise mirrors vite.config.ts: it resolves to the OSS no-op
* stub by default, or the real overlay when VITE_PRO_BUILD +
* PRO_OVERLAY_PATH are set. data/examples.ts statically imports
* `@pro/data/proExamples`, so without this alias every test that loads
* examples.ts would explode with "Cannot find package '@pro/...'".
test(sim): Phase 1d-tests J + C — vitest.config.ts + components-metadata integrity J: vitest.config.ts split out from inline `test:` block in vite.config.ts. CI workflows can now reference vitest.config.ts directly; test settings no longer pulled into vite build deps. Settings: testTimeout 30s, hookTimeout 30s, forks pool with singleFork:false (per-file worker isolation for the NgSpiceNodeAdapter singleton), coverage excludes `src/simulation/spice/wasm/**` (irrelevant lcov bytes). C: components-metadata-integrity.test.ts — 11 sub-tests, all live checks against the real `public/components-metadata.json` + every examples-*.ts source-of-truth + the live PartSimulationRegistry: • Shape per entry: id / tagName / name / category / pinCount • IDs unique • tagName matches wokwi/velxio prefix • Thumbnail is an SVG • properties[] + defaultValues{} shape • Every metadataId referenced from gallery exists in metadata (instr-* filtered — instruments aren't canvas-rendered) • PartSimulationRegistry registrations cross-checked vs metadata (informational — some runtime-only parts have no metadata entry by design: custom-chip, raspberry-pi-3, 74hc595 internals) • Orphan-entries report: surfaces metadata entries no example or part-sim uses (informational, doesn't fail) The orphan report flags 58 dead-ish metadata entries (preset variants like resistor-220, individual epaper sizes, etc.) for later cleanup conversation. Not an error. `PartSimulationRegistry.listRegisteredParts()` exposed for the test to enumerate without duplicating the list. 1472 tests pass (was 1461 — +11 new metadata sub-tests). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-16 03:58:12 +07:00
*/
const proOverlayPath =
process.env.VITE_PRO_BUILD && process.env.PRO_OVERLAY_PATH
? path.resolve(process.env.PRO_OVERLAY_PATH)
: path.resolve(__dirname, 'src/__pro_stub__');
test(sim): Phase 1d-tests J + C — vitest.config.ts + components-metadata integrity J: vitest.config.ts split out from inline `test:` block in vite.config.ts. CI workflows can now reference vitest.config.ts directly; test settings no longer pulled into vite build deps. Settings: testTimeout 30s, hookTimeout 30s, forks pool with singleFork:false (per-file worker isolation for the NgSpiceNodeAdapter singleton), coverage excludes `src/simulation/spice/wasm/**` (irrelevant lcov bytes). C: components-metadata-integrity.test.ts — 11 sub-tests, all live checks against the real `public/components-metadata.json` + every examples-*.ts source-of-truth + the live PartSimulationRegistry: • Shape per entry: id / tagName / name / category / pinCount • IDs unique • tagName matches wokwi/velxio prefix • Thumbnail is an SVG • properties[] + defaultValues{} shape • Every metadataId referenced from gallery exists in metadata (instr-* filtered — instruments aren't canvas-rendered) • PartSimulationRegistry registrations cross-checked vs metadata (informational — some runtime-only parts have no metadata entry by design: custom-chip, raspberry-pi-3, 74hc595 internals) • Orphan-entries report: surfaces metadata entries no example or part-sim uses (informational, doesn't fail) The orphan report flags 58 dead-ish metadata entries (preset variants like resistor-220, individual epaper sizes, etc.) for later cleanup conversation. Not an error. `PartSimulationRegistry.listRegisteredParts()` exposed for the test to enumerate without duplicating the list. 1472 tests pass (was 1461 — +11 new metadata sub-tests). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-16 03:58:12 +07:00
export default defineConfig({
resolve: {
alias: {
'@velxio': path.resolve(__dirname, 'src'),
'@pro': proOverlayPath,
},
},
// 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
// the read with "Cannot find module '/@fs/...'".
server: { fs: { allow: ['..', '../..'] } },
test(sim): Phase 1d-tests J + C — vitest.config.ts + components-metadata integrity J: vitest.config.ts split out from inline `test:` block in vite.config.ts. CI workflows can now reference vitest.config.ts directly; test settings no longer pulled into vite build deps. Settings: testTimeout 30s, hookTimeout 30s, forks pool with singleFork:false (per-file worker isolation for the NgSpiceNodeAdapter singleton), coverage excludes `src/simulation/spice/wasm/**` (irrelevant lcov bytes). C: components-metadata-integrity.test.ts — 11 sub-tests, all live checks against the real `public/components-metadata.json` + every examples-*.ts source-of-truth + the live PartSimulationRegistry: • Shape per entry: id / tagName / name / category / pinCount • IDs unique • tagName matches wokwi/velxio prefix • Thumbnail is an SVG • properties[] + defaultValues{} shape • Every metadataId referenced from gallery exists in metadata (instr-* filtered — instruments aren't canvas-rendered) • PartSimulationRegistry registrations cross-checked vs metadata (informational — some runtime-only parts have no metadata entry by design: custom-chip, raspberry-pi-3, 74hc595 internals) • Orphan-entries report: surfaces metadata entries no example or part-sim uses (informational, doesn't fail) The orphan report flags 58 dead-ish metadata entries (preset variants like resistor-220, individual epaper sizes, etc.) for later cleanup conversation. Not an error. `PartSimulationRegistry.listRegisteredParts()` exposed for the test to enumerate without duplicating the list. 1472 tests pass (was 1461 — +11 new metadata sub-tests). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-16 03:58:12 +07:00
test: {
globals: true,
environment: 'node',
include: [
'src/__tests__/**/*.test.ts',
'src/**/__tests__/**/*.test.ts',
// velxio-prod pro overlay tests (when run from a velxio-prod
// checkout — these are the source-of-truth pro tests, not the
// stale copies at src/pro/). Harmless on pure-OSS clones
// because the glob has nothing to match there.
'../../pro/frontend/src/pro/**/__tests__/**/*.test.ts',
],
test(sim): Phase 1d-tests J + C — vitest.config.ts + components-metadata integrity J: vitest.config.ts split out from inline `test:` block in vite.config.ts. CI workflows can now reference vitest.config.ts directly; test settings no longer pulled into vite build deps. Settings: testTimeout 30s, hookTimeout 30s, forks pool with singleFork:false (per-file worker isolation for the NgSpiceNodeAdapter singleton), coverage excludes `src/simulation/spice/wasm/**` (irrelevant lcov bytes). C: components-metadata-integrity.test.ts — 11 sub-tests, all live checks against the real `public/components-metadata.json` + every examples-*.ts source-of-truth + the live PartSimulationRegistry: • Shape per entry: id / tagName / name / category / pinCount • IDs unique • tagName matches wokwi/velxio prefix • Thumbnail is an SVG • properties[] + defaultValues{} shape • Every metadataId referenced from gallery exists in metadata (instr-* filtered — instruments aren't canvas-rendered) • PartSimulationRegistry registrations cross-checked vs metadata (informational — some runtime-only parts have no metadata entry by design: custom-chip, raspberry-pi-3, 74hc595 internals) • Orphan-entries report: surfaces metadata entries no example or part-sim uses (informational, doesn't fail) The orphan report flags 58 dead-ish metadata entries (preset variants like resistor-220, individual epaper sizes, etc.) for later cleanup conversation. Not an error. `PartSimulationRegistry.listRegisteredParts()` exposed for the test to enumerate without duplicating the list. 1472 tests pass (was 1461 — +11 new metadata sub-tests). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-16 03:58:12 +07:00
testTimeout: 30_000,
hookTimeout: 30_000,
// Vitest 4 removed `test.poolOptions` — config moved to top-level
// `forks` / `threads` / etc. See the deprecation banner the runner
// emits: "DEPRECATED test.poolOptions was removed in Vitest 4. All
// previous poolOptions are now top-level options."
//
// Each forked worker also needs its heap cap raised because the
// suite leaks state across the 117 test files (ngspice WASM ~30 MB
// per init, MixedModeScheduler singleton, zustand stores). Even
// sharded (60 files / shard) the leak overflows Node's 4 GB
// default; 8 GB plus sharding fits the runner's 16 GB budget.
forks: {
singleFork: false,
execArgv: ['--max-old-space-size=8192'],
test(sim): Phase 1d-tests J + C — vitest.config.ts + components-metadata integrity J: vitest.config.ts split out from inline `test:` block in vite.config.ts. CI workflows can now reference vitest.config.ts directly; test settings no longer pulled into vite build deps. Settings: testTimeout 30s, hookTimeout 30s, forks pool with singleFork:false (per-file worker isolation for the NgSpiceNodeAdapter singleton), coverage excludes `src/simulation/spice/wasm/**` (irrelevant lcov bytes). C: components-metadata-integrity.test.ts — 11 sub-tests, all live checks against the real `public/components-metadata.json` + every examples-*.ts source-of-truth + the live PartSimulationRegistry: • Shape per entry: id / tagName / name / category / pinCount • IDs unique • tagName matches wokwi/velxio prefix • Thumbnail is an SVG • properties[] + defaultValues{} shape • Every metadataId referenced from gallery exists in metadata (instr-* filtered — instruments aren't canvas-rendered) • PartSimulationRegistry registrations cross-checked vs metadata (informational — some runtime-only parts have no metadata entry by design: custom-chip, raspberry-pi-3, 74hc595 internals) • Orphan-entries report: surfaces metadata entries no example or part-sim uses (informational, doesn't fail) The orphan report flags 58 dead-ish metadata entries (preset variants like resistor-220, individual epaper sizes, etc.) for later cleanup conversation. Not an error. `PartSimulationRegistry.listRegisteredParts()` exposed for the test to enumerate without duplicating the list. 1472 tests pass (was 1461 — +11 new metadata sub-tests). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-16 03:58:12 +07:00
},
coverage: {
provider: 'v8',
include: [
'src/simulation/**/*.ts',
'src/utils/exampleTo*.ts',
],
exclude: [
'**/*.test.ts',
'**/__tests__/**',
'src/simulation/spice/wasm/**',
],
reporter: ['text', 'lcov', 'html'],
},
},
});