Registry / testing / web-audio-test-api

web-audio-test-api

JSON →
library0.5.2jsnpmunverified

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-api
INSTALL
IMPORT
SIG · WEB-AUDIO-TEST-API
W
web-audio-test-api
testingjavascriptv0.5.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Side Effect Global Install
import 'web-audio-test-api';
const WebAudioTestAPI = require('web-audio-test-api');
This import statement installs the Web Audio API interfaces (like AudioContext, OscillatorNode) onto the global scope. It does not export any specific symbols directly.
WebAudioTestAPI
import 'web-audio-test-api'; // Then, WebAudioTestAPI is available globally WebAudioTestAPI.unuse();
After the global import, the `WebAudioTestAPI` object becomes globally available, primarily used for methods like `unuse()` to revert the global replacement.
AudioContext
import 'web-audio-test-api'; const audioContext = new AudioContext();
import { AudioContext } from 'web-audio-test-api';
AudioContext and other Web Audio API interfaces are made globally available after the side-effect import; they are not named exports from the package.

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.

import 'web-audio-test-api'; // Create a test AudioContext instance const audioContext = new AudioContext(); // Create some nodes and connect them const osc = audioContext.createOscillator(); const lfo = audioContext.createOscillator(); const amp = audioContext.createGain(); // Assign an ID for easier debugging in the JSON output lfo.$id = 'LFO'; // Configure node properties osc.type = 'sawtooth'; osc.frequency.value = 880; lfo.frequency.value = 2; // Connect the audio graph lfo.connect(amp.gain); osc.connect(amp); amp.connect(audioContext.destination); // Output the audio graph as a JSON object for inspection const graphJson = audioContext.toJSON(); // In a test environment, you would assert on this JSON structure // For demonstration, we'll log it. console.log(JSON.stringify(graphJson, null, 2)); /* Expected output (truncated): { "name": "AudioDestinationNode", "inputs": [ { "name": "GainNode", "gain": { "value": 1, "inputs": [ { "name": "OscillatorNode#LFO", "type": "sine", "frequency": { "value": 2, "inputs": [] }, "detune": { "value": 0, "inputs": [] }, "inputs": [] } ] }, "inputs": [ { "name": "OscillatorNode", "type": "sawtooth", "frequency": { "value": 880, "inputs": [] }, "detune": { "value": 0, "inputs": [] }, "inputs": [] } ] } ] } */
Debug
Known issues
breakingThis package globally replaces the native Web Audio API interfaces (e.g., AudioContext, OscillatorNode) upon import. This can cause conflicts or unexpected behavior if other libraries expect the native API or if you try to use both the mock and real API simultaneously. Ensure it's only imported in test environments where this behavior is desired.
fix
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.
affects: >=0.1.0
gotchaweb-audio-test-api enforces stricter type checking and validation rules than most browser implementations of the Web Audio API. While this is a feature designed to catch common errors, it means code that might run without error in a browser (due to type coercion or lenient checks) could throw TypeErrors when tested with this library.
fix
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.
affects: >=0.1.0
deprecatedThe `web-audio-test-api` package appears to be unmaintained. The last publish to npm and code commit activity occurred over eight years ago (as of 2024). This means it may not be compatible with newer Node.js versions, updated Web Audio API specifications, or modern JavaScript features. Security vulnerabilities are also unlikely to be patched.
fix
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.
affects: >=0.5.0
Errors
Common errors & fixes
ReferenceError: AudioContext is not defined
The side-effect import `import 'web-audio-test-api';` was not executed or not executed early enough to expose `AudioContext` globally.
fix
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`.
TypeError: OscillatorNode#frequency is readonly
Attempting to assign a value directly to a `AudioParam` property (like `frequency` or `detune`) instead of its `value` property.
fix
Always assign values to the `.value` property of `AudioParam` interfaces. Correct: `osc.frequency.value = 880;` Incorrect: `osc.frequency = 880;`
TypeError: OscillatorNode#type should be an enum { sine, square, sawtooth, triangle }, but got: [some_value]
Attempting to assign a numeric value or an invalid string to the `type` property of an `OscillatorNode` or similar enum-restricted property.
fix
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;`
Upgrade
Version history
0.5.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Resources
web-audio-test-api — npm install web-audio-test-api · libregistry