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
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
WireMock
✓ import { WireMock } from 'wiremock-captain';
✗ const { WireMock } = require('wiremock-captain');
The primary class for connecting to and configuring a running WireMock instance. Prefer ESM `import` syntax in modern Node.js environments.
IWireMockRequest
✓ import type { IWireMockRequest } from 'wiremock-captain';
✗ import { IWireMockRequest } from 'wiremock-captain';
TypeScript interface for defining the structure of a WireMock request stub. Use `import type` for type-only imports to avoid bundling issues.
IWireMockResponse
✓ import type { IWireMockResponse } from 'wiremock-captain';
✗ import { IWireMockResponse } from 'wiremock-captain';
TypeScript interface for defining the structure of a WireMock response stub. Use `import type` for type-only imports.
Demonstrates how to set up, register stubs for GET and POST requests, and verify interactions with a WireMock instance using WireMock Captain in a typical Jest testing environment. Requires an external WireMock Docker container.
import { WireMock } from 'wiremock-captain';
import axios from 'axios'; // Example HTTP client
describe('API Integration Test with WireMock Captain', () => {
const wiremockEndpoint = 'http://localhost:8080';
let mock: WireMock;
// Ensure WireMock Docker container is running before tests
// docker run -itd --rm -p 8080:8080 --name mocked-service wiremock/wiremock:3.9.1
beforeAll(() => {
mock = new WireMock(wiremockEndpoint);
});
beforeEach(async () => {
await mock.resetAll(); // Clear all previous stubs and scenarios
});
afterAll(async () => {
await mock.resetAll();
// Optionally, stop the WireMock container if managed by the test runner
// e.g., using 'docker stop mocked-service'
});
test('should mock a GET request and receive the predefined response', async () => {
const request = {
method: 'GET',
endpoint: '/api/resource/123',
headers: { 'Accept': 'application/json' }
};
const mockedResponse = {
status: 200,
body: { id: '123', name: 'Mocked Resource' },
headers: { 'Content-Type': 'application/json' }
};
await mock.register(request, mockedResponse);
const response = await axios.get(`${wiremockEndpoint}/api/resource/123`);
expect(response.status).toBe(200);
expect(response.data).toEqual({ id: '123', name: 'Mocked Resource' });
// Verify WireMock received the request (optional but good practice)
const receivedRequests = await mock.getAllRequests();
expect(receivedRequests.length).toBe(1);
expect(receivedRequests[0].url).toContain('/api/resource/123');
});
test('should handle a POST request with specific body matching', async () => {
const postRequest = {
method: 'POST',
endpoint: '/api/items',
body: { item: 'new item' }
};
const postResponse = {
status: 201,
body: { message: 'Item created' },
headers: { 'Content-Type': 'application/json' }
};
await mock.register(postRequest, postResponse);
const response = await axios.post(`${wiremockEndpoint}/api/items`, { item: 'new item' });
expect(response.status).toBe(201);
expect(response.data).toEqual({ message: 'Item created' });
});
});
Errors
Common errors & fixes
connect ECONNREFUSED 127.0.0.1:8080
WireMock Docker container is not running or is not accessible on the specified host and port (e.g., `http://localhost:8080`).
fixStart the WireMock Docker container: `docker run -itd --rm -p 8080:8080 --name my-mocked-service wiremock/wiremock:3.9.1`. Verify the `wiremockEndpoint` in your tests matches the running WireMock service.
TypeError: Class constructor WireMock cannot be invoked without 'new'
Attempted to call `WireMock` as a function (e.g., `WireMock(endpoint)`) instead of instantiating it with `new`.
fixInstantiate the `WireMock` class using the `new` keyword: `const mock = new WireMock(wiremockEndpoint);`.
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: ...wiremock-captain/dist/index.js
Attempting to import `wiremock-captain` using CommonJS `require()` syntax in an ESM-only context, or in a project configured for ESM.
fixUpdate your import statements to use ES module syntax: `import { WireMock } from 'wiremock-captain';`. Ensure your `package.json` has `"type": "module"` if you intend to use ESM globally, or name your files `.mjs`. Audit
Dependencies
WireMock (Docker)requiredRequired runtime dependency; WireMock Captain interfaces with an external WireMock instance, typically run as a Docker container.
JestoptionalCommonly used testing framework, although WireMock Captain is framework-agnostic.
TypeScriptoptionalUsed for development and type safety, though the library also supports plain JavaScript.