@hellaweb3/wiremock-testcontainers-nodejs 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +120 -0
- package/dist/index.cjs +76 -0
- package/dist/index.d.cts +56 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +56 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +73 -0
- package/package.json +92 -0
- package/src/index.ts +89 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Chris Anatalio
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
<!--suppress HtmlDeprecatedAttribute -->
|
|
2
|
+
<div align="center">
|
|
3
|
+
|
|
4
|
+
<h1>WireMock Testcontainers Node.js</h1>
|
|
5
|
+
|
|
6
|
+
<p>A library for easily using WireMock with Testcontainers in Node.js applications.</p>
|
|
7
|
+
|
|
8
|
+
<a href="https://github.com/hella-web3/wiremock-testcontainers-nodejs/actions/workflows/main.yml">
|
|
9
|
+
<img alt="Build Status" src="https://github.com/hella-web3/wiremock-testcontainers-nodejs/actions/workflows/main.yml/badge.svg" />
|
|
10
|
+
</a>
|
|
11
|
+
|
|
12
|
+
<a href="https://www.npmjs.com/package/@hellaweb3/wiremock-testcontainers-nodejs">
|
|
13
|
+
<img alt="npm version" src="https://img.shields.io/npm/v/%40hellaweb3%2Fwiremock-testcontainers-nodejs" />
|
|
14
|
+
</a>
|
|
15
|
+
|
|
16
|
+
<a href="https://www.npmjs.com/package/@hellaweb3/wiremock-testcontainers-nodejs">
|
|
17
|
+
<img alt="npm downloads" src="https://img.shields.io/npm/dm/%40hellaweb3%2Fwiremock-testcontainers-nodejs" />
|
|
18
|
+
</a>
|
|
19
|
+
|
|
20
|
+
</div>
|
|
21
|
+
|
|
22
|
+
## Description
|
|
23
|
+
|
|
24
|
+
`wiremock-testcontainers-nodejs` spins up a [WireMock](https://wiremock.org/)
|
|
25
|
+
instance with [Testcontainers](https://node.testcontainers.org/). It provides a
|
|
26
|
+
fluent API to configure and start WireMock
|
|
27
|
+
containers, including support for loading mappings and files from recorded
|
|
28
|
+
Wiremock sessions.
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pnpm add -D @hellaweb3/wiremock-testcontainers-nodejs testcontainers
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
### Basic Example
|
|
39
|
+
|
|
40
|
+
Assuming you placed your mappings in `test/__mocks__/wiremock`,
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
import { WiremockContainer } from "@hellaweb3/wiremock-testcontainers-nodejs";
|
|
44
|
+
|
|
45
|
+
describe("E2E Test", () => {
|
|
46
|
+
let container;
|
|
47
|
+
|
|
48
|
+
beforeAll(async () => {
|
|
49
|
+
container = await new WiremockContainer()
|
|
50
|
+
.withMappings("./test/__mocks__/wiremock")
|
|
51
|
+
.start();
|
|
52
|
+
}, 60000);
|
|
53
|
+
|
|
54
|
+
afterAll(async () => {
|
|
55
|
+
await container.stop();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("should interact with WireMock", async () => {
|
|
59
|
+
const url = container.rpcUrl;
|
|
60
|
+
// Your test logic here
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### With Mappings and Files
|
|
66
|
+
|
|
67
|
+
WireMock uses a specific directory structure for mappings and static files. This
|
|
68
|
+
library makes it easy to mount these into the container.
|
|
69
|
+
|
|
70
|
+
**Project structure:**
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
test/
|
|
74
|
+
└── __mocks__/
|
|
75
|
+
└── wiremock/
|
|
76
|
+
├── mappings/
|
|
77
|
+
│ └── my-mapping.json
|
|
78
|
+
└── __files/
|
|
79
|
+
└── some-data.json
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
import { WiremockContainer } from "@hellaweb3/wiremock-testcontainers-nodejs";
|
|
84
|
+
|
|
85
|
+
const container = await new WiremockContainer()
|
|
86
|
+
.withMappings("./test/__mocks__/wiremock")
|
|
87
|
+
.start();
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## API
|
|
91
|
+
|
|
92
|
+
### `WiremockContainer`
|
|
93
|
+
|
|
94
|
+
- `constructor(image?: string)`: Create a new container. Defaults to
|
|
95
|
+
`wiremock/wiremock`.
|
|
96
|
+
- `withMappings(directory: string)`: Mounts `mappings` and `__files` from the
|
|
97
|
+
specified local directory to the container.
|
|
98
|
+
- `start()`: Starts the container and returns a `StartedWiremockContainer`.
|
|
99
|
+
|
|
100
|
+
### `StartedWiremockContainer`
|
|
101
|
+
|
|
102
|
+
- `rpcUrl`: Returns the base URL of the running WireMock instance (e.g.,
|
|
103
|
+
`http://localhost:32768`).
|
|
104
|
+
- `stop()`: Stops the container (inherited from Testcontainers).
|
|
105
|
+
|
|
106
|
+
## Best Practices
|
|
107
|
+
|
|
108
|
+
1. **Test Isolation**: Start a new container for each test suite (or even each
|
|
109
|
+
test if performance allows) to ensure a clean state.
|
|
110
|
+
2. **Mapping Organization**: Keep your mappings organized in a dedicated
|
|
111
|
+
directory structure that mirrors your API endpoints.
|
|
112
|
+
3. **Timeouts**: Docker container startup can sometimes exceed the default test
|
|
113
|
+
runner timeout (e.g., 5s in Jest). Always set a higher timeout for
|
|
114
|
+
`beforeAll` hooks that start containers.
|
|
115
|
+
4. **Resource Management**: Always ensure `container.stop()` is called in an
|
|
116
|
+
`afterAll` or `afterEach` block to prevent orphaned containers.
|
|
117
|
+
|
|
118
|
+
## License
|
|
119
|
+
|
|
120
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
|
|
3
|
+
var testcontainers = require('testcontainers');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A Testcontainer for Wiremock.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const container = await new WiremockContainer().start();
|
|
11
|
+
* ```
|
|
12
|
+
*/ class WiremockContainer extends testcontainers.GenericContainer {
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new WiremockContainer.
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const container = await new WiremockContainer().start();
|
|
18
|
+
* ```
|
|
19
|
+
* @param image The docker image to use. Defaults to "wiremock/wiremock".
|
|
20
|
+
*/ constructor(image = "wiremock/wiremock"){
|
|
21
|
+
super(image);
|
|
22
|
+
this.withExposedPorts(8080);
|
|
23
|
+
this.withWaitStrategy(testcontainers.Wait.forListeningPorts());
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Adds mappings to the Wiremock container.
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const container = await new WiremockContainer()
|
|
30
|
+
* .withMappings("./test/__mocks__/wiremock")
|
|
31
|
+
* .start();
|
|
32
|
+
* ```
|
|
33
|
+
* @param directory The directory containing the mappings and __files.
|
|
34
|
+
*/ withMappings(directory) {
|
|
35
|
+
this.withCopyDirectoriesToContainer([
|
|
36
|
+
{
|
|
37
|
+
source: `${directory}/__files`,
|
|
38
|
+
target: "/home/wiremock/__files"
|
|
39
|
+
}
|
|
40
|
+
]);
|
|
41
|
+
this.withCopyDirectoriesToContainer([
|
|
42
|
+
{
|
|
43
|
+
source: `${directory}/mappings`,
|
|
44
|
+
target: "/home/wiremock/mappings"
|
|
45
|
+
}
|
|
46
|
+
]);
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Starts the container and returns a {@link StartedWiremockContainer}.
|
|
51
|
+
* @returns A promise that resolves to the started container.
|
|
52
|
+
*/ async start() {
|
|
53
|
+
const startedContainer = await super.start();
|
|
54
|
+
return new StartedWiremockContainer(startedContainer, `http://${startedContainer.getHost()}:${startedContainer.getMappedPort(8080)}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* A started Wiremock container with helper methods for interacting with the node.
|
|
59
|
+
*/ class StartedWiremockContainer extends testcontainers.AbstractStartedContainer {
|
|
60
|
+
/**
|
|
61
|
+
* Creates a new StartedWiremockContainer.
|
|
62
|
+
* @param startedTestContainer The underlying TestContainer.
|
|
63
|
+
* @param url The URL of the started container.
|
|
64
|
+
*/ constructor(startedTestContainer, url){
|
|
65
|
+
super(startedTestContainer);
|
|
66
|
+
this._rpcUrl = url;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Gets the URL of the Wiremock node.
|
|
70
|
+
*/ get rpcUrl() {
|
|
71
|
+
return this._rpcUrl;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
exports.StartedWiremockContainer = StartedWiremockContainer;
|
|
76
|
+
exports.WiremockContainer = WiremockContainer;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { AbstractStartedContainer, StartedTestContainer, GenericContainer } from 'testcontainers';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A Testcontainer for Wiremock.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* const container = await new WiremockContainer().start();
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
declare class WiremockContainer extends GenericContainer {
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new WiremockContainer.
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const container = await new WiremockContainer().start();
|
|
17
|
+
* ```
|
|
18
|
+
* @param image The docker image to use. Defaults to "wiremock/wiremock".
|
|
19
|
+
*/
|
|
20
|
+
constructor(image?: string);
|
|
21
|
+
/**
|
|
22
|
+
* Adds mappings to the Wiremock container.
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const container = await new WiremockContainer()
|
|
26
|
+
* .withMappings("./test/__mocks__/wiremock")
|
|
27
|
+
* .start();
|
|
28
|
+
* ```
|
|
29
|
+
* @param directory The directory containing the mappings and __files.
|
|
30
|
+
*/
|
|
31
|
+
withMappings(directory: string): this;
|
|
32
|
+
/**
|
|
33
|
+
* Starts the container and returns a {@link StartedWiremockContainer}.
|
|
34
|
+
* @returns A promise that resolves to the started container.
|
|
35
|
+
*/
|
|
36
|
+
start(): Promise<StartedWiremockContainer>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* A started Wiremock container with helper methods for interacting with the node.
|
|
40
|
+
*/
|
|
41
|
+
declare class StartedWiremockContainer extends AbstractStartedContainer {
|
|
42
|
+
private readonly _rpcUrl;
|
|
43
|
+
/**
|
|
44
|
+
* Creates a new StartedWiremockContainer.
|
|
45
|
+
* @param startedTestContainer The underlying TestContainer.
|
|
46
|
+
* @param url The URL of the started container.
|
|
47
|
+
*/
|
|
48
|
+
constructor(startedTestContainer: StartedTestContainer, url: string);
|
|
49
|
+
/**
|
|
50
|
+
* Gets the URL of the Wiremock node.
|
|
51
|
+
*/
|
|
52
|
+
get rpcUrl(): string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export { StartedWiremockContainer, WiremockContainer };
|
|
56
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","sources":["../src/index.ts"],"sourcesContent":["import {\n AbstractStartedContainer,\n GenericContainer,\n StartedTestContainer,\n Wait,\n} from \"testcontainers\";\n\n/**\n * A Testcontainer for Wiremock.\n *\n * @example\n * ```typescript\n * const container = await new WiremockContainer().start();\n * ```\n */\nexport class WiremockContainer extends GenericContainer {\n /**\n * Creates a new WiremockContainer.\n * @example\n * ```typescript\n * const container = await new WiremockContainer().start();\n * ```\n * @param image The docker image to use. Defaults to \"wiremock/wiremock\".\n */\n constructor(image: string = \"wiremock/wiremock\") {\n super(image);\n this.withExposedPorts(8080);\n this.withWaitStrategy(Wait.forListeningPorts());\n }\n\n /**\n * Adds mappings to the Wiremock container.\n * @example\n * ```typescript\n * const container = await new WiremockContainer()\n * .withMappings(\"./test/__mocks__/wiremock\")\n * .start();\n * ```\n * @param directory The directory containing the mappings and __files.\n */\n public withMappings(directory: string) {\n this.withCopyDirectoriesToContainer([{\n source: `${directory}/__files`,\n target: \"/home/wiremock/__files\",\n }]);\n this.withCopyDirectoriesToContainer([{\n source: `${directory}/mappings`,\n target: \"/home/wiremock/mappings\",\n }]);\n\n return this;\n }\n\n /**\n * Starts the container and returns a {@link StartedWiremockContainer}.\n * @returns A promise that resolves to the started container.\n */\n public override async start(): Promise<StartedWiremockContainer> {\n const startedContainer = await super.start();\n return new StartedWiremockContainer(\n startedContainer,\n `http://${startedContainer.getHost()}:${startedContainer.getMappedPort(8080)}`,\n );\n }\n}\n\n/**\n * A started Wiremock container with helper methods for interacting with the node.\n */\nexport class StartedWiremockContainer extends AbstractStartedContainer {\n private readonly _rpcUrl;\n\n /**\n * Creates a new StartedWiremockContainer.\n * @param startedTestContainer The underlying TestContainer.\n * @param url The URL of the started container.\n */\n constructor(startedTestContainer: StartedTestContainer, url: string) {\n super(startedTestContainer);\n this._rpcUrl = url;\n }\n\n /**\n * Gets the URL of the Wiremock node.\n */\n get rpcUrl() {\n return this._rpcUrl;\n }\n}\n"],"names":[],"mappings":";;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,cAAA,iBAAA,SAAA,gBAAA;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAA,OAAA,CAAA,wBAAA;AACA;AACA;AACA;AACA;AACO,cAAA,wBAAA,SAAA,wBAAA;AACP;AACA;AACA;AACA;AACA;AACA;AACA,sCAAA,oBAAA;AACA;AACA;AACA;AACA;AACA;;;;"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { AbstractStartedContainer, StartedTestContainer, GenericContainer } from 'testcontainers';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A Testcontainer for Wiremock.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* const container = await new WiremockContainer().start();
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
declare class WiremockContainer extends GenericContainer {
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new WiremockContainer.
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const container = await new WiremockContainer().start();
|
|
17
|
+
* ```
|
|
18
|
+
* @param image The docker image to use. Defaults to "wiremock/wiremock".
|
|
19
|
+
*/
|
|
20
|
+
constructor(image?: string);
|
|
21
|
+
/**
|
|
22
|
+
* Adds mappings to the Wiremock container.
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const container = await new WiremockContainer()
|
|
26
|
+
* .withMappings("./test/__mocks__/wiremock")
|
|
27
|
+
* .start();
|
|
28
|
+
* ```
|
|
29
|
+
* @param directory The directory containing the mappings and __files.
|
|
30
|
+
*/
|
|
31
|
+
withMappings(directory: string): this;
|
|
32
|
+
/**
|
|
33
|
+
* Starts the container and returns a {@link StartedWiremockContainer}.
|
|
34
|
+
* @returns A promise that resolves to the started container.
|
|
35
|
+
*/
|
|
36
|
+
start(): Promise<StartedWiremockContainer>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* A started Wiremock container with helper methods for interacting with the node.
|
|
40
|
+
*/
|
|
41
|
+
declare class StartedWiremockContainer extends AbstractStartedContainer {
|
|
42
|
+
private readonly _rpcUrl;
|
|
43
|
+
/**
|
|
44
|
+
* Creates a new StartedWiremockContainer.
|
|
45
|
+
* @param startedTestContainer The underlying TestContainer.
|
|
46
|
+
* @param url The URL of the started container.
|
|
47
|
+
*/
|
|
48
|
+
constructor(startedTestContainer: StartedTestContainer, url: string);
|
|
49
|
+
/**
|
|
50
|
+
* Gets the URL of the Wiremock node.
|
|
51
|
+
*/
|
|
52
|
+
get rpcUrl(): string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export { StartedWiremockContainer, WiremockContainer };
|
|
56
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sources":["../src/index.ts"],"sourcesContent":["import {\n AbstractStartedContainer,\n GenericContainer,\n StartedTestContainer,\n Wait,\n} from \"testcontainers\";\n\n/**\n * A Testcontainer for Wiremock.\n *\n * @example\n * ```typescript\n * const container = await new WiremockContainer().start();\n * ```\n */\nexport class WiremockContainer extends GenericContainer {\n /**\n * Creates a new WiremockContainer.\n * @example\n * ```typescript\n * const container = await new WiremockContainer().start();\n * ```\n * @param image The docker image to use. Defaults to \"wiremock/wiremock\".\n */\n constructor(image: string = \"wiremock/wiremock\") {\n super(image);\n this.withExposedPorts(8080);\n this.withWaitStrategy(Wait.forListeningPorts());\n }\n\n /**\n * Adds mappings to the Wiremock container.\n * @example\n * ```typescript\n * const container = await new WiremockContainer()\n * .withMappings(\"./test/__mocks__/wiremock\")\n * .start();\n * ```\n * @param directory The directory containing the mappings and __files.\n */\n public withMappings(directory: string) {\n this.withCopyDirectoriesToContainer([{\n source: `${directory}/__files`,\n target: \"/home/wiremock/__files\",\n }]);\n this.withCopyDirectoriesToContainer([{\n source: `${directory}/mappings`,\n target: \"/home/wiremock/mappings\",\n }]);\n\n return this;\n }\n\n /**\n * Starts the container and returns a {@link StartedWiremockContainer}.\n * @returns A promise that resolves to the started container.\n */\n public override async start(): Promise<StartedWiremockContainer> {\n const startedContainer = await super.start();\n return new StartedWiremockContainer(\n startedContainer,\n `http://${startedContainer.getHost()}:${startedContainer.getMappedPort(8080)}`,\n );\n }\n}\n\n/**\n * A started Wiremock container with helper methods for interacting with the node.\n */\nexport class StartedWiremockContainer extends AbstractStartedContainer {\n private readonly _rpcUrl;\n\n /**\n * Creates a new StartedWiremockContainer.\n * @param startedTestContainer The underlying TestContainer.\n * @param url The URL of the started container.\n */\n constructor(startedTestContainer: StartedTestContainer, url: string) {\n super(startedTestContainer);\n this._rpcUrl = url;\n }\n\n /**\n * Gets the URL of the Wiremock node.\n */\n get rpcUrl() {\n return this._rpcUrl;\n }\n}\n"],"names":[],"mappings":";;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,cAAA,iBAAA,SAAA,gBAAA;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAA,OAAA,CAAA,wBAAA;AACA;AACA;AACA;AACA;AACO,cAAA,wBAAA,SAAA,wBAAA;AACP;AACA;AACA;AACA;AACA;AACA;AACA,sCAAA,oBAAA;AACA;AACA;AACA;AACA;AACA;;;;"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { GenericContainer, Wait, AbstractStartedContainer } from 'testcontainers';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A Testcontainer for Wiremock.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* const container = await new WiremockContainer().start();
|
|
9
|
+
* ```
|
|
10
|
+
*/ class WiremockContainer extends GenericContainer {
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new WiremockContainer.
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const container = await new WiremockContainer().start();
|
|
16
|
+
* ```
|
|
17
|
+
* @param image The docker image to use. Defaults to "wiremock/wiremock".
|
|
18
|
+
*/ constructor(image = "wiremock/wiremock"){
|
|
19
|
+
super(image);
|
|
20
|
+
this.withExposedPorts(8080);
|
|
21
|
+
this.withWaitStrategy(Wait.forListeningPorts());
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Adds mappings to the Wiremock container.
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const container = await new WiremockContainer()
|
|
28
|
+
* .withMappings("./test/__mocks__/wiremock")
|
|
29
|
+
* .start();
|
|
30
|
+
* ```
|
|
31
|
+
* @param directory The directory containing the mappings and __files.
|
|
32
|
+
*/ withMappings(directory) {
|
|
33
|
+
this.withCopyDirectoriesToContainer([
|
|
34
|
+
{
|
|
35
|
+
source: `${directory}/__files`,
|
|
36
|
+
target: "/home/wiremock/__files"
|
|
37
|
+
}
|
|
38
|
+
]);
|
|
39
|
+
this.withCopyDirectoriesToContainer([
|
|
40
|
+
{
|
|
41
|
+
source: `${directory}/mappings`,
|
|
42
|
+
target: "/home/wiremock/mappings"
|
|
43
|
+
}
|
|
44
|
+
]);
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Starts the container and returns a {@link StartedWiremockContainer}.
|
|
49
|
+
* @returns A promise that resolves to the started container.
|
|
50
|
+
*/ async start() {
|
|
51
|
+
const startedContainer = await super.start();
|
|
52
|
+
return new StartedWiremockContainer(startedContainer, `http://${startedContainer.getHost()}:${startedContainer.getMappedPort(8080)}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* A started Wiremock container with helper methods for interacting with the node.
|
|
57
|
+
*/ class StartedWiremockContainer extends AbstractStartedContainer {
|
|
58
|
+
/**
|
|
59
|
+
* Creates a new StartedWiremockContainer.
|
|
60
|
+
* @param startedTestContainer The underlying TestContainer.
|
|
61
|
+
* @param url The URL of the started container.
|
|
62
|
+
*/ constructor(startedTestContainer, url){
|
|
63
|
+
super(startedTestContainer);
|
|
64
|
+
this._rpcUrl = url;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Gets the URL of the Wiremock node.
|
|
68
|
+
*/ get rpcUrl() {
|
|
69
|
+
return this._rpcUrl;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export { StartedWiremockContainer, WiremockContainer };
|
package/package.json
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hellaweb3/wiremock-testcontainers-nodejs",
|
|
3
|
+
"description": "A Node.js library for using WireMock with Testcontainers, providing a fluent API for easy setup and integration testing.",
|
|
4
|
+
"homepage": "https://github.com/hella-web3/wiremock-testcontainers-nodejs#readme",
|
|
5
|
+
"repository": "https://github.com/hella-web3/wiremock-testcontainers-nodejs",
|
|
6
|
+
"bugs": "https://github.com/hella-web3/wiremock-testcontainers-nodejs/issues",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"testcontainers",
|
|
9
|
+
"wiremock",
|
|
10
|
+
"testing",
|
|
11
|
+
"mock",
|
|
12
|
+
"api"
|
|
13
|
+
],
|
|
14
|
+
"version": "0.1.1",
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"author": "Chris Anatalio",
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"src",
|
|
23
|
+
"README.md",
|
|
24
|
+
"LICENSE"
|
|
25
|
+
],
|
|
26
|
+
"type": "module",
|
|
27
|
+
"main": "./dist/index.cjs",
|
|
28
|
+
"module": "./dist/index.js",
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"import": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"default": "./dist/index.js"
|
|
35
|
+
},
|
|
36
|
+
"require": {
|
|
37
|
+
"types": "./dist/index.d.cts",
|
|
38
|
+
"default": "./dist/index.cjs"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"./package.json": "./package.json"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"dev": "tsdx dev",
|
|
45
|
+
"build": "tsdx build",
|
|
46
|
+
"test": "jest --colors --injectGlobals",
|
|
47
|
+
"lint": "tsdx lint",
|
|
48
|
+
"typecheck": "tsc --noEmit",
|
|
49
|
+
"prepack": "pnpm build",
|
|
50
|
+
"prepublishOnly": "pnpm run build",
|
|
51
|
+
"check": "pnpm build && pnpm typecheck && pnpm lint && pnpm test"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"testcontainers": "^11.11.0"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@types/jest": "^30.0.0",
|
|
58
|
+
"@types/node": "^25.0.10",
|
|
59
|
+
"bunchee": "^6.9.4",
|
|
60
|
+
"jest": "^30.2.0",
|
|
61
|
+
"ts-jest": "^29.4.6",
|
|
62
|
+
"tsdx": "^2.0.0",
|
|
63
|
+
"typescript": "^5.9.3",
|
|
64
|
+
"vitest": "^4.0.18"
|
|
65
|
+
},
|
|
66
|
+
"jest": {
|
|
67
|
+
"collectCoverageFrom": [
|
|
68
|
+
"**/*.(t|j)s"
|
|
69
|
+
],
|
|
70
|
+
"coverageDirectory": "../coverage",
|
|
71
|
+
"coveragePathIgnorePatterns": [
|
|
72
|
+
"app.module.ts",
|
|
73
|
+
"main.ts",
|
|
74
|
+
".*\\.module\\.ts",
|
|
75
|
+
".*\\.dto\\.ts"
|
|
76
|
+
],
|
|
77
|
+
"moduleFileExtensions": [
|
|
78
|
+
"js",
|
|
79
|
+
"json",
|
|
80
|
+
"ts"
|
|
81
|
+
],
|
|
82
|
+
"rootDir": ".",
|
|
83
|
+
"testEnvironment": "node",
|
|
84
|
+
"testRegex": "test/.*\\.test\\.ts$",
|
|
85
|
+
"transform": {
|
|
86
|
+
"^.+\\.(t|j)s$": "ts-jest"
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
"engines": {
|
|
90
|
+
"node": ">=22"
|
|
91
|
+
}
|
|
92
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AbstractStartedContainer,
|
|
3
|
+
GenericContainer,
|
|
4
|
+
StartedTestContainer,
|
|
5
|
+
Wait,
|
|
6
|
+
} from "testcontainers";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A Testcontainer for Wiremock.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const container = await new WiremockContainer().start();
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export class WiremockContainer extends GenericContainer {
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new WiremockContainer.
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const container = await new WiremockContainer().start();
|
|
22
|
+
* ```
|
|
23
|
+
* @param image The docker image to use. Defaults to "wiremock/wiremock".
|
|
24
|
+
*/
|
|
25
|
+
constructor(image: string = "wiremock/wiremock") {
|
|
26
|
+
super(image);
|
|
27
|
+
this.withExposedPorts(8080);
|
|
28
|
+
this.withWaitStrategy(Wait.forListeningPorts());
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Adds mappings to the Wiremock container.
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const container = await new WiremockContainer()
|
|
36
|
+
* .withMappings("./test/__mocks__/wiremock")
|
|
37
|
+
* .start();
|
|
38
|
+
* ```
|
|
39
|
+
* @param directory The directory containing the mappings and __files.
|
|
40
|
+
*/
|
|
41
|
+
public withMappings(directory: string) {
|
|
42
|
+
this.withCopyDirectoriesToContainer([{
|
|
43
|
+
source: `${directory}/__files`,
|
|
44
|
+
target: "/home/wiremock/__files",
|
|
45
|
+
}]);
|
|
46
|
+
this.withCopyDirectoriesToContainer([{
|
|
47
|
+
source: `${directory}/mappings`,
|
|
48
|
+
target: "/home/wiremock/mappings",
|
|
49
|
+
}]);
|
|
50
|
+
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Starts the container and returns a {@link StartedWiremockContainer}.
|
|
56
|
+
* @returns A promise that resolves to the started container.
|
|
57
|
+
*/
|
|
58
|
+
public override async start(): Promise<StartedWiremockContainer> {
|
|
59
|
+
const startedContainer = await super.start();
|
|
60
|
+
return new StartedWiremockContainer(
|
|
61
|
+
startedContainer,
|
|
62
|
+
`http://${startedContainer.getHost()}:${startedContainer.getMappedPort(8080)}`,
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* A started Wiremock container with helper methods for interacting with the node.
|
|
69
|
+
*/
|
|
70
|
+
export class StartedWiremockContainer extends AbstractStartedContainer {
|
|
71
|
+
private readonly _rpcUrl;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Creates a new StartedWiremockContainer.
|
|
75
|
+
* @param startedTestContainer The underlying TestContainer.
|
|
76
|
+
* @param url The URL of the started container.
|
|
77
|
+
*/
|
|
78
|
+
constructor(startedTestContainer: StartedTestContainer, url: string) {
|
|
79
|
+
super(startedTestContainer);
|
|
80
|
+
this._rpcUrl = url;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Gets the URL of the Wiremock node.
|
|
85
|
+
*/
|
|
86
|
+
get rpcUrl() {
|
|
87
|
+
return this._rpcUrl;
|
|
88
|
+
}
|
|
89
|
+
}
|