@tsed/testcontainers-localstack 8.29.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/package.json +36 -0
- package/readme.md +180 -0
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tsed/testcontainers-localstack",
|
|
3
|
+
"description": "A module to test Ts.ED code that use AWS services using LocalStack and Test Containers",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"version": "8.29.0",
|
|
6
|
+
"source": "./src/index.ts",
|
|
7
|
+
"main": "./lib/esm/index.js",
|
|
8
|
+
"module": "./lib/esm/index.js",
|
|
9
|
+
"typings": "./lib/types/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"tsed-source": "./src/index.ts",
|
|
13
|
+
"types": "./lib/types/index.d.ts",
|
|
14
|
+
"import": "./lib/esm/index.js",
|
|
15
|
+
"default": "./lib/esm/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "yarn build:ts",
|
|
20
|
+
"build:ts": "tsc --build tsconfig.esm.json"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"tslib": "2.8.1"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"typescript": "6.0.2"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {},
|
|
29
|
+
"repository": "https://github.com/tsedio/tsed",
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/tsedio/tsed/issues"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://github.com/tsedio/tsed/tree/production/packages/testcontainers/localstack",
|
|
34
|
+
"author": "Romain Lenzotti",
|
|
35
|
+
"license": "MIT"
|
|
36
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
<p style="text-align: center" align="center">
|
|
2
|
+
<a href="https://tsed.dev" target="_blank"><img src="https://tsed.dev/tsed-og.png" width="200" alt="Ts.ED logo"/></a>
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<div align="center">
|
|
6
|
+
<h1>TestContainers LocalStack</h1>
|
|
7
|
+
|
|
8
|
+
[](https://github.com/semantic-release/semantic-release)
|
|
9
|
+
[](https://github.com/prettier/prettier)
|
|
10
|
+
[](https://github.com/sponsors/romakita)
|
|
11
|
+
[](https://opencollective.com/tsed)
|
|
12
|
+
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
<div align="center">
|
|
16
|
+
<a href="https://tsed.dev/">Website</a>
|
|
17
|
+
<span> โข </span>
|
|
18
|
+
<a href="https://tsed.dev/getting-started/">Getting started</a>
|
|
19
|
+
<span> โข </span>
|
|
20
|
+
<a href="https://slack.tsed.dev">Slack</a>
|
|
21
|
+
<span> โข </span>
|
|
22
|
+
<a href="https://twitter.com/TsED_io">Twitter</a>
|
|
23
|
+
</div>
|
|
24
|
+
|
|
25
|
+
<hr />
|
|
26
|
+
|
|
27
|
+
A package for the [Ts.ED](https://tsed.dev/) framework to help you test your code using the [TestContainers](https://node.testcontainers.org/) library with [LocalStack](https://localstack.cloud/).
|
|
28
|
+
|
|
29
|
+
> **Note**: This package does **not** depend on `@tsed/platform-http`. You can use it with any test framework.
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## โจ Features
|
|
34
|
+
|
|
35
|
+
- ๐ **Spin up a LocalStack server** using TestContainers for your tests
|
|
36
|
+
- ๐ **Automatically stop** the LocalStack server after your tests
|
|
37
|
+
- ๐ง **Configure AWS services** to use in your tests
|
|
38
|
+
- ๐ **Set environment variables** for AWS SDK to use LocalStack
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## ๐ฆ Installation
|
|
43
|
+
|
|
44
|
+
Install with your favorite package manager:
|
|
45
|
+
|
|
46
|
+
```sh npm
|
|
47
|
+
npm install --save-dev @tsed/testcontainers-localstack @testcontainers/localstack
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
```sh yarn
|
|
51
|
+
yarn add --dev @tsed/testcontainers-localstack @testcontainers/localstack
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
```sh pnpm
|
|
55
|
+
pnpm add --dev @tsed/testcontainers-localstack @testcontainers/localstack
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
```sh bun
|
|
59
|
+
bun add --dev @tsed/testcontainers-localstack @testcontainers/localstack
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
This package uses `@testcontainers/localstack` which provides a specialized container for LocalStack.
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## โ๏ธ Configuration
|
|
67
|
+
|
|
68
|
+
Set up a global test lifecycle to manage the LocalStack container.
|
|
69
|
+
|
|
70
|
+
### ๐งช Vitest
|
|
71
|
+
|
|
72
|
+
Add a global setup file in your `vitest.config.ts`:
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import {defineConfig} from "vitest/config";
|
|
76
|
+
import {localstackPlugin} from "@tsed/testcontainers-localstack/vitest/plugin";
|
|
77
|
+
|
|
78
|
+
export default defineConfig({
|
|
79
|
+
plugins: [
|
|
80
|
+
localstackPlugin({
|
|
81
|
+
// Optional: image name (defaults to "localstack/localstack:latest")
|
|
82
|
+
image: "localstack/localstack:latest",
|
|
83
|
+
// Optional: specify services to start
|
|
84
|
+
services: ["s3", "dynamodb", "lambda"],
|
|
85
|
+
// Optional: specify default region
|
|
86
|
+
defaultRegion: "us-east-1",
|
|
87
|
+
// Optional: specify edge port
|
|
88
|
+
edgePort: 4566
|
|
89
|
+
})
|
|
90
|
+
],
|
|
91
|
+
test: {}
|
|
92
|
+
});
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## ๐ Usage
|
|
98
|
+
|
|
99
|
+
### Basic Usage
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
import {TestContainersLocalstack} from "@tsed/testcontainers-localstack";
|
|
103
|
+
import {ListBucketsCommand, S3Client} from "@aws-sdk/client-s3";
|
|
104
|
+
|
|
105
|
+
describe("S3 Tests", () => {
|
|
106
|
+
let s3Client: S3Client;
|
|
107
|
+
|
|
108
|
+
beforeEach(async () => {
|
|
109
|
+
// Create an S3 client that points to LocalStack
|
|
110
|
+
s3Client = new S3Client({
|
|
111
|
+
endpoint: TestContainersLocalstack.getUrl(),
|
|
112
|
+
region: "us-east-1",
|
|
113
|
+
credentials: {
|
|
114
|
+
accessKeyId: "test",
|
|
115
|
+
secretAccessKey: "test"
|
|
116
|
+
},
|
|
117
|
+
forcePathStyle: true
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
afterEach(async () => {
|
|
121
|
+
// Clean up any resources
|
|
122
|
+
try {
|
|
123
|
+
await s3Client.send(new DeleteBucketCommand({Bucket: bucketName}));
|
|
124
|
+
} catch (error) {
|
|
125
|
+
// Ignore errors if bucket doesn't exist
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("should list buckets", async () => {
|
|
130
|
+
const response = await s3Client.send(new ListBucketsCommand({}));
|
|
131
|
+
expect(response.Buckets).toBeDefined();
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Environment Variables
|
|
137
|
+
|
|
138
|
+
The following environment variables are automatically set when the container starts:
|
|
139
|
+
|
|
140
|
+
- `LOCALSTACK_URL`: The URL of the LocalStack container
|
|
141
|
+
- `AWS_ENDPOINT`: The URL of the LocalStack container (for AWS SDK)
|
|
142
|
+
- `AWS_ACCESS_KEY_ID`: Set to "test"
|
|
143
|
+
- `AWS_SECRET_ACCESS_KEY`: Set to "test"
|
|
144
|
+
- `AWS_REGION`: The default region (defaults to "us-east-1")
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## Contributors
|
|
149
|
+
|
|
150
|
+
<a href="https://github.com/tsedio/tsed/graphs/contributors"><img src="https://opencollective.com/tsed/contributors.svg?width=890" /></a>
|
|
151
|
+
|
|
152
|
+
## Backers
|
|
153
|
+
|
|
154
|
+
Thank you to all our backers! ๐ [[Become a backer](https://opencollective.com/tsed#backer)]
|
|
155
|
+
|
|
156
|
+
<a href="https://opencollective.com/tsed#backers" target="_blank"><img src="https://opencollective.com/tsed/tiers/backer.svg?width=890"></a>
|
|
157
|
+
|
|
158
|
+
## Sponsors
|
|
159
|
+
|
|
160
|
+
Support this project by becoming a sponsor. Your logo will show up here with a link to your
|
|
161
|
+
website. [[Become a sponsor](https://opencollective.com/tsed#sponsor)]
|
|
162
|
+
|
|
163
|
+
## License
|
|
164
|
+
|
|
165
|
+
The MIT License (MIT)
|
|
166
|
+
|
|
167
|
+
Copyright (c) 2016 - 2022 Romain Lenzotti
|
|
168
|
+
|
|
169
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
170
|
+
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
|
171
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
172
|
+
persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
173
|
+
|
|
174
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
|
175
|
+
Software.
|
|
176
|
+
|
|
177
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
|
178
|
+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
179
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
180
|
+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|