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
Extends
Constructors
Constructor
new WiremockContainer(image?): WiremockContainer;
Defined in: src/index.ts:98
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
image? | string | "wiremock/wiremock" | Docker image, default wiremock/wiremock – pin a tag for reproducible tests. |
Returns
WiremockContainer
See
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
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
| Parameter | Type |
|---|---|
command | string[] |
Returns
this
See
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
| Parameter | Type |
|---|---|
extension | ExtensionInput |
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
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
| Parameter | Type | Description |
|---|---|---|
jar | WiremockStaticFile | Any 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
withExtensionJars()
withExtensionJars(jars): this;
Defined in: src/index.ts:222
withExtensionJar for several JARs or directories – all or nothing.
Parameters
| Parameter | Type |
|---|---|
jars | readonly 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
| Parameter | Type |
|---|---|
options | WiremockExtensionOptions |
Returns
this
Throws
For an unknown option or a non-boolean value.
See
withExtensions()
withExtensions(extensions): this;
Defined in: src/index.ts:202
withExtension for several extensions – all or nothing.
Parameters
| Parameter | Type |
|---|---|
extensions | readonly 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
| Parameter | Type |
|---|---|
...files | WiremockStaticFile[] |
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
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
| Parameter | Type | Description |
|---|---|---|
name | string | The file name below mappings/, without .json. |
source | WiremockMappingSource | A 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
withMappings()
withMappings(directory): this;
Defined in: src/index.ts:119
Copies directory/mappings/ (required) and directory/__files/ (optional) into the container.
Parameters
| Parameter | Type | Description |
|---|---|---|
directory | string | A path, relative to the working directory. |
Returns
this
Throws
If mappings/ is missing or a file would overwrite an earlier registration.