
Security News
Static vs. Runtime Reachability: Insights from Latioβs On the Record Podcast
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.
beatbox-recorder
Advanced tools
Beatbox is a lightweight TypeScript library that records and replays function calls, making it perfect for testing, mocking, and debugging. It can capture the results of expensive operations, API calls, or complex computations and play them back instantly, significantly speeding up tests and development cycles.
npm install beatbox-recorder
import { Beatbox, Mode } from 'beatbox-recorder';
// Create a new instance
const beatbox = new Beatbox('my-storage.json');
// Example function to wrap
const fetchUserData = async (userId: string) => {
// Expensive API call
const response = await fetch(`/api/users/${userId}`);
return response.json();
};
// Wrap the function
const wrappedFetchUserData = beatbox.wrap(fetchUserData);
// Record mode: Actually makes API calls and saves results
beatbox.setMode(Mode.RECORD);
const userData = await wrappedFetchUserData('user123');
// Playback mode: Returns saved results instantly
beatbox.setMode(Mode.PLAYBACK);
const cachedData = await wrappedFetchUserData('user123');
// Bypass mode: Makes actual API calls again
beatbox.setMode(Mode.BYPASS);
const freshData = await wrappedFetchUserData('user123');
new Beatbox(storageFile?: string)
storageFile
: Optional path to storage JSON file (default: 'beatbox-storage.json')Sets the operating mode of the wrapper:
Mode.BYPASS
: Direct function executionMode.RECORD
: Record function resultsMode.PLAYBACK
: Return recorded resultsWraps a function for recording/playback:
Results are stored in a JSON file with MD5 hashes of function arguments as keys. Special types are preserved with type information:
{
"d41d8cd98f00b204e9800998ecf8427e": {
"result": "cached value"
},
"a7b5f3e21d9c4f8g": {
"value": [1, 2, 3],
"__type": "Set"
},
"h8j2k4l6m8n0p2q4": {
"value": "2024-01-01T00:00:00.000Z",
"__type": "Date"
}
Version Control
Storage Management
Error Handling
Security
Type Handling
if (process.env.NODE_ENV === 'test') {
beatbox.setMode(Mode.PLAYBACK);
} else {
beatbox.setMode(Mode.BYPASS);
}
// Record a set of related calls
beatbox.setMode(Mode.RECORD);
await Promise.all([
wrappedFn('test1'),
wrappedFn('test2'),
wrappedFn('test3')
]);
// Sets and Maps are automatically preserved
const wrappedSet = beatbox.wrap(() => new Set([1, 2, 3]));
const result = wrappedSet(); // Will be restored as Set in playback
// Dates are preserved
const wrappedDate = beatbox.wrap(() => new Date());
const date = wrappedDate(); // Will be restored as Date in playback
// Handle circular references
const wrappedCircular = beatbox.wrap(() => {
const obj: any = { a: 1 };
obj.self = obj;
return obj;
}); // Will be handled gracefully
Contributions are welcome! Please feel free to submit a Pull Request.
MIT License - see LICENSE file for details
FAQs
Record and playback function calls for testing and mocking
The npm package beatbox-recorder receives a total of 0 weekly downloads. As such, beatbox-recorder popularity was classified as not popular.
We found that beatbox-recorder demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Β It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.
Security News
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.