@tsed/testcontainers-redis 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.
Files changed (2) hide show
  1. package/package.json +36 -0
  2. package/readme.md +199 -0
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@tsed/testcontainers-redis",
3
+ "description": "A module to test Ts.ED code that use Redis as database using 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/redis",
34
+ "author": "Romain Lenzotti",
35
+ "license": "MIT"
36
+ }
package/readme.md ADDED
@@ -0,0 +1,199 @@
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 Redis</h1>
7
+
8
+ [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
9
+ [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
10
+ [![github](https://img.shields.io/static/v1?label=Github%20sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/romakita)
11
+ [![opencollective](https://img.shields.io/static/v1?label=OpenCollective%20sponsor&message=%E2%9D%A4&logo=OpenCollective&color=%23fe8e86)](https://opencollective.com/tsed)
12
+
13
+ </div>
14
+
15
+ <div align="center">
16
+ <a href="https://tsed.dev/">Website</a>
17
+ <span>&nbsp;&nbsp;โ€ข&nbsp;&nbsp;</span>
18
+ <a href="https://tsed.dev/getting-started/">Getting started</a>
19
+ <span>&nbsp;&nbsp;โ€ข&nbsp;&nbsp;</span>
20
+ <a href="https://slack.tsed.dev">Slack</a>
21
+ <span>&nbsp;&nbsp;โ€ข&nbsp;&nbsp;</span>
22
+ <a href="https://twitter.com/TsED_io">Twitter</a>
23
+ </div>
24
+
25
+ <hr />
26
+
27
+ A [Ts.ED](https://tsed.dev/) package to help you easily test your code using the power of [TestContainers](https://node.testcontainers.org/) with Redis.
28
+
29
+ > **Note:** This package does **not** depend on `@tsed/platform-http` and can be used with any test framework.
30
+
31
+ ---
32
+
33
+ ## โœจ Features
34
+
35
+ - ๐Ÿš€ Easily spin up a Redis server in a Docker container for your tests
36
+ - ๐Ÿ›‘ Automatically stop the Redis server after your tests
37
+ - ๐Ÿ”„ Reset the Redis server state between tests (by restarting the container)
38
+ - ๐Ÿท๏ธ Namespacing support to avoid collisions between different test suites
39
+
40
+ ---
41
+
42
+ ## ๐Ÿ“ฆ Installation
43
+
44
+ Install the package with your favorite package manager:
45
+
46
+ ```sh npm
47
+ npm install --save-dev @tsedio/testcontainers-redis
48
+ ```
49
+
50
+ ```sh yarn
51
+ yarn add --dev @tsedio/testcontainers-redis
52
+ ```
53
+
54
+ ```sh pnpm
55
+ pnpm add --dev @tsedio/testcontainers-redis
56
+ ```
57
+
58
+ ```sh bun
59
+ bun add --dev @tsedio/testcontainers-redis
60
+ ```
61
+
62
+ ---
63
+
64
+ ## โš™๏ธ Configuration
65
+
66
+ Set up a global test lifecycle to manage your Redis container.
67
+
68
+ ### ๐Ÿงช Vitest
69
+
70
+ Add a global setup in your `vitest.config.ts`:
71
+
72
+ ```ts
73
+ import {defineConfig} from "vitest/config";
74
+
75
+ export default defineConfig({
76
+ test: {
77
+ globalSetup: [import.meta.resolve("@tsed/testcontainers-redis/vitest/setup")]
78
+ }
79
+ });
80
+ ```
81
+
82
+ ---
83
+
84
+ ### ๐Ÿงช Jest
85
+
86
+ Add `globalSetup` and `globalTeardown` to your Jest config:
87
+
88
+ ```ts
89
+ // jest.config.js
90
+ module.exports = {
91
+ globalSetup: ["jest.setup.js"],
92
+ globalTeardown: ["jest.teardown.js"]
93
+ };
94
+ ```
95
+
96
+ Create the following files:
97
+
98
+ ```ts
99
+ // jest.setup.js
100
+ import {TestContainersRedis} from "@tsedio/testcontainers-redis";
101
+ module.exports = async () => {
102
+ await TestContainersRedis.startContainer();
103
+ };
104
+
105
+ // jest.teardown.js
106
+ import {TestContainersRedis} from "@tsedio/testcontainers-redis";
107
+ module.exports = async () => {
108
+ await TestContainersRedis.stopContainer();
109
+ };
110
+ ```
111
+
112
+ ---
113
+
114
+ ## ๐Ÿ› ๏ธ Usage
115
+
116
+ Set up a Redis connection in your project like this:
117
+
118
+ ```ts
119
+ import {registerConnectionProvider} from "@tsed/ioredis";
120
+ import {type Redis} from "ioredis";
121
+
122
+ export const REDIS_CONNECTION = Symbol.for("REDIS_CONNECTION");
123
+ export type REDIS_CONNECTION = typeof Redis;
124
+
125
+ registerConnectionProvider({
126
+ token: REDIS_CONNECTION,
127
+ name: "default"
128
+ });
129
+ ```
130
+
131
+ Start the Redis server before your tests using `TestContainersRedis`:
132
+
133
+ ```ts
134
+ import {PlatformTest, inject} from "@tsed/platform-http/testing";
135
+ import {TestContainersRedis} from "@tsedio/testcontainers-redis";
136
+
137
+ describe("Integration test", () => {
138
+ beforeEach(() => {
139
+ return PlatformTest.create({
140
+ ioredis: [
141
+ {
142
+ name: "redis",
143
+ ...TestContainersRedis.getRedisOptions()
144
+ }
145
+ ]
146
+ });
147
+ });
148
+
149
+ afterEach(() => PlatformTest.reset());
150
+
151
+ it("should run pre and post hook", async () => {
152
+ const client = inject(REDIS_CONNECTION);
153
+ // do something with the client
154
+ });
155
+ });
156
+ ```
157
+
158
+ ---
159
+
160
+ ## ๐Ÿ’ก Tips
161
+
162
+ - ๐Ÿงน Use `TestContainersRedis.reset()` to clear the Redis server state between tests (by restarting the container).
163
+ - ๐Ÿท๏ธ Use `TestContainersRedis.getRedisOptions(namespace, options)` to generate Redis connection options:
164
+ - `namespace`: isolates Redis instances between tests.
165
+ - `options`: corresponds to [RedisOptions](https://github.com/redis/ioredis/blob/master/API.md#new-redisport-host-options).
166
+ - ๐ŸŒ You can set a global namespace with `TestContainersRedis.setNamespace("my-namespace")` if you want to use the same namespace in every call.
167
+
168
+ ---
169
+
170
+ ## ๐Ÿ“š Resources
171
+
172
+ - [Ts.ED Documentation](https://tsed.dev/) ๐Ÿ“–
173
+ - [TestContainers Node.js](https://node.testcontainers.org/) ๐Ÿณ
174
+
175
+ ## Contributors
176
+
177
+ <a href="https://github.com/tsedio/tsed/graphs/contributors"><img src="https://opencollective.com/tsed/contributors.svg?width=890" /></a>
178
+
179
+ ## Backers
180
+
181
+ Thank you to all our backers! ๐Ÿ™ [[Become a backer](https://opencollective.com/tsed#backer)]
182
+
183
+ <a href="https://opencollective.com/tsed#backers" target="_blank"><img src="https://opencollective.com/tsed/tiers/backer.svg?width=890"></a>
184
+
185
+ ## Sponsors
186
+
187
+ Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/tsed#sponsor)]
188
+
189
+ ## License
190
+
191
+ The MIT License (MIT)
192
+
193
+ Copyright (c) 2016 - Today Ts.ED
194
+
195
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
196
+
197
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
198
+
199
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.