Skip to content

test: #10 set up vitest and add initial audio tests#11

Merged
Tnalxmsk merged 5 commits intodevelopfrom
feat/#10/setup-test
Jan 28, 2026
Merged

test: #10 set up vitest and add initial audio tests#11
Tnalxmsk merged 5 commits intodevelopfrom
feat/#10/setup-test

Conversation

@Tnalxmsk
Copy link
Owner

@Tnalxmsk Tnalxmsk commented Jan 28, 2026

Summary

Set up Vitest-based testing infrastructure and add initial unit tests for the audio manager and hook.

Related Issues

Changes

We needed a lightweight test runner to validate the global singleton audio manager and the React hook behavior without
introducing heavy setup or browser-based E2E tooling. Since this package is distributed as an ESM + TypeScript library,
the test tool needed to align with that environment and keep configuration overhead low.

Vitest was chosen because it is ESM‑friendly out of the box, integrates cleanly with TypeScript, and provides fast
feedback for library development. It also works well with @testing-library/react for hook tests and supports jsdom, which
lets us mock Audio/DOM APIs and test our logic without real media files or a full browser.

In short, Vitest gives us the simplest path to reliable unit/hook tests while matching the project’s ESM/TS setup and
keeping maintenance cost small.

  • Adopt Vitest as the test runner because this repo is ESM (type: "module") and TypeScript-based, and Vitest fits that
    setup with minimal configuration and fast feedback for library development.
  • Configure a jsdom environment and a dedicated setup file so DOM- and Audio-related APIs work reliably in tests without
    real media files or a browser.
  • Mock HTMLMediaElement methods (play, pause, load) and ensure an Audio constructor exists in jsdom, which keeps Audio-
    dependent tests stable and prevents runtime errors.
  • Add initial tests for audioManager to cover core behaviors (source reset, clamped volume/rate, pending seek after
    metadata, error state, stop behavior, event fanout).
  • Add initial tests for useGlobalAudio to validate shared singleton state across hooks and autoPlay wiring, plus add test
    scripts and dev dependencies.

How To Test

npm run test

Checklist

  • Title follows the convention (e.g., feat: add global audio seek guard)
  • Build passes locally (npm run build)
  • No breaking changes, or they are documented below
  • Tests added/updated where appropriate
  • Docs/comments updated where helpful

Breaking Changes (if any)

None.

Notes For Reviewers

None

Screenshots / Recordings (if UI changes)

N/A

- Cover global state sharing across hook instances
- Verify source reset and autoPlay behavior
- Cover source reset, seek deferral, error state, and event fanout
- Verify hook state sharing and autoPlay behavior
@Tnalxmsk Tnalxmsk self-assigned this Jan 28, 2026
@Tnalxmsk Tnalxmsk merged commit c7dd350 into develop Jan 28, 2026
1 check passed
@Tnalxmsk Tnalxmsk deleted the feat/#10/setup-test branch January 28, 2026 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: set up Vitest testing infrastructure

1 participant