@amqp-contract/testing 0.0.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 +100 -0
- package/dist/extension.d.mts +10 -0
- package/dist/extension.d.mts.map +1 -0
- package/dist/extension.mjs +13124 -0
- package/dist/extension.mjs.map +1 -0
- package/dist/global-setup.d.mts +20 -0
- package/dist/global-setup.d.mts.map +1 -0
- package/dist/global-setup.mjs +43 -0
- package/dist/global-setup.mjs.map +1 -0
- package/dist/magic-string.es-mfcqQQ0l.mjs +1014 -0
- package/dist/magic-string.es-mfcqQQ0l.mjs.map +1 -0
- package/package.json +35 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Benoit Travers
|
|
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,100 @@
|
|
|
1
|
+
# @amqp-contract/testing
|
|
2
|
+
|
|
3
|
+
Testing utilities for AMQP contracts using testcontainers.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🐳 Automatically starts RabbitMQ container for tests
|
|
8
|
+
- ✅ Works with Vitest globalSetup
|
|
9
|
+
- 🚀 Fast and reliable integration testing
|
|
10
|
+
- 📊 Includes RabbitMQ management console
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pnpm add -D @amqp-contract/testing
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
### 1. Configure Vitest
|
|
21
|
+
|
|
22
|
+
Add to your `vitest.config.ts`:
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { defineConfig } from "vitest/config";
|
|
26
|
+
|
|
27
|
+
export default defineConfig({
|
|
28
|
+
test: {
|
|
29
|
+
globalSetup: ["@amqp-contract/testing/global-setup"],
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### 2. TypeScript Support
|
|
35
|
+
|
|
36
|
+
For TypeScript projects, reference the type definitions in your `tsconfig.json`:
|
|
37
|
+
|
|
38
|
+
```json
|
|
39
|
+
{
|
|
40
|
+
"compilerOptions": {
|
|
41
|
+
"types": ["@amqp-contract/testing/types/vitest"]
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Or add a triple-slash reference in your test files:
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
/// <reference types="@amqp-contract/testing/types/vitest" />
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
This provides type-safe access to the test container context variables.
|
|
53
|
+
|
|
54
|
+
### 3. Use Vitest Extension in Tests
|
|
55
|
+
|
|
56
|
+
The package provides a Vitest extension that automatically manages RabbitMQ connections:
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import { describe, expect } from "vitest";
|
|
60
|
+
import { it } from "@amqp-contract/testing/extension";
|
|
61
|
+
|
|
62
|
+
describe("Order Processing", () => {
|
|
63
|
+
it("should publish and consume messages", async ({ amqpConnection }) => {
|
|
64
|
+
// amqpConnection is automatically provided and cleaned up
|
|
65
|
+
// Your test code here using amqpConnection
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
The extension provides:
|
|
71
|
+
|
|
72
|
+
- `amqpConnection`: An established connection to the RabbitMQ testcontainer
|
|
73
|
+
- Automatic connection cleanup after each test
|
|
74
|
+
|
|
75
|
+
## What It Does
|
|
76
|
+
|
|
77
|
+
The global setup:
|
|
78
|
+
|
|
79
|
+
1. Starts a RabbitMQ container with management plugin
|
|
80
|
+
2. Waits for RabbitMQ to be healthy
|
|
81
|
+
3. Provides connection details to your tests
|
|
82
|
+
4. Cleans up the container after tests complete
|
|
83
|
+
|
|
84
|
+
## Container Details
|
|
85
|
+
|
|
86
|
+
- **Image**: `rabbitmq:3-management-alpine`
|
|
87
|
+
- **Ports**:
|
|
88
|
+
- 5672 (AMQP)
|
|
89
|
+
- 15672 (Management console)
|
|
90
|
+
- **Credentials**:
|
|
91
|
+
- User: `guest`
|
|
92
|
+
- Password: `guest`
|
|
93
|
+
|
|
94
|
+
## Environment Variables
|
|
95
|
+
|
|
96
|
+
The following variables are provided to tests:
|
|
97
|
+
|
|
98
|
+
- `__TESTCONTAINERS_RABBITMQ_IP__` - Container host IP
|
|
99
|
+
- `__TESTCONTAINERS_RABBITMQ_PORT_5672__` - Mapped AMQP port
|
|
100
|
+
- `__TESTCONTAINERS_RABBITMQ_PORT_15672__` - Mapped management port
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ChannelModel } from "amqplib";
|
|
2
|
+
import * as vitest0 from "vitest";
|
|
3
|
+
|
|
4
|
+
//#region src/extension.d.ts
|
|
5
|
+
declare const it: vitest0.TestAPI<{
|
|
6
|
+
amqpConnection: ChannelModel;
|
|
7
|
+
}>;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { it };
|
|
10
|
+
//# sourceMappingURL=extension.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extension.d.mts","names":[],"sources":["../src/extension.ts"],"sourcesContent":[],"mappings":";;;;cAGa,IAWX,OAAA,CAXa;kBAWb"}
|