The `test-server-sdk` is a TypeScript SDK designed to provide client-side interaction with a companion `test-server` for robust HTTP and WebSocket request recording and replaying. This package facilitates deterministic and isolated testing by allowing developers to capture network traffic and simulate server responses. It's currently on version 0.2.9 and exhibits a rapid release cadence with frequent minor updates, focusing on new features and bug fixes. Key functionalities include recording and replaying HTTP and WebSocket requests, supporting dynamic subdirectory recording paths, streaming capabilities, and redacting sensitive information from response bodies. A notable differentiator is its ability to manage recording formats, which was updated to a JSON serializable format in v0.2.6, enhancing interoperability and storage. This SDK is a core component for integrating `test-server` capabilities into TypeScript-based test environments.
npm install test-server-sdkVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize, start, and interact with the `TestServer` in `Record` mode to capture HTTP requests. It sets up a local directory for recordings, sends a sample request through the proxy, and ensures the server is properly shut down.
Review existing test recordings. If they were created with versions older than 0.2.6, regenerate them using the latest SDK version. Ensure your CI/CD pipelines use a consistent SDK version for recording and replay.
Verify that the `test-server` executable is installed and running, or that the SDK is configured to launch and manage it. Consult the `test-server`'s documentation for its setup and operational requirements.
Explicitly configure the `recordingPath` and verify the expected directory structure for your recordings. Update any test setup or teardown logic that relies on specific file paths or discovery mechanisms.
Choose a different port for the `TestServer` or ensure no other application is listening on that port before running your tests. You can use a utility like `lsof -i :9000` (macOS/Linux) or `netstat -ano | findstr :9000` (Windows) to identify the conflicting process.
Ensure you are using named imports with modern TypeScript/ESM syntax: `import { TestServer } from 'test-server-sdk';`. If using CommonJS, it might require `const { TestServer } = require('test-server-sdk');` but ESM is preferred.Ensure the directory specified by `recordingPath` exists before starting the `TestServer`. You can add `fs.mkdirSync(recordingsDir, { recursive: true });` in your setup code. Also, check that your application has read/write permissions for that directory.No dependency data recorded yet.