2.2 KiB
test-utils
Purpose
Test-only helpers for the @suaveplan/react-audio test suite. The
module exports three utilities: makeFakeAudioContext, an injectable
BaseAudioContext-shaped stub used by adapter tests; makeFakePlugin,
a minimal AudioFxPlugin implementation with two declared parameters
used by parameter / chain hook tests; and renderWithProvider, a
@testing-library/react wrapper that mounts the component under an
<AudioProvider> configured with the fake context.
The helpers are excluded from coverage and from the production build — they exist purely to keep the test files concise and the assertions focused on behaviour rather than fixture setup.
Features
makeFakeAudioContext(sampleRate?)— returns a plain object that satisfies the engine'sAdapterContextLikeandAudioContextLikestructural interfaces, with every node type stubbed to no-ops.makeFakePlugin(options?)— returns a minimalAudioFxPluginwith two parameters (gain,tone) and a workinggetParameter/setParameterpair.renderWithProvider(ui, opts?, rtlOpts?)— rendersuiinside an<AudioProvider>injected with the fake context;opts.stricttoggles<StrictMode>.
Usage: Basic
import { renderWithProvider } from "../test-utils.js";
renderWithProvider(<Consumer />);
Usage: Advanced
import { makeFakePlugin, renderWithProvider } from "../test-utils.js";
const plugin = makeFakePlugin({ id: "fake-eq" });
renderWithProvider(<UsesPlugin plugin={plugin} />, {
strict: true,
options: { sampleRateHz: 30 },
});
API Reference
makeFakeAudioContext(sampleRate?): unknown.makeFakePlugin(options?): AudioFxPlugin.renderWithProvider(ui, opts?, rtlOptions?).
Implementation Notes
The fake context is a plain object rather than a class because the
engine's structural type checks pass without nominal identity; every
createXxx method returns a tagged stub whose constructor.name
matches the relevant AudioNode class so the engine's
classifyNode helper resolves correctly. The fake plugin's process
is a no-op — these tests do not exercise audio block processing,
only the React-tier event/state surface around the engine.