mirror of
https://github.com/kilyabin/psysonic.git
synced 2026-07-22 14:35:41 +00:00
test(frontend): vitest framework bootstrap + hot-path coverage gate (#536)
* test(frontend): vitest framework bootstrap + hot-path file coverage gate
Adds the harness for component, hook and store tests on top of the existing
util tests in src/utils/. Mirrors the backend rust-tests rollout: jsdom env,
v8 coverage, soft hot-path file gate, dedicated CI workflow.
What's in:
- vitest.config.ts: jsdom environment, v8 coverage, alias @ -> src
- src/test/setup.ts: jest-dom, @testing-library cleanup, vi.mock for
@tauri-apps/api/{core,event} + plugin-shell, Map-backed Storage polyfill
for Node 25 + jsdom 26 (both ship a broken native localStorage)
- src/test/mocks/tauri.ts: programmable onInvoke() / emitTauriEvent() helpers,
auto-reset between tests
- src/test/helpers/factories.ts: makeTrack / makeTracks
- src/test/helpers/renderWithProviders.tsx: render() wrapped with
MemoryRouter + I18nextProvider
- src/test/README.md: conventions doc (where tests go, how to mock Tauri,
what to never mock)
Sample tests showing the patterns:
- src/components/CoverLightbox.test.tsx: component, queries by role
- src/store/previewStore.test.ts: store characterization, event handlers
+ stopPreview (startPreview deferred until the cross-store provider
strategy is decided)
CI:
- .github/workflows/frontend-tests.yml: jobs for vitest, tsc, coverage +
hot-path gate. coverage job carries continue-on-error: true (soft).
- .github/frontend-hot-path-files.txt: initial list (3 utils at >=70%).
playerStore + the unfinished half of previewStore are deferred until
Phase 1 coverage work lands.
- scripts/check-frontend-hot-path-coverage.sh: mirror of the rust gate.
npm scripts:
- test: one-shot run (unchanged)
- test⌚ vitest in watch mode
- test:coverage: v8 coverage + html / lcov / json-summary reports
57 / 57 tests pass; tsc --noEmit clean.
* chore(nix): sync npmDepsHash with package-lock.json
---------
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
1cc43dc669
commit
02d533e949
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Test fixture factories.
|
||||
*
|
||||
* Build minimal but valid domain objects with sensible defaults; override only
|
||||
* the fields the test cares about. Keeps tests focused on behaviour rather
|
||||
* than on assembling boilerplate.
|
||||
*/
|
||||
import type { Track } from '@/store/playerStore';
|
||||
|
||||
let trackCounter = 0;
|
||||
|
||||
export function makeTrack(overrides: Partial<Track> = {}): Track {
|
||||
trackCounter += 1;
|
||||
const id = overrides.id ?? `track-${trackCounter}`;
|
||||
return {
|
||||
id,
|
||||
title: `Track ${trackCounter}`,
|
||||
artist: 'Test Artist',
|
||||
album: 'Test Album',
|
||||
albumId: `album-${trackCounter}`,
|
||||
duration: 180,
|
||||
coverArt: id,
|
||||
...overrides,
|
||||
} as Track;
|
||||
}
|
||||
|
||||
export function makeTracks(n: number, overridesFn?: (i: number) => Partial<Track>): Track[] {
|
||||
return Array.from({ length: n }, (_, i) => makeTrack(overridesFn?.(i) ?? {}));
|
||||
}
|
||||
|
||||
export function resetFactoryCounters(): void {
|
||||
trackCounter = 0;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Wraps `render()` from @testing-library/react with the providers most
|
||||
* Psysonic components need: a router (for hooks like useNavigate / useParams)
|
||||
* and i18n (for components that call `useTranslation`).
|
||||
*
|
||||
* Tests that don't need a specific route can call `renderWithProviders(<X />)`.
|
||||
* Tests that need a specific URL pass `{ route: '/album/42' }`.
|
||||
*/
|
||||
import type { ReactElement, ReactNode } from 'react';
|
||||
import { render, type RenderOptions, type RenderResult } from '@testing-library/react';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
import { I18nextProvider } from 'react-i18next';
|
||||
import i18n from '@/i18n';
|
||||
|
||||
interface WrapperOptions {
|
||||
route?: string;
|
||||
}
|
||||
|
||||
function makeWrapper({ route = '/' }: WrapperOptions) {
|
||||
return function Wrapper({ children }: { children: ReactNode }) {
|
||||
return (
|
||||
<I18nextProvider i18n={i18n}>
|
||||
<MemoryRouter initialEntries={[route]}>{children}</MemoryRouter>
|
||||
</I18nextProvider>
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export function renderWithProviders(
|
||||
ui: ReactElement,
|
||||
options: WrapperOptions & Omit<RenderOptions, 'wrapper'> = {},
|
||||
): RenderResult {
|
||||
const { route, ...rest } = options;
|
||||
return render(ui, { wrapper: makeWrapper({ route }), ...rest });
|
||||
}
|
||||
Reference in New Issue
Block a user