Files
romm/frontend/vitest.setup.ts
Zach Clendenen a0ede752f4 perf(frontend): smaller first load and faster vitest setup (#5072)
* perf(frontend): keep the inactive UI and the markdown renderer out of the first load

vue-router fetches every named view of a route before entering it, so a v2 visit also downloaded the v1 view tree. The inactive UI's views are now deferred until rendered. The changelog dialog, mounted on every v2 page, loads md-editor-v3 on first open.

* perf(frontend): set up Storybook annotations only for the story test

Every vitest file paid for the Storybook preview (full Vuetify and the Storybook runtime) though only storybook.test.ts renders stories.

* fix(frontend): address pr-ready code review

* style(frontend): pr-ready polish

* docs(frontend): pr-ready humanizer pass

* fix(frontend): address Greptile review

- router.test.ts: cover an in-place UI switch, so a deferred view that renders blank fails the suite.
- storybook.test.ts: narrow the preview setup comment to the invariant it guards.

* refactor(frontend): drop the view-loader check from the deferred-view guard

Every route view is a lazy import loader, so a typeof check finds the
inactive UI's views without copying vue-router's own heuristic.

* chore(frontend): restrict direct md-editor-v3 imports

md-editor-v3 now loads lazily on v2 pages outside the game details route,
so an eager import anywhere else would quietly pull it back into a shared
chunk. ESLint now flags it and points at the MarkdownPreview wrapper. Type
imports stay allowed, the frozen v1 trees are skipped, and the list is
shared with the v2/lib block so primitives keep their own restrictions.

* fix(frontend): pr-ready code review

Prefetch every deferred view of the current route on a UI switch, lint
static imports of the md-editor wrappers, make the hand-back test
self-contained, and drop redundant mock resets.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* refactor(frontend): pr-ready simplify

Render MarkdownViewer through the shared MarkdownPreview wrapper, inline
the route-entering check, and set the test UI version once in beforeEach.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* perf(frontend): load md-editor config with its consumers and skip echarts

The md-editor config module now applies itself on import, and each
md-editor consumer (v1 details, NotesTab, MarkdownPreview) imports it,
so md-editor's config, json5 and the XSS filter leave the entry chunk.
Lint flags eager imports of the config module.

Echarts fences render as code and a stub instance stops md-editor from
fetching echarts from unpkg whenever a preview mounts.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Georges-Antoine Assi <contact@me.gantoine.com>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-03 12:55:05 -04:00

19 lines
722 B
TypeScript

import { enableAutoUnmount } from "@vue/test-utils";
import { createPinia, setActivePinia } from "pinia";
import { afterEach, beforeEach, vi } from "vitest";
// Loaded here, before any test file mocks vue-i18n (see __mocks__/vue-i18n.ts),
// so the shared i18n instance is built from the real library.
import "@/locales";
// After-hooks run in reverse, so this lands after auto-unmount clears its timers.
afterEach(() => {
vi.useRealTimers();
});
// A mount left standing keeps its window listeners and timers, which would
// answer the next test's events.
enableAutoUnmount(afterEach);
// Every test starts with empty stores; a test that needs its own Pinia sets it.
beforeEach(() => setActivePinia(createPinia()));