
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
@osskit/wiremock-client
Advanced tools
yarn add --dev @osskit/wiremock-client
import { setGlobalConfiguration, reset, createMapping, hasMadeCalls, waitForCalls } from '@osskit/wiremock-client';
setGlobalConfiguration({ baseUrl: 'http://localhost:9090' });
describe('tests', () => {
beforeEach(async () => {
await reset();
});
// check if a call has been made
it('hasMadeCalls', async () => {
const request = await createMapping({ request: { urlPathPattern: '/someUrl', method: HttpMethod.Post } });
await fetch('http://localhost:9090/someUrl', { method: HttpMethod.Post, body: '{}' });
await expect(hasMadeCalls(request)).resolves.toBeTruthy();
});
// Simulate error
it('Simulating errors', async () => {
await createMapping({
request: { urlPathPattern: '/someUrl', method: HttpMethod.Post },
response: { fault: 'CONNECTION_RESET_BY_PEER' },
});
await fetch('http://localhost:9090/someUrl', { method: HttpMethod.Post, body: '{}' });
});
// validate the calls that has been made
it('waitForCalls', async () => {
const request = await createMapping({ request: { urlPathPattern: '/someUrl', method: HttpMethod.Post } });
await fetch('http://localhost:9090/someUrl', { method: HttpMethod.Post, body: '{}' });
const calls = await waitForCalls(request);
expect(calls).toHaveLength(1);
expect(calls[0]).toHaveProperty('body', {});
});
});
useful for parallel tests
import { WireMockClient } from '@osskit/wiremock-client';
const client = new WireMockClient('http://localhost:9090');
const client2 = new WireMockClient('http://localhost:8080');
describe('tests', () => {
beforeEach(async () => {
await client.reset();
await client2.reset();
});
// check if a call has been made
it('hasMadeCalls', async () => {
const request = await client.createMapping({ request: { urlPathPattern: '/someUrl', method: HttpMethod.Post } });
await fetch('http://localhost:9090/someUrl', { method: HttpMethod.Post, body: '{}' });
await expect(client.hasMadeCalls(request)).resolves.toBeTruthy();
});
// validate the calls that has been made
it('waitForCalls', async () => {
const request = await client2.createMapping({ request: { urlPathPattern: '/someUrl', method: HttpMethod.Post } });
await fetch('http://localhost:8080/someUrl', { method: HttpMethod.Post, body: '{}' });
const calls = await client2.waitForCalls(request);
expect(calls).toHaveLength(1);
expect(calls[0]).toHaveProperty('body', {});
});
});
Overrides the global configuration for the wiremock client. Usually called once at the start of the tests.
Type: Configuration
Type: string
Default: http://localhost:8080
The url to the wiremock
server.
Resets the requests' mapping.
Returns a Promise<void>
.
Creates mapping between request and response for the mocks to return.
Returns a Promise
to the request, so it can later be used to get the calls or check if the request was made.
Type: Mapping
Type: RequestPattern
The pattern to match requests
Type: string
Type: string
Type: HttpMethod
Type: Record<string, any>
Type: Record<string, any>[]
Type: Response
Default: { status: 200 }
Type: number
Type: Record<string, any>
Type: Record<string, any>
Type: string
Body can be a template used to generate random responses, for example:
await createMapping({
request: { urlPathPattern: '/someUrl', method: HttpMethod.Post },
response: { status: 200, body: "{{randomValue length=33 type='ALPHANUMERIC'}}", transformers: ['response-template'] },
});
To use this feature, make sure to start the wiremock docker with the --local-response-templating
option.
For more on templates see wiremock docs
Type: string
Type: number
Return a Promise
to the calls that was made with the given request pattern.
Can be optionally ordered by a given orderBy
method.
It waits to get the
requests from
wiremock with the given timeout and interval.
Defaults:
Type: RequestPattern
Type: Options
Type: TimeoutOptions
Default: { timeoutInMs: 3000, intervalInMs: 500 }
The options for waiting until calls has been made.
Type: Function
An optional function to sort the returning calls, returns a number
.
Type: boolean
Wheter to treat the body
of the requests as string
.
Returns a Promise
to a boolean
representing if any calls with the given request pattern were made.
Type: RequestPattern
Type: TimeoutOptions
Default: { timeoutInMs: 3000, intervalInMs: 500 }
The options for waiting until calls has been made.
FAQs
Unknown package
The npm package @osskit/wiremock-client receives a total of 10,177 weekly downloads. As such, @osskit/wiremock-client popularity was classified as popular.
We found that @osskit/wiremock-client demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.