@amqp-contract/testing 0.13.0 โ 0.15.0
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/dist/extension.d.mts +2 -3
- package/dist/extension.d.mts.map +1 -1
- package/dist/global-setup.d.mts +1 -2
- package/dist/global-setup.d.mts.map +1 -1
- package/dist/global-setup.mjs +6 -12
- package/dist/global-setup.mjs.map +1 -1
- package/docs/extension.md +30 -0
- package/docs/global-setup.md +58 -0
- package/docs/index.md +10 -0
- package/package.json +5 -4
package/dist/extension.d.mts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import amqpLib from "amqplib";
|
|
2
|
-
import * as
|
|
2
|
+
import * as vitest from "vitest";
|
|
3
3
|
|
|
4
4
|
//#region src/extension.d.ts
|
|
5
|
-
|
|
6
|
-
declare const it: vitest0.TestAPI<{
|
|
5
|
+
declare const it: vitest.TestAPI<{
|
|
7
6
|
vhost: string;
|
|
8
7
|
amqpConnectionUrl: string;
|
|
9
8
|
amqpConnection: amqpLib.ChannelModel;
|
package/dist/extension.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extension.d.mts","names":[],"sources":["../src/extension.ts"],"
|
|
1
|
+
{"version":3,"file":"extension.d.mts","names":[],"sources":["../src/extension.ts"],"mappings":";;;;cAea,EAAA,EASC,MAAA,CATC,OAAA;;;;;qCAKoB,UAAA,UAAoB,OAAA;mCAEnC,UAAA,aAEb,OAAA,EACF,OAAA;IAAY,QAAA;IAAmB,OAAA;EAAA,MAAuB,OAAA,CAAQ,OAAA,CAAQ,cAAA;AAAA"}
|
package/dist/global-setup.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { TestProject } from "vitest/node";
|
|
2
2
|
|
|
3
3
|
//#region src/global-setup.d.ts
|
|
4
|
-
|
|
5
4
|
declare module "vitest" {
|
|
6
5
|
interface ProvidedContext {
|
|
7
6
|
__TESTCONTAINERS_RABBITMQ_IP__: string;
|
|
@@ -36,7 +35,7 @@ declare module "vitest" {
|
|
|
36
35
|
*/
|
|
37
36
|
declare function setup({
|
|
38
37
|
provide
|
|
39
|
-
}: TestProject): Promise<void
|
|
38
|
+
}: TestProject): Promise<() => Promise<void>>;
|
|
40
39
|
//#endregion
|
|
41
40
|
export { setup as default };
|
|
42
41
|
//# sourceMappingURL=global-setup.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global-setup.d.mts","names":[],"sources":["../src/global-setup.ts"],"
|
|
1
|
+
{"version":3,"file":"global-setup.d.mts","names":[],"sources":["../src/global-setup.ts"],"mappings":";;;;YAyBmB,eAAA;IACf,8BAAA;IACA,qCAAA;IACA,sCAAA;IACA,oCAAA;IACA,oCAAA;EAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;iBA2B0B,KAAA,CAAA;EAAQ;AAAA,GAAW,WAAA,GAAW,OAAA,OAAA,OAAA"}
|
package/dist/global-setup.mjs
CHANGED
|
@@ -49,18 +49,7 @@ async function setup({ provide }) {
|
|
|
49
49
|
const rabbitmqContainer = await new GenericContainer(rabbitmqImage).withExposedPorts(5672, 15672).withEnvironment({
|
|
50
50
|
RABBITMQ_DEFAULT_USER: "guest",
|
|
51
51
|
RABBITMQ_DEFAULT_PASS: "guest"
|
|
52
|
-
}).
|
|
53
|
-
test: [
|
|
54
|
-
"CMD",
|
|
55
|
-
"rabbitmq-diagnostics",
|
|
56
|
-
"-q",
|
|
57
|
-
"check_running"
|
|
58
|
-
],
|
|
59
|
-
interval: 1e3,
|
|
60
|
-
retries: 30,
|
|
61
|
-
startPeriod: 3e3,
|
|
62
|
-
timeout: 5e3
|
|
63
|
-
}).withWaitStrategy(Wait.forHealthCheck()).withReuse().withAutoRemove(true).start();
|
|
52
|
+
}).withWaitStrategy(Wait.forAll([Wait.forLogMessage(/Server startup complete/), Wait.forListeningPorts()])).start();
|
|
64
53
|
console.log("โ
RabbitMQ container started");
|
|
65
54
|
const __TESTCONTAINERS_RABBITMQ_IP__ = rabbitmqContainer.getHost();
|
|
66
55
|
const __TESTCONTAINERS_RABBITMQ_PORT_5672__ = rabbitmqContainer.getMappedPort(5672);
|
|
@@ -74,6 +63,11 @@ async function setup({ provide }) {
|
|
|
74
63
|
provide("__TESTCONTAINERS_RABBITMQ_PASSWORD__", __TESTCONTAINERS_RABBITMQ_PASSWORD__);
|
|
75
64
|
console.log(`๐ RabbitMQ test environment is ready at ${__TESTCONTAINERS_RABBITMQ_IP__}:${__TESTCONTAINERS_RABBITMQ_PORT_5672__}`);
|
|
76
65
|
console.log(`๐ RabbitMQ management console available at http://${__TESTCONTAINERS_RABBITMQ_IP__}:${__TESTCONTAINERS_RABBITMQ_PORT_15672__}`);
|
|
66
|
+
return async () => {
|
|
67
|
+
console.log("๐งน Stopping RabbitMQ test environment...");
|
|
68
|
+
await rabbitmqContainer.stop();
|
|
69
|
+
console.log("โ
RabbitMQ container stopped");
|
|
70
|
+
};
|
|
77
71
|
}
|
|
78
72
|
|
|
79
73
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global-setup.mjs","names":[],"sources":["../src/global-setup.ts"],"sourcesContent":["/**\n * Global setup module for starting RabbitMQ test containers\n *\n * This module provides a Vitest globalSetup function that automatically starts\n * a RabbitMQ container with the management plugin before tests run, and stops\n * it after all tests complete.\n *\n * The RabbitMQ image can be configured via the `RABBITMQ_IMAGE` environment variable.\n * By default, it uses the public Docker Hub image (`rabbitmq:4.2.1-management-alpine`).\n *\n * @module global-setup\n * @packageDocumentation\n */\n\nimport { GenericContainer, Wait } from \"testcontainers\";\nimport type { TestProject } from \"vitest/node\";\n\n/**\n * Default RabbitMQ Docker image to use for testing.\n * Can be overridden via RABBITMQ_IMAGE environment variable.\n */\nconst DEFAULT_RABBITMQ_IMAGE = \"rabbitmq:4.2.1-management-alpine\";\n\ndeclare module \"vitest\" {\n // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- Module augmentation requires interface for declaration merging\n export interface ProvidedContext {\n __TESTCONTAINERS_RABBITMQ_IP__: string;\n __TESTCONTAINERS_RABBITMQ_PORT_5672__: number;\n __TESTCONTAINERS_RABBITMQ_PORT_15672__: number;\n __TESTCONTAINERS_RABBITMQ_USERNAME__: string;\n __TESTCONTAINERS_RABBITMQ_PASSWORD__: string;\n }\n}\n\n/**\n * Setup function for Vitest globalSetup\n *\n * Starts a RabbitMQ container before all tests and provides connection details\n * to tests via Vitest's provide API. The container is automatically stopped\n * and cleaned up after all tests complete.\n *\n * This function should be configured in your `vitest.config.ts`:\n *\n * @example\n * ```typescript\n * import { defineConfig } from \"vitest/config\";\n *\n * export default defineConfig({\n * test: {\n * globalSetup: [\"@amqp-contract/testing/global-setup\"],\n * },\n * });\n * ```\n *\n * @param provide - Function to provide context values to tests\n * @returns Cleanup function that stops the RabbitMQ container\n */\nexport default async function setup({ provide }: TestProject) {\n const rabbitmqImage = process.env[\"RABBITMQ_IMAGE\"] ?? DEFAULT_RABBITMQ_IMAGE;\n\n console.log(\"๐ณ Starting RabbitMQ test environment...\");\n console.log(`๐ฆ Using RabbitMQ image: ${rabbitmqImage}`);\n\n // Start RabbitMQ container with management plugin\n const rabbitmqContainer = await new GenericContainer(rabbitmqImage)\n .withExposedPorts(5672, 15672)\n .withEnvironment({\n RABBITMQ_DEFAULT_USER: \"guest\",\n RABBITMQ_DEFAULT_PASS: \"guest\",\n })\n .
|
|
1
|
+
{"version":3,"file":"global-setup.mjs","names":[],"sources":["../src/global-setup.ts"],"sourcesContent":["/**\n * Global setup module for starting RabbitMQ test containers\n *\n * This module provides a Vitest globalSetup function that automatically starts\n * a RabbitMQ container with the management plugin before tests run, and stops\n * it after all tests complete.\n *\n * The RabbitMQ image can be configured via the `RABBITMQ_IMAGE` environment variable.\n * By default, it uses the public Docker Hub image (`rabbitmq:4.2.1-management-alpine`).\n *\n * @module global-setup\n * @packageDocumentation\n */\n\nimport { GenericContainer, Wait } from \"testcontainers\";\nimport type { TestProject } from \"vitest/node\";\n\n/**\n * Default RabbitMQ Docker image to use for testing.\n * Can be overridden via RABBITMQ_IMAGE environment variable.\n */\nconst DEFAULT_RABBITMQ_IMAGE = \"rabbitmq:4.2.1-management-alpine\";\n\ndeclare module \"vitest\" {\n // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- Module augmentation requires interface for declaration merging\n export interface ProvidedContext {\n __TESTCONTAINERS_RABBITMQ_IP__: string;\n __TESTCONTAINERS_RABBITMQ_PORT_5672__: number;\n __TESTCONTAINERS_RABBITMQ_PORT_15672__: number;\n __TESTCONTAINERS_RABBITMQ_USERNAME__: string;\n __TESTCONTAINERS_RABBITMQ_PASSWORD__: string;\n }\n}\n\n/**\n * Setup function for Vitest globalSetup\n *\n * Starts a RabbitMQ container before all tests and provides connection details\n * to tests via Vitest's provide API. The container is automatically stopped\n * and cleaned up after all tests complete.\n *\n * This function should be configured in your `vitest.config.ts`:\n *\n * @example\n * ```typescript\n * import { defineConfig } from \"vitest/config\";\n *\n * export default defineConfig({\n * test: {\n * globalSetup: [\"@amqp-contract/testing/global-setup\"],\n * },\n * });\n * ```\n *\n * @param provide - Function to provide context values to tests\n * @returns Cleanup function that stops the RabbitMQ container\n */\nexport default async function setup({ provide }: TestProject) {\n const rabbitmqImage = process.env[\"RABBITMQ_IMAGE\"] ?? DEFAULT_RABBITMQ_IMAGE;\n\n console.log(\"๐ณ Starting RabbitMQ test environment...\");\n console.log(`๐ฆ Using RabbitMQ image: ${rabbitmqImage}`);\n\n // Start RabbitMQ container with management plugin\n const rabbitmqContainer = await new GenericContainer(rabbitmqImage)\n .withExposedPorts(5672, 15672)\n .withEnvironment({\n RABBITMQ_DEFAULT_USER: \"guest\",\n RABBITMQ_DEFAULT_PASS: \"guest\",\n })\n .withWaitStrategy(\n Wait.forAll([Wait.forLogMessage(/Server startup complete/), Wait.forListeningPorts()]),\n )\n .start();\n\n console.log(\"โ
RabbitMQ container started\");\n\n const __TESTCONTAINERS_RABBITMQ_IP__ = rabbitmqContainer.getHost();\n const __TESTCONTAINERS_RABBITMQ_PORT_5672__ = rabbitmqContainer.getMappedPort(5672);\n const __TESTCONTAINERS_RABBITMQ_PORT_15672__ = rabbitmqContainer.getMappedPort(15672);\n const __TESTCONTAINERS_RABBITMQ_USERNAME__ = \"guest\";\n const __TESTCONTAINERS_RABBITMQ_PASSWORD__ = \"guest\";\n\n // Provide context values with type assertions to work around TypeScript limitations\n provide(\"__TESTCONTAINERS_RABBITMQ_IP__\", __TESTCONTAINERS_RABBITMQ_IP__);\n provide(\"__TESTCONTAINERS_RABBITMQ_PORT_5672__\", __TESTCONTAINERS_RABBITMQ_PORT_5672__);\n provide(\"__TESTCONTAINERS_RABBITMQ_PORT_15672__\", __TESTCONTAINERS_RABBITMQ_PORT_15672__);\n provide(\"__TESTCONTAINERS_RABBITMQ_USERNAME__\", __TESTCONTAINERS_RABBITMQ_USERNAME__);\n provide(\"__TESTCONTAINERS_RABBITMQ_PASSWORD__\", __TESTCONTAINERS_RABBITMQ_PASSWORD__);\n\n console.log(\n `๐ RabbitMQ test environment is ready at ${__TESTCONTAINERS_RABBITMQ_IP__}:${__TESTCONTAINERS_RABBITMQ_PORT_5672__}`,\n );\n console.log(\n `๐ RabbitMQ management console available at http://${__TESTCONTAINERS_RABBITMQ_IP__}:${__TESTCONTAINERS_RABBITMQ_PORT_15672__}`,\n );\n\n // Return cleanup function that stops the container\n return async () => {\n console.log(\"๐งน Stopping RabbitMQ test environment...\");\n await rabbitmqContainer.stop();\n console.log(\"โ
RabbitMQ container stopped\");\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAqBA,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;AAoC/B,eAA8B,MAAM,EAAE,WAAwB;CAC5D,MAAM,gBAAgB,QAAQ,IAAI,qBAAqB;AAEvD,SAAQ,IAAI,2CAA2C;AACvD,SAAQ,IAAI,4BAA4B,gBAAgB;CAGxD,MAAM,oBAAoB,MAAM,IAAI,iBAAiB,cAAc,CAChE,iBAAiB,MAAM,MAAM,CAC7B,gBAAgB;EACf,uBAAuB;EACvB,uBAAuB;EACxB,CAAC,CACD,iBACC,KAAK,OAAO,CAAC,KAAK,cAAc,0BAA0B,EAAE,KAAK,mBAAmB,CAAC,CAAC,CACvF,CACA,OAAO;AAEV,SAAQ,IAAI,+BAA+B;CAE3C,MAAM,iCAAiC,kBAAkB,SAAS;CAClE,MAAM,wCAAwC,kBAAkB,cAAc,KAAK;CACnF,MAAM,yCAAyC,kBAAkB,cAAc,MAAM;CACrF,MAAM,uCAAuC;CAC7C,MAAM,uCAAuC;AAG7C,SAAQ,kCAAkC,+BAA+B;AACzE,SAAQ,yCAAyC,sCAAsC;AACvF,SAAQ,0CAA0C,uCAAuC;AACzF,SAAQ,wCAAwC,qCAAqC;AACrF,SAAQ,wCAAwC,qCAAqC;AAErF,SAAQ,IACN,4CAA4C,+BAA+B,GAAG,wCAC/E;AACD,SAAQ,IACN,sDAAsD,+BAA+B,GAAG,yCACzF;AAGD,QAAO,YAAY;AACjB,UAAQ,IAAI,2CAA2C;AACvD,QAAM,kBAAkB,MAAM;AAC9B,UAAQ,IAAI,+BAA+B"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
[**@amqp-contract/testing**](index.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@amqp-contract/testing](index.md) / extension
|
|
6
|
+
|
|
7
|
+
# extension
|
|
8
|
+
|
|
9
|
+
Vitest extension module for AMQP testing utilities
|
|
10
|
+
|
|
11
|
+
This module provides a Vitest test extension that adds AMQP-specific fixtures
|
|
12
|
+
to your tests. Each test gets an isolated virtual host (vhost) with pre-configured
|
|
13
|
+
connections, channels, and helper functions for publishing and consuming messages.
|
|
14
|
+
|
|
15
|
+
## Variables
|
|
16
|
+
|
|
17
|
+
### it
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
const it: TestAPI<{
|
|
21
|
+
amqpChannel: Channel;
|
|
22
|
+
amqpConnection: ChannelModel;
|
|
23
|
+
amqpConnectionUrl: string;
|
|
24
|
+
initConsumer: (exchange, routingKey) => Promise<(options?) => Promise<ConsumeMessage[]>>;
|
|
25
|
+
publishMessage: (exchange, routingKey, content) => void;
|
|
26
|
+
vhost: string;
|
|
27
|
+
}>;
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Defined in: [extension.ts:16](https://github.com/btravers/amqp-contract/blob/a7c4b48f76ed6c3c5c7a9d457229c7ba475af3b1/packages/testing/src/extension.ts#L16)
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
[**@amqp-contract/testing**](index.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@amqp-contract/testing](index.md) / global-setup
|
|
6
|
+
|
|
7
|
+
# global-setup
|
|
8
|
+
|
|
9
|
+
Global setup module for starting RabbitMQ test containers
|
|
10
|
+
|
|
11
|
+
This module provides a Vitest globalSetup function that automatically starts
|
|
12
|
+
a RabbitMQ container with the management plugin before tests run, and stops
|
|
13
|
+
it after all tests complete.
|
|
14
|
+
|
|
15
|
+
The RabbitMQ image can be configured via the `RABBITMQ_IMAGE` environment variable.
|
|
16
|
+
By default, it uses the public Docker Hub image (`rabbitmq:4.2.1-management-alpine`).
|
|
17
|
+
|
|
18
|
+
## Functions
|
|
19
|
+
|
|
20
|
+
### default()
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
function default(provide): Promise<() => Promise<void>>;
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Defined in: [global-setup.ts:58](https://github.com/btravers/amqp-contract/blob/a7c4b48f76ed6c3c5c7a9d457229c7ba475af3b1/packages/testing/src/global-setup.ts#L58)
|
|
27
|
+
|
|
28
|
+
Setup function for Vitest globalSetup
|
|
29
|
+
|
|
30
|
+
Starts a RabbitMQ container before all tests and provides connection details
|
|
31
|
+
to tests via Vitest's provide API. The container is automatically stopped
|
|
32
|
+
and cleaned up after all tests complete.
|
|
33
|
+
|
|
34
|
+
This function should be configured in your `vitest.config.ts`:
|
|
35
|
+
|
|
36
|
+
#### Parameters
|
|
37
|
+
|
|
38
|
+
| Parameter | Type | Description |
|
|
39
|
+
| ------ | ------ | ------ |
|
|
40
|
+
| `provide` | `TestProject` | Function to provide context values to tests |
|
|
41
|
+
|
|
42
|
+
#### Returns
|
|
43
|
+
|
|
44
|
+
`Promise`<() => `Promise`<`void`>>
|
|
45
|
+
|
|
46
|
+
Cleanup function that stops the RabbitMQ container
|
|
47
|
+
|
|
48
|
+
#### Example
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
import { defineConfig } from "vitest/config";
|
|
52
|
+
|
|
53
|
+
export default defineConfig({
|
|
54
|
+
test: {
|
|
55
|
+
globalSetup: ["@amqp-contract/testing/global-setup"],
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
```
|
package/docs/index.md
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amqp-contract/testing",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "Testing utilities for AMQP contracts with testcontainers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"amqp",
|
|
@@ -30,7 +30,8 @@
|
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
32
|
"files": [
|
|
33
|
-
"dist"
|
|
33
|
+
"dist",
|
|
34
|
+
"docs"
|
|
34
35
|
],
|
|
35
36
|
"dependencies": {
|
|
36
37
|
"amqplib": "0.10.9",
|
|
@@ -38,11 +39,11 @@
|
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
41
|
"@types/amqplib": "0.10.8",
|
|
41
|
-
"tsdown": "0.
|
|
42
|
+
"tsdown": "0.20.3",
|
|
42
43
|
"typedoc": "0.28.16",
|
|
43
44
|
"typedoc-plugin-markdown": "4.9.0",
|
|
44
45
|
"typescript": "5.9.3",
|
|
45
|
-
"vitest": "4.0.
|
|
46
|
+
"vitest": "4.0.18",
|
|
46
47
|
"@amqp-contract/tsconfig": "0.1.0",
|
|
47
48
|
"@amqp-contract/typedoc": "0.1.0"
|
|
48
49
|
},
|