Skip to main content

Class: WiremockContainer

Defined in: src/index.ts:77

A WireMock Testcontainer: register stubs, response bodies and extensions, then start it. Registrations are validated at once and may not overwrite one another. Every Testcontainers GenericContainer builder method is available, too.

See​

Quick start

Extends​

Constructors​

Constructor​

new WiremockContainer(image?): WiremockContainer;

Defined in: src/index.ts:98

Parameters​

ParameterTypeDefault valueDescription
image?string"wiremock/wiremock"Docker image, default wiremock/wiremock – pin a tag for reproducible tests.

Returns​

WiremockContainer

See​

Configuring the container

Overrides​

GenericContainer.constructor

Methods​

start()​

start(): Promise<StartedWiremockContainer>;

Defined in: src/index.ts:250

Starts WireMock – in Docker, or locally once ./no-docker is installed. Resolves once the port listens; StartedWiremockContainer.waitUntilReady waits until WireMock is healthy.

Returns​

Promise<StartedWiremockContainer>

Throws​

Before starting, for a class with no registered JAR or options conflicting with withCommand(); if WireMock fails, naming the extensions in use.

See​

Container lifecycle

Overrides​

GenericContainer.start


withCommand()​

withCommand(command): this;

Defined in: src/index.ts:108

WireMock CLI arguments, e.g. ["--verbose"]; extensions add theirs on start().

Parameters​

ParameterType
commandstring[]

Returns​

this

See​

WireMock options

Overrides​

GenericContainer.withCommand


withExtension()​

withExtension(extension): this;

Defined in: src/index.ts:195

Registers an extension: a fully qualified Java class name, or a WireMockExtension or its class. Class names share one --extensions, in registration order, without repeats.

Parameters​

ParameterType
extensionExtensionInput

Returns​

this

Example​

.withExtensionJar("./__mocks__/extensions/example-extensions.jar") // onto WireMock's class path
.withExtension("com.hellaweb3.wiremock.extensions.UppercaseTransformer") // --extensions <class>
.withExtension(shortJournal)

Throws​

If a class name, an extension or its JARs are invalid, or an option conflicts.

See​

Registering extensions


withExtensionJar()​

withExtensionJar(jar): this;

Defined in: src/index.ts:213

Puts a JAR – or every *.jar of a directory – on WireMock's class path. Extensions listed in its META-INF/services load by themselves; others need withExtension.

Parameters​

ParameterTypeDescription
jarWiremockStaticFileAny file source; { file, name } renames the JAR.

Returns​

this

Throws​

If the source is missing, unreadable or not a JAR, or another JAR has the same name.

See​

Java extensions


withExtensionJars()​

withExtensionJars(jars): this;

Defined in: src/index.ts:222

withExtensionJar for several JARs or directories – all or nothing.

Parameters​

ParameterType
jarsreadonly WiremockStaticFile[]

Returns​

this

Example​

.withExtensionJars(["./__mocks__/extensions"]) // example-extensions.jar and powered-by-extension.jar

withExtensionOptions()​

withExtensionOptions(options): this;

Defined in: src/index.ts:231

Configures how extensions load; options not given keep their value.

Parameters​

ParameterType
optionsWiremockExtensionOptions

Returns​

this

Throws​

For an unknown option or a non-boolean value.

See​

Extension options


withExtensions()​

withExtensions(extensions): this;

Defined in: src/index.ts:202

withExtension for several extensions – all or nothing.

Parameters​

ParameterType
extensionsreadonly ExtensionInput[]

Returns​

this


withFiles()​

withFiles(...files): this;

Defined in: src/index.ts:173

Registers response bodies at __files/<name> (default: base name). All or nothing.

Parameters​

ParameterType
...filesWiremockStaticFile[]

Returns​

this

Example​

.withFiles(STATEMENT_BODY, INVOICE_BODY, EXCHANGE_RATES_BODY); // bodies → __files/

Throws​

If a source or name is invalid, or a file would overwrite an earlier registration.

See​

Registering stubs


withMapping()​

withMapping(name, source): this;

Defined in: src/index.ts:153

Registers one mapping file at mappings/<name>.json (name may contain /); it may hold one stub or { "mappings": [...] }.

Parameters​

ParameterTypeDescription
namestringThe file name below mappings/, without .json.
sourceWiremockMappingSourceA file source, or inline JSON: { json }.

Returns​

this

Example​

.withMapping("ping", { json: PING_STUB }) // inline: an object…
.withMapping("maintenance", { json: MAINTENANCE_STUB }) // …or a JSON string
.withMapping("payments/refunds", REFUND_STUBS) // "/" nests: mappings/payments/refunds.json

Throws​

If the source is invalid, not a WireMock stub, or would overwrite an earlier registration.

See​

Registering stubs


withMappings()​

withMappings(directory): this;

Defined in: src/index.ts:119

Copies directory/mappings/ (required) and directory/__files/ (optional) into the container.

Parameters​

ParameterTypeDescription
directorystringA path, relative to the working directory.

Returns​

this

Throws​

If mappings/ is missing or a file would overwrite an earlier registration.

See​

Registering stubs