The `mockserver-client` is a Node.js and browser client library designed to facilitate interaction with a running MockServer instance. It allows developers to programmatically define, update, and verify HTTP/HTTPS expectations against a MockServer. Key functionalities include setting simple or complex request/response pairs, forwarding requests, and verifying received requests. The current stable version is 5.15.0, which was last published over three years ago. While the core MockServer project remains actively developed, this specific client library exhibits a slower release cadence, suggesting it is in maintenance mode rather than active development for new features or compatibility updates. A key characteristic is that MockServer itself is a Java-based application, which needs to be running separately, often managed by `mockserver-node` or other methods. This client is a declarative mocking tool, meaning expectations are hand-written, which can lead to 'mock drift' if the real APIs evolve significantly without corresponding updates to the mock definitions.
npm install mockserver-clientVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to initialize the MockServer client, set up both simple and complex HTTP expectations, and verify that requests were received, including error handling for connection issues.
Review the MockServer documentation for alternatives or newer client implementations if compatibility issues arise. Consider direct interaction with MockServer's REST API if the client library becomes a blocker for newer Node.js features.
Ensure MockServer is started before running code that uses `mockserver-client`. This can be done via Docker, a standalone JAR, or using the `mockserver-node` npm package (a separate project) to manage the server lifecycle from Node.js.
Regularly review and update mock definitions to reflect current API specifications. Consider integrating contract testing or using traffic-recording/replay tools in conjunction with (or as an alternative to) declarative mocks to minimize drift.
Exercise caution when using with very recent Node.js versions. Test thoroughly in your target environment. Be prepared for potential runtime issues due to breaking changes or deprecated APIs in Node.js itself.
Start the MockServer application on the correct host and port before executing client code. For example, using `mockserver-node -p 1080` if `mockserver-node` is installed globally. Verify network connectivity if running in a container or remote environment.
Ensure `mockServerClient('localhost', 1080)` is called and its return value is assigned to `client`. Also, ensure `mockServerClient` itself is imported correctly (e.g., `import { mockServerClient } from 'mockserver-client';` or `const { mockServerClient } = require('mockserver-client');`).Always include `.catch(error => console.error(error))` in your promise chains when interacting with `mockserver-client` methods. Inspect the `error` object for more details, which often contains an `httpResponse` or a `message` property from the MockServer. Check MockServer logs for more specific server-side errors.
No dependency data recorded yet.