@tsed/testcontainers-mongo 8.11.0 → 8.11.2-rc.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/lib/esm/index.js +0 -1
- package/lib/esm/services/ContainerUtils.js +0 -1
- package/lib/esm/services/TestContainersMongo.js +0 -1
- package/lib/esm/setup/vi.setup.js +0 -1
- package/package.json +10 -7
- package/readme.md +18 -4
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/services/ContainerUtils.js.map +0 -1
- package/lib/esm/services/TestContainersMongo.js.map +0 -1
- package/lib/esm/setup/vi.setup.js.map +0 -1
- package/src/index.ts +0 -1
- package/src/services/ContainerUtils.ts +0 -84
- package/src/services/TestContainersMongo.ts +0 -55
- package/src/setup/vi.setup.ts +0 -9
package/lib/esm/index.js
CHANGED
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@tsed/testcontainers-mongo",
|
|
3
3
|
"description": "A module to test Ts.ED code that use MongoDB as database using Test Containers",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "8.11.
|
|
5
|
+
"version": "8.11.2-rc.1",
|
|
6
6
|
"source": "./src/index.ts",
|
|
7
7
|
"main": "./lib/esm/index.js",
|
|
8
8
|
"module": "./lib/esm/index.js",
|
|
@@ -31,11 +31,11 @@
|
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@testcontainers/mongodb": "^10.13.2",
|
|
34
|
-
"@tsed/barrels": "8.11.
|
|
35
|
-
"@tsed/core": "8.11.
|
|
36
|
-
"@tsed/di": "8.11.
|
|
37
|
-
"@tsed/platform-http": "8.11.
|
|
38
|
-
"@tsed/typescript": "8.11.
|
|
34
|
+
"@tsed/barrels": "8.11.2-rc.1",
|
|
35
|
+
"@tsed/core": "8.11.2-rc.1",
|
|
36
|
+
"@tsed/di": "8.11.2-rc.1",
|
|
37
|
+
"@tsed/platform-http": "8.11.2-rc.1",
|
|
38
|
+
"@tsed/typescript": "8.11.2-rc.1",
|
|
39
39
|
"eslint": "9.12.0",
|
|
40
40
|
"mongodb": "6.9.0",
|
|
41
41
|
"testcontainers": ">=10.11.0",
|
|
@@ -55,5 +55,8 @@
|
|
|
55
55
|
},
|
|
56
56
|
"homepage": "https://github.com/tsedio/tsed/tree/production/packages/orm/testcontainers-mongo",
|
|
57
57
|
"author": "Romain Lenzotti",
|
|
58
|
-
"license": "MIT"
|
|
58
|
+
"license": "MIT",
|
|
59
|
+
"publishConfig": {
|
|
60
|
+
"tag": "rc"
|
|
61
|
+
}
|
|
59
62
|
}
|
package/readme.md
CHANGED
|
@@ -51,6 +51,12 @@ pnpm add --dev @tsed/testcontainers-mongo
|
|
|
51
51
|
bun add --dev @tsed/testcontainers-mongo
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
+
### Important
|
|
55
|
+
|
|
56
|
+
This package requires the `@tsed/platform-http` package to work properly. If you're looking for a standalone package,
|
|
57
|
+
you can use the `@tsedio/testcontainers-mongo` premium package available
|
|
58
|
+
here: https://tsed.dev/plugins/premium/config-source/mongo.html
|
|
59
|
+
|
|
54
60
|
### Configuration
|
|
55
61
|
|
|
56
62
|
Add or update your jest or vitest configuration file to add a global setup file:
|
|
@@ -201,7 +207,8 @@ Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com
|
|
|
201
207
|
|
|
202
208
|
## Sponsors
|
|
203
209
|
|
|
204
|
-
Support this project by becoming a sponsor. Your logo will show up here with a link to your
|
|
210
|
+
Support this project by becoming a sponsor. Your logo will show up here with a link to your
|
|
211
|
+
website. [[Become a sponsor](https://opencollective.com/tsed#sponsor)]
|
|
205
212
|
|
|
206
213
|
## License
|
|
207
214
|
|
|
@@ -209,8 +216,15 @@ The MIT License (MIT)
|
|
|
209
216
|
|
|
210
217
|
Copyright (c) 2016 - 2022 Romain Lenzotti
|
|
211
218
|
|
|
212
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
219
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
220
|
+
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
|
221
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
222
|
+
persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
213
223
|
|
|
214
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
|
224
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
|
225
|
+
Software.
|
|
215
226
|
|
|
216
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
|
227
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
|
228
|
+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
229
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
230
|
+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/lib/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mCAAmC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ContainerUtils.js","sourceRoot":"","sources":["../../../src/services/ContainerUtils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,gBAAgB,EAA0B,MAAM,yBAAyB,CAAC;AAWlF,MAAM,GAAG,GAAG,sBAAsB,CAAC;AAEnC,aAAa;AACb,MAAM,CA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AK,UAAU,KAAK;IACzB,MAAM,gBAAgB,EAAE,CAAC;AAC3B,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,QAAQ;IAC5B,MAAM,eAAe,EAAE,CAAC;AAC1B,CAAC"}
|
package/src/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./services/TestContainersMongo.js";
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import type {ConnectionOptions} from "node:tls";
|
|
2
|
-
|
|
3
|
-
import {MongoDBContainer, StartedMongoDBContainer} from "@testcontainers/mongodb";
|
|
4
|
-
import type {ConnectOptions} from "mongoose";
|
|
5
|
-
|
|
6
|
-
declare global {
|
|
7
|
-
namespace NodeJS {
|
|
8
|
-
interface Global {
|
|
9
|
-
TEST_CONTAINER_MONGO: StartedMongoDBContainer | null;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const KEY = "TEST_CONTAINER_MONGO";
|
|
15
|
-
|
|
16
|
-
// @ts-ignore
|
|
17
|
-
global[KEY] = null;
|
|
18
|
-
|
|
19
|
-
function getEnvironment<T>(key: string): T | null {
|
|
20
|
-
// @ts-ignore
|
|
21
|
-
return global[key];
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function setEnvironment(key: string, environment: unknown) {
|
|
25
|
-
// @ts-ignore
|
|
26
|
-
global[key] = environment;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function createMongoContainer(image = "mongo:6.0.1") {
|
|
30
|
-
return new MongoDBContainer(image).start();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export async function startMongoServer(image?: string) {
|
|
34
|
-
// await stopMockServer()
|
|
35
|
-
const container = getEnvironment<StartedMongoDBContainer>(KEY) || (await createMongoContainer(image));
|
|
36
|
-
|
|
37
|
-
setEnvironment(KEY, container);
|
|
38
|
-
|
|
39
|
-
process.env.MONGO_URL = container.getConnectionString();
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
container,
|
|
43
|
-
url: process.env.MONGO_URL
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export async function stopMongoServer() {
|
|
48
|
-
const container = getEnvironment<StartedMongoDBContainer>(KEY);
|
|
49
|
-
|
|
50
|
-
process.stdout.write("Stopping mongo server\n");
|
|
51
|
-
if (container) {
|
|
52
|
-
await container.stop();
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function getMongoUrl(): string {
|
|
57
|
-
return process.env.MONGO_URL as string;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function getMongoConnectionOptions(
|
|
61
|
-
id: string = "",
|
|
62
|
-
opts: ConnectOptions = {}
|
|
63
|
-
): {
|
|
64
|
-
id: string;
|
|
65
|
-
url: string;
|
|
66
|
-
connectionOptions: ConnectOptions;
|
|
67
|
-
} {
|
|
68
|
-
const seed = Math.floor(Math.random() * 10000);
|
|
69
|
-
const {dbName = "db-test", ...otherOpts} = opts;
|
|
70
|
-
const url = `${getMongoUrl()}/${dbName}-${seed}`;
|
|
71
|
-
|
|
72
|
-
return {
|
|
73
|
-
id,
|
|
74
|
-
url,
|
|
75
|
-
connectionOptions: {
|
|
76
|
-
directConnection: true,
|
|
77
|
-
...otherOpts
|
|
78
|
-
} satisfies ConnectOptions
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export function getMongoConnectionsOptions(opts: ConnectionOptions = {}) {
|
|
83
|
-
return [getMongoConnectionOptions("default", opts)];
|
|
84
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import {PlatformTest} from "@tsed/platform-http/testing";
|
|
2
|
-
import {MongoClient} from "mongodb";
|
|
3
|
-
|
|
4
|
-
import {getMongoConnectionOptions, getMongoConnectionsOptions, startMongoServer, stopMongoServer} from "./ContainerUtils.js";
|
|
5
|
-
|
|
6
|
-
export class TestContainersMongo {
|
|
7
|
-
static startMongoServer = startMongoServer;
|
|
8
|
-
static stopMongoServer = stopMongoServer;
|
|
9
|
-
static getMongoConnectionsOptions = getMongoConnectionsOptions;
|
|
10
|
-
static getMongoConnectionOptions = getMongoConnectionOptions;
|
|
11
|
-
|
|
12
|
-
private static configuration: ReturnType<typeof getMongoConnectionsOptions>;
|
|
13
|
-
|
|
14
|
-
static create(options: Partial<TsED.Configuration> = {}) {
|
|
15
|
-
TestContainersMongo.configuration = getMongoConnectionsOptions();
|
|
16
|
-
|
|
17
|
-
return PlatformTest.create({
|
|
18
|
-
...options,
|
|
19
|
-
mongoose: TestContainersMongo.configuration
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
static bootstrap(mod: unknown, opts: Partial<TsED.Configuration> = {}) {
|
|
24
|
-
return () => {
|
|
25
|
-
TestContainersMongo.configuration = getMongoConnectionsOptions();
|
|
26
|
-
return PlatformTest.bootstrap(mod, {
|
|
27
|
-
mongoose: TestContainersMongo.configuration,
|
|
28
|
-
...opts
|
|
29
|
-
})();
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
static async reset(collectionName?: string) {
|
|
34
|
-
if (typeof collectionName === "string") {
|
|
35
|
-
await TestContainersMongo.cleanCollection(collectionName);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return PlatformTest.reset();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
static async cleanCollection(collectionName: string, mongoSettings = TestContainersMongo.configuration) {
|
|
42
|
-
try {
|
|
43
|
-
const client = new MongoClient(mongoSettings[0].url, {
|
|
44
|
-
directConnection: true
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
await client.connect();
|
|
48
|
-
const db = client.db();
|
|
49
|
-
await db.collection(collectionName).deleteMany({});
|
|
50
|
-
await client.close();
|
|
51
|
-
} catch (er) {
|
|
52
|
-
console.error(`Collection ${collectionName} not found. ${er.message} ${er.stack}`);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|