{"id":15054,"library":"web-audio-test-api","title":"Web Audio API Test Utilities","description":"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.","status":"abandoned","version":"0.5.2","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/mohayonao/web-audio-test-api","tags":["javascript","test","web audio api"],"install":[{"cmd":"npm install web-audio-test-api","lang":"bash","label":"npm"},{"cmd":"yarn add web-audio-test-api","lang":"bash","label":"yarn"},{"cmd":"pnpm add web-audio-test-api","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This import statement installs the Web Audio API interfaces (like AudioContext, OscillatorNode) onto the global scope. It does not export any specific symbols directly.","wrong":"const WebAudioTestAPI = require('web-audio-test-api');","symbol":"Side Effect Global Install","correct":"import 'web-audio-test-api';"},{"note":"After the global import, the `WebAudioTestAPI` object becomes globally available, primarily used for methods like `unuse()` to revert the global replacement.","symbol":"WebAudioTestAPI","correct":"import 'web-audio-test-api';\n// Then, WebAudioTestAPI is available globally\nWebAudioTestAPI.unuse();"},{"note":"AudioContext and other Web Audio API interfaces are made globally available after the side-effect import; they are not named exports from the package.","wrong":"import { AudioContext } from 'web-audio-test-api';","symbol":"AudioContext","correct":"import 'web-audio-test-api';\nconst audioContext = new AudioContext();"}],"quickstart":{"code":"import 'web-audio-test-api';\n\n// Create a test AudioContext instance\nconst audioContext = new AudioContext();\n\n// Create some nodes and connect them\nconst osc = audioContext.createOscillator();\nconst lfo = audioContext.createOscillator();\nconst amp = audioContext.createGain();\n\n// Assign an ID for easier debugging in the JSON output\nlfo.$id = 'LFO';\n\n// Configure node properties\nosc.type = 'sawtooth';\nosc.frequency.value = 880;\nlfo.frequency.value = 2;\n\n// Connect the audio graph\nlfo.connect(amp.gain);\nosc.connect(amp);\namp.connect(audioContext.destination);\n\n// Output the audio graph as a JSON object for inspection\nconst graphJson = audioContext.toJSON();\n\n// In a test environment, you would assert on this JSON structure\n// For demonstration, we'll log it.\nconsole.log(JSON.stringify(graphJson, null, 2));\n\n/* Expected output (truncated):\n{\n  \"name\": \"AudioDestinationNode\",\n  \"inputs\": [\n    {\n      \"name\": \"GainNode\",\n      \"gain\": {\n        \"value\": 1,\n        \"inputs\": [\n          {\n            \"name\": \"OscillatorNode#LFO\",\n            \"type\": \"sine\",\n            \"frequency\": {\n              \"value\": 2,\n              \"inputs\": []\n            },\n            \"detune\": {\n              \"value\": 0,\n              \"inputs\": []\n            },\n            \"inputs\": []\n          }\n        ]\n      },\n      \"inputs\": [\n        {\n          \"name\": \"OscillatorNode\",\n          \"type\": \"sawtooth\",\n          \"frequency\": {\n            \"value\": 880,\n            \"inputs\": []\n          },\n          \"detune\": {\n            \"value\": 0,\n            \"inputs\": []\n          },\n          \"inputs\": []\n        }\n      ]\n    }\n  ]\n}\n*/","lang":"javascript","description":"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."},"warnings":[{"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.","message":"This 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.","severity":"breaking","affected_versions":">=0.1.0"},{"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.","message":"web-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.","severity":"gotcha","affected_versions":">=0.1.0"},{"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.","message":"The `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.","severity":"deprecated","affected_versions":">=0.5.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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`.","cause":"The side-effect import `import 'web-audio-test-api';` was not executed or not executed early enough to expose `AudioContext` globally.","error":"ReferenceError: AudioContext is not defined"},{"fix":"Always assign values to the `.value` property of `AudioParam` interfaces. Correct: `osc.frequency.value = 880;` Incorrect: `osc.frequency = 880;`","cause":"Attempting to assign a value directly to a `AudioParam` property (like `frequency` or `detune`) instead of its `value` property.","error":"TypeError: OscillatorNode#frequency is readonly"},{"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;`","cause":"Attempting to assign a numeric value or an invalid string to the `type` property of an `OscillatorNode` or similar enum-restricted property.","error":"TypeError: OscillatorNode#type should be an enum { sine, square, sawtooth, triangle }, but got: [some_value]"}],"ecosystem":"npm"}