web-audio-test-api is a JavaScript library designed for testing applications that use the Web Audio API, primarily in CI environments. It provides a mock implementation of the Web Audio API interfaces, which, when imported, replaces the native browser or Node.js-emulated Web Audio API globally. Key features include stricter type checking for audio parameters compared to browser implementations, the ability to serialize an audio graph to a JSON object for assertion and debugging, and tracking of OscillatorNode/BufferSourceNode states. The current stable version is 0.5.2. However, the package appears to be unmaintained, with the last publish occurring over eight years ago, suggesting a very slow or effectively abandoned release cadence. Its primary differentiator is its focus on testability and debuggability through explicit state tracking and serialization, rather than mimicking real-time audio processing.
npm install web-audio-test-apiVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up an AudioContext, create and connect several audio nodes (OscillatorNode, GainNode), configure their properties, and then serialize the entire audio graph to a JSON object for testing or debugging purposes.
Isolate its usage to dedicated test files or environments. Ensure it's imported before any other code that might initialize or check for Web Audio API availability. Use `WebAudioTestAPI.unuse()` if you need to temporarily disable it and restore the original Web Audio API.
Adhere strictly to Web Audio API specifications regarding types (e.g., using enum strings for `type` properties like 'sine' instead of numeric values). Treat any `TypeError` thrown by web-audio-test-api as a potential bug in your audio graph construction.
Evaluate alternative, actively maintained Web Audio API testing solutions if possible. If you must use this library, thoroughly test its compatibility with your target environment and consider forking or contributing fixes yourself. Be aware of potential security risks in unmaintained dependencies.
Ensure `import 'web-audio-test-api';` is the first statement in your test file or in a setup file that runs before any code attempts to instantiate `AudioContext`.
Always assign values to the `.value` property of `AudioParam` interfaces. Correct: `osc.frequency.value = 880;` Incorrect: `osc.frequency = 880;`
Ensure that properties expecting an enum value (like `OscillatorNode.type`) are assigned one of the allowed string values. Correct: `osc.type = 'sawtooth';` Incorrect: `osc.type = 2;`
No dependency data recorded yet.