@tsed/testcontainers-mongo 8.0.0-alpha.1 → 8.0.0-alpha.10
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/services/ContainerUtils.js +1 -4
- package/lib/esm/services/ContainerUtils.js.map +1 -1
- package/lib/esm/services/TestContainersMongo.js +22 -13
- package/lib/esm/services/TestContainersMongo.js.map +1 -1
- package/lib/types/services/ContainerUtils.d.ts +28 -3
- package/lib/types/services/TestContainersMongo.d.ts +32 -1
- package/package.json +20 -21
- package/readme.md +42 -1
- package/lib/cjs/index.js +0 -5
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/package.json +0 -3
- package/lib/cjs/services/ContainerUtils.js +0 -63
- package/lib/cjs/services/ContainerUtils.js.map +0 -1
- package/lib/cjs/services/TestContainersMongo.js +0 -41
- package/lib/cjs/services/TestContainersMongo.js.map +0 -1
- package/lib/cjs/setup/vi.setup.js +0 -13
- package/lib/cjs/setup/vi.setup.js.map +0 -1
- package/lib/esm/package.json +0 -3
- package/lib/types-esm/index.d.ts +0 -1
- package/lib/types-esm/services/ContainerUtils.d.ts +0 -27
- package/lib/types-esm/services/TestContainersMongo.d.ts +0 -11
- package/lib/types-esm/setup/vi.setup.d.ts +0 -2
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { MongoDBContainer } from "@testcontainers/mongodb";
|
|
2
2
|
const KEY = "TEST_CONTAINER_MONGO";
|
|
3
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
4
3
|
// @ts-ignore
|
|
5
4
|
global[KEY] = null;
|
|
6
5
|
function getEnvironment(key) {
|
|
7
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
8
6
|
// @ts-ignore
|
|
9
7
|
return global[key];
|
|
10
8
|
}
|
|
11
9
|
function setEnvironment(key, environment) {
|
|
12
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
13
10
|
// @ts-ignore
|
|
14
11
|
global[key] = environment;
|
|
15
12
|
}
|
|
@@ -36,7 +33,7 @@ export async function stopMongoServer() {
|
|
|
36
33
|
export function getMongoUrl() {
|
|
37
34
|
return process.env.MONGO_URL;
|
|
38
35
|
}
|
|
39
|
-
export function getMongoConnectionOptions(id, opts = {}) {
|
|
36
|
+
export function getMongoConnectionOptions(id = "", opts = {}) {
|
|
40
37
|
const seed = Math.floor(Math.random() * 10000);
|
|
41
38
|
const { dbName = "db-test", ...otherOpts } = opts;
|
|
42
39
|
const url = `${getMongoUrl()}/${dbName}-${seed}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContainerUtils.js","sourceRoot":"","sources":["../../../src/services/ContainerUtils.ts"],"names":[],"mappings":"
|
|
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,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;AAEnB,SAAS,cAAc,CAAI,GAAW;IACpC,aAAa;IACb,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;AACrB,CAAC;AAED,SAAS,cAAc,CAAC,GAAW,EAAE,WAAoB;IACvD,aAAa;IACb,MAAM,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC;AAC5B,CAAC;AAED,SAAS,oBAAoB,CAAC,KAAK,GAAG,aAAa;IACjD,OAAO,IAAI,gBAAgB,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,CAAC;AAC7C,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,KAAc;IACnD,yBAAyB;IACzB,MAAM,SAAS,GAAG,cAAc,CAA0B,GAAG,CAAC,IAAI,CAAC,MAAM,oBAAoB,CAAC,KAAK,CAAC,CAAC,CAAC;IAEtG,cAAc,CAAC,G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ConnectionOptions, getMongoConnectionsOptions, startMongoServer, stopMongoServer } from "./ContainerUtils.js";
|
|
4
4
|
export class TestContainersMongo {
|
|
5
5
|
static { this.startMongoServer = startMongoServer; }
|
|
@@ -7,16 +7,20 @@ export class TestContainersMongo {
|
|
|
7
7
|
static { this.getMongoConnectionsOptions = getMongoConnectionsOptions; }
|
|
8
8
|
static { this.getMongoConnectionOptions = getMongoConnectionOptions; }
|
|
9
9
|
static create(options = {}) {
|
|
10
|
+
TestContainersMongo.configuration = getMongoConnectionsOptions();
|
|
10
11
|
return PlatformTest.create({
|
|
11
12
|
...options,
|
|
12
|
-
mongoose:
|
|
13
|
+
mongoose: TestContainersMongo.configuration
|
|
13
14
|
});
|
|
14
15
|
}
|
|
15
16
|
static bootstrap(mod, opts = {}) {
|
|
16
|
-
return () =>
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
return () => {
|
|
18
|
+
TestContainersMongo.configuration = getMongoConnectionsOptions();
|
|
19
|
+
return PlatformTest.bootstrap(mod, {
|
|
20
|
+
mongoose: TestContainersMongo.configuration,
|
|
21
|
+
...opts
|
|
22
|
+
})();
|
|
23
|
+
};
|
|
20
24
|
}
|
|
21
25
|
static async reset(collectionName) {
|
|
22
26
|
if (typeof collectionName === "string") {
|
|
@@ -24,14 +28,19 @@ export class TestContainersMongo {
|
|
|
24
28
|
}
|
|
25
29
|
return PlatformTest.reset();
|
|
26
30
|
}
|
|
27
|
-
static async cleanCollection(collectionName) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
static async cleanCollection(collectionName, mongoSettings = TestContainersMongo.configuration) {
|
|
32
|
+
try {
|
|
33
|
+
const client = new MongoClient(mongoSettings[0].url, {
|
|
34
|
+
directConnection: true
|
|
35
|
+
});
|
|
36
|
+
await client.connect();
|
|
37
|
+
const db = client.db();
|
|
38
|
+
await db.collection(collectionName).deleteMany({});
|
|
39
|
+
await client.close();
|
|
40
|
+
}
|
|
41
|
+
catch (er) {
|
|
42
|
+
console.error(`Collection ${collectionName} not found. ${er.message} ${er.stack}`);
|
|
33
43
|
}
|
|
34
|
-
await collections[collectionName].deleteMany({});
|
|
35
44
|
}
|
|
36
45
|
}
|
|
37
46
|
//# sourceMappingURL=TestContainersMongo.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TestContainersMongo.js","sourceRoot":"","sources":["../../../src/services/TestContainersMongo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"TestContainersMongo.js","sourceRoot":"","sources":["../../../src/services/TestContainersMongo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAC,WAAW,EAAC,MAAM,SAAS,CAAC;AAEpC,OAAO,EAAC,yBAAyB,EAAE,0BAA0B,EAAE,gBAAgB,EAAE,eAAe,EAAC,MAAM,qBAAqB,CAAC;AAE7H,MAAM,OAAO,mBAAmB;aACvB,qBAAgB,GAAG,gBAAgB,CAAC;aACpC,oBAAe,GAAG,eAAe,CAAC;aAClC,+BAA0B,GAAG,0BAA0B,CAAC;aACxD,8BAAyB,GAAG,yBAAyB,CAAC;IAI7D,MAAM,CAAC,MAAM,CAAC,UAAuC,EAAE;QACrD,mBAAmB,CAAC,aAAa,GAAG,0BAA0B,EAAE,CAAC;QAEjE,OAAO,YAAY,CAAC,MAAM,CAAC;YACzB,GAAG,OAAO;YACV,QAAQ,EAAE,mBAAmB,CAAC,aAAa;SAC5C,CAAC,CAAC;IACL,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,GAAY,EAAE,OAAoC,EAAE;QACnE,OAAO,GAAG,EAAE;YACV,mBAAmB,CAAC,aAAa,GAAG,0BAA0B,EAAE,CAAC;YACjE,OAAO,YAAY,CAAC,SAAS,CAAC,GAAG,EAAE;gBACjC,QAAQ,EAAE,mBAAmB,CAAC,aAAa;gBAC3C,GAAG,IAAI;aACR,CAAC,EAAE,CAAC;QACP,CAAC,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,cAAuB;QACxC,IAAI,OAAO,cAAc,KAAK,QAAQ,EAAE,CAAC;YACvC,MAAM,mBAAmB,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC;QAC5D,CAAC;QAED,OAAO,YAAY,CAAC,KAAK,EAAE,CAAC;IAC9B,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,cAAsB,EAAE,aAAa,GAAG,mBAAmB,CAAC,aAAa;QACpG,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,IAAI,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE;gBACnD,gBAAgB,EAAE,IAAI;aACvB,CAAC,CAAC;YAEH,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;YACvB,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,EAAE,CAAC;YACvB,MAAM,EAAE,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;YACnD,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;QACvB,CAAC;QAAC,OAAO,EAAE,EAAE,CAAC;YACZ,OAAO,CAAC,KAAK,CAAC,cAAc,cAAc,eAAe,EAAE,CAAC,OAAO,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC;QACrF,CAAC;IACH,CAAC"}
|
|
@@ -1,7 +1,32 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="mongoose/types/aggregate.js" />
|
|
3
|
+
/// <reference types="mongoose/types/callback.js" />
|
|
4
|
+
/// <reference types="mongoose/types/collection.js" />
|
|
5
|
+
/// <reference types="mongoose/types/connection.js" />
|
|
6
|
+
/// <reference types="mongoose/types/cursor.js" />
|
|
7
|
+
/// <reference types="mongoose/types/document.js" />
|
|
8
|
+
/// <reference types="mongoose/types/error.js" />
|
|
9
|
+
/// <reference types="mongoose/types/expressions.js" />
|
|
10
|
+
/// <reference types="mongoose/types/helpers.js" />
|
|
11
|
+
/// <reference types="mongoose/types/middlewares.js" />
|
|
12
|
+
/// <reference types="mongoose/types/indexes.js" />
|
|
13
|
+
/// <reference types="mongoose/types/models.js" />
|
|
14
|
+
/// <reference types="mongoose/types/mongooseoptions.js" />
|
|
15
|
+
/// <reference types="mongoose/types/pipelinestage.js" />
|
|
16
|
+
/// <reference types="mongoose/types/populate.js" />
|
|
17
|
+
/// <reference types="mongoose/types/query.js" />
|
|
18
|
+
/// <reference types="mongoose/types/schemaoptions.js" />
|
|
19
|
+
/// <reference types="mongoose/types/schematypes.js" />
|
|
20
|
+
/// <reference types="mongoose/types/session.js" />
|
|
21
|
+
/// <reference types="mongoose/types/types.js" />
|
|
22
|
+
/// <reference types="mongoose/types/utility.js" />
|
|
23
|
+
/// <reference types="mongoose/types/validation.js" />
|
|
24
|
+
/// <reference types="mongoose/types/virtuals.js" />
|
|
25
|
+
/// <reference types="mongoose/types/inferschematype.js" />
|
|
26
|
+
/// <reference types="mongoose/types/inferrawdoctype.js" />
|
|
27
|
+
import type { ConnectionOptions } from "node:tls";
|
|
2
28
|
import { StartedMongoDBContainer } from "@testcontainers/mongodb";
|
|
3
29
|
import type { ConnectOptions } from "mongoose";
|
|
4
|
-
import type { ConnectionOptions } from "node:tls";
|
|
5
30
|
declare global {
|
|
6
31
|
namespace NodeJS {
|
|
7
32
|
interface Global {
|
|
@@ -15,7 +40,7 @@ export declare function startMongoServer(image?: string): Promise<{
|
|
|
15
40
|
}>;
|
|
16
41
|
export declare function stopMongoServer(): Promise<void>;
|
|
17
42
|
export declare function getMongoUrl(): string;
|
|
18
|
-
export declare function getMongoConnectionOptions(id
|
|
43
|
+
export declare function getMongoConnectionOptions(id?: string, opts?: ConnectOptions): {
|
|
19
44
|
id: string;
|
|
20
45
|
url: string;
|
|
21
46
|
connectionOptions: ConnectOptions;
|
|
@@ -1,11 +1,42 @@
|
|
|
1
|
+
/// <reference types="mongoose/types/aggregate.js" />
|
|
2
|
+
/// <reference types="mongoose/types/callback.js" />
|
|
3
|
+
/// <reference types="mongoose/types/collection.js" />
|
|
4
|
+
/// <reference types="mongoose/types/connection.js" />
|
|
5
|
+
/// <reference types="mongoose/types/cursor.js" />
|
|
6
|
+
/// <reference types="mongoose/types/document.js" />
|
|
7
|
+
/// <reference types="mongoose/types/error.js" />
|
|
8
|
+
/// <reference types="mongoose/types/expressions.js" />
|
|
9
|
+
/// <reference types="mongoose/types/helpers.js" />
|
|
10
|
+
/// <reference types="mongoose/types/middlewares.js" />
|
|
11
|
+
/// <reference types="mongoose/types/indexes.js" />
|
|
12
|
+
/// <reference types="mongoose/types/models.js" />
|
|
13
|
+
/// <reference types="mongoose/types/mongooseoptions.js" />
|
|
14
|
+
/// <reference types="mongoose/types/pipelinestage.js" />
|
|
15
|
+
/// <reference types="mongoose/types/populate.js" />
|
|
16
|
+
/// <reference types="mongoose/types/query.js" />
|
|
17
|
+
/// <reference types="mongoose/types/schemaoptions.js" />
|
|
18
|
+
/// <reference types="mongoose/types/schematypes.js" />
|
|
19
|
+
/// <reference types="mongoose/types/session.js" />
|
|
20
|
+
/// <reference types="mongoose/types/types.js" />
|
|
21
|
+
/// <reference types="mongoose/types/utility.js" />
|
|
22
|
+
/// <reference types="mongoose/types/validation.js" />
|
|
23
|
+
/// <reference types="mongoose/types/virtuals.js" />
|
|
24
|
+
/// <reference types="mongoose" />
|
|
25
|
+
/// <reference types="mongoose/types/inferschematype.js" />
|
|
26
|
+
/// <reference types="mongoose/types/inferrawdoctype.js" />
|
|
1
27
|
import { getMongoConnectionOptions, getMongoConnectionsOptions, startMongoServer, stopMongoServer } from "./ContainerUtils.js";
|
|
2
28
|
export declare class TestContainersMongo {
|
|
3
29
|
static startMongoServer: typeof startMongoServer;
|
|
4
30
|
static stopMongoServer: typeof stopMongoServer;
|
|
5
31
|
static getMongoConnectionsOptions: typeof getMongoConnectionsOptions;
|
|
6
32
|
static getMongoConnectionOptions: typeof getMongoConnectionOptions;
|
|
33
|
+
private static configuration;
|
|
7
34
|
static create(options?: Partial<TsED.Configuration>): Promise<void>;
|
|
8
35
|
static bootstrap(mod: unknown, opts?: Partial<TsED.Configuration>): () => Promise<void>;
|
|
9
36
|
static reset(collectionName?: string): Promise<void>;
|
|
10
|
-
static cleanCollection(collectionName: string
|
|
37
|
+
static cleanCollection(collectionName: string, mongoSettings?: {
|
|
38
|
+
id: string;
|
|
39
|
+
url: string;
|
|
40
|
+
connectionOptions: import("mongoose").ConnectOptions;
|
|
41
|
+
}[]): Promise<void>;
|
|
11
42
|
}
|
package/package.json
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
{
|
|
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
|
-
"type": "
|
|
5
|
-
"version": "8.0.0-alpha.
|
|
4
|
+
"type": "module",
|
|
5
|
+
"version": "8.0.0-alpha.10",
|
|
6
6
|
"source": "./src/index.ts",
|
|
7
|
-
"main": "./lib/
|
|
7
|
+
"main": "./lib/esm/index.js",
|
|
8
8
|
"module": "./lib/esm/index.js",
|
|
9
9
|
"typings": "./lib/types/index.d.ts",
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
12
12
|
"types": "./lib/types/index.d.ts",
|
|
13
13
|
"import": "./lib/esm/index.js",
|
|
14
|
-
"
|
|
15
|
-
"default": "./lib/cjs/index.js"
|
|
14
|
+
"default": "./lib/esm/index.js"
|
|
16
15
|
},
|
|
17
16
|
"./vitest/setup": {
|
|
18
17
|
"types": "./lib/types/setup/vi.setup.d.ts",
|
|
19
18
|
"import": "./lib/esm/setup/vi.setup.js",
|
|
20
|
-
"default": "./lib/
|
|
19
|
+
"default": "./lib/esm/setup/vi.setup.js"
|
|
21
20
|
}
|
|
22
21
|
},
|
|
23
22
|
"scripts": {
|
|
@@ -25,27 +24,27 @@
|
|
|
25
24
|
"build:ts": "tsc --build tsconfig.json"
|
|
26
25
|
},
|
|
27
26
|
"dependencies": {
|
|
28
|
-
"semver": "^7.6.
|
|
29
|
-
"tslib": "2.
|
|
27
|
+
"semver": "^7.6.3",
|
|
28
|
+
"tslib": "2.7.0"
|
|
30
29
|
},
|
|
31
30
|
"devDependencies": {
|
|
32
|
-
"@testcontainers/mongodb": "
|
|
33
|
-
"@tsed/barrels": "8.0.0-alpha.
|
|
34
|
-
"@tsed/common": "8.0.0-alpha.
|
|
35
|
-
"@tsed/core": "8.0.0-alpha.
|
|
36
|
-
"@tsed/di": "8.0.0-alpha.
|
|
37
|
-
"@tsed/
|
|
38
|
-
"
|
|
39
|
-
"
|
|
31
|
+
"@testcontainers/mongodb": "^10.13.2",
|
|
32
|
+
"@tsed/barrels": "8.0.0-alpha.10",
|
|
33
|
+
"@tsed/common": "8.0.0-alpha.10",
|
|
34
|
+
"@tsed/core": "8.0.0-alpha.10",
|
|
35
|
+
"@tsed/di": "8.0.0-alpha.10",
|
|
36
|
+
"@tsed/typescript": "8.0.0-alpha.10",
|
|
37
|
+
"eslint": "9.12.0",
|
|
38
|
+
"mongodb": "6.9.0",
|
|
40
39
|
"testcontainers": ">=10.11.0",
|
|
41
|
-
"typescript": "4.
|
|
40
|
+
"typescript": "5.4.5"
|
|
42
41
|
},
|
|
43
42
|
"peerDependencies": {
|
|
44
43
|
"@testcontainers/mongodb": ">=10.11.0",
|
|
45
|
-
"@tsed/common": "8.0.0-alpha.
|
|
46
|
-
"@tsed/core": "8.0.0-alpha.
|
|
47
|
-
"@tsed/di": "8.0.0-alpha.
|
|
48
|
-
"
|
|
44
|
+
"@tsed/common": "8.0.0-alpha.10",
|
|
45
|
+
"@tsed/core": "8.0.0-alpha.10",
|
|
46
|
+
"@tsed/di": "8.0.0-alpha.10",
|
|
47
|
+
"mongodb": ">=6",
|
|
49
48
|
"testcontainers": ">=10.11.0"
|
|
50
49
|
},
|
|
51
50
|
"repository": "https://github.com/tsedio/tsed",
|
package/readme.md
CHANGED
|
@@ -91,7 +91,13 @@ export default defineConfig({
|
|
|
91
91
|
|
|
92
92
|
:::
|
|
93
93
|
|
|
94
|
-
|
|
94
|
+
## Usage
|
|
95
|
+
|
|
96
|
+
### @tsed/mongoose
|
|
97
|
+
|
|
98
|
+
#### Unit test
|
|
99
|
+
|
|
100
|
+
Use the `TestContainersMongo.create` method to start the mongo server before your test:
|
|
95
101
|
|
|
96
102
|
```ts
|
|
97
103
|
import {PlatformTest} from "@tsed/common";
|
|
@@ -148,6 +154,41 @@ describe("UserModel", () => {
|
|
|
148
154
|
});
|
|
149
155
|
```
|
|
150
156
|
|
|
157
|
+
#### Integration test
|
|
158
|
+
|
|
159
|
+
Just use the `TestContainersMongo.bootstrap` method to start the mongo server before your test:
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
beforeEach(() => TestContainersMongo.bootstrap(Server, {}));
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Mikro ORM
|
|
166
|
+
|
|
167
|
+
TestContainersMongo provides a method to get the connection options for MikroORM:
|
|
168
|
+
|
|
169
|
+
```ts
|
|
170
|
+
import {EntityManager, MikroORM} from "@mikro-orm/core";
|
|
171
|
+
import {defineConfig} from "@mikro-orm/mongodb";
|
|
172
|
+
import {PlatformTest} from "@tsed/common";
|
|
173
|
+
import {TestContainersMongo} from "@tsed/testcontainers-mongo";
|
|
174
|
+
|
|
175
|
+
beforeEach(async () => {
|
|
176
|
+
const mongoSettings = TestContainersMongo.getMongoConnectionOptions();
|
|
177
|
+
const bstrp = PlatformTest.bootstrap(Server, {
|
|
178
|
+
disableComponentScan: true,
|
|
179
|
+
imports: [MikroOrmModule],
|
|
180
|
+
mikroOrm: [
|
|
181
|
+
defineConfig({
|
|
182
|
+
clientUrl: mongoSettings.url,
|
|
183
|
+
driverOptions: mongoSettings.connectionOptions,
|
|
184
|
+
entities: [User],
|
|
185
|
+
subscribers: [UnmanagedEventSubscriber1, new UnmanagedEventSubscriber2()]
|
|
186
|
+
})
|
|
187
|
+
]
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
```
|
|
191
|
+
|
|
151
192
|
## Contributors
|
|
152
193
|
|
|
153
194
|
Please read [contributing guidelines here](https://tsed.io/contributing.html)
|
package/lib/cjs/index.js
DELETED
package/lib/cjs/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,4EAAkD"}
|
package/lib/cjs/package.json
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getMongoConnectionsOptions = exports.getMongoConnectionOptions = exports.getMongoUrl = exports.stopMongoServer = exports.startMongoServer = void 0;
|
|
4
|
-
const mongodb_1 = require("@testcontainers/mongodb");
|
|
5
|
-
const KEY = "TEST_CONTAINER_MONGO";
|
|
6
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
7
|
-
// @ts-ignore
|
|
8
|
-
global[KEY] = null;
|
|
9
|
-
function getEnvironment(key) {
|
|
10
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
11
|
-
// @ts-ignore
|
|
12
|
-
return global[key];
|
|
13
|
-
}
|
|
14
|
-
function setEnvironment(key, environment) {
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
16
|
-
// @ts-ignore
|
|
17
|
-
global[key] = environment;
|
|
18
|
-
}
|
|
19
|
-
function createMongoContainer(image = "mongo:6.0.1") {
|
|
20
|
-
return new mongodb_1.MongoDBContainer(image).start();
|
|
21
|
-
}
|
|
22
|
-
async function startMongoServer(image) {
|
|
23
|
-
// await stopMockServer()
|
|
24
|
-
const container = getEnvironment(KEY) || (await createMongoContainer(image));
|
|
25
|
-
setEnvironment(KEY, container);
|
|
26
|
-
process.env.MONGO_URL = container.getConnectionString();
|
|
27
|
-
return {
|
|
28
|
-
container,
|
|
29
|
-
url: process.env.MONGO_URL
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
exports.startMongoServer = startMongoServer;
|
|
33
|
-
async function stopMongoServer() {
|
|
34
|
-
const container = getEnvironment(KEY);
|
|
35
|
-
process.stdout.write("Stopping mongo server\n");
|
|
36
|
-
if (container) {
|
|
37
|
-
await container.stop();
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
exports.stopMongoServer = stopMongoServer;
|
|
41
|
-
function getMongoUrl() {
|
|
42
|
-
return process.env.MONGO_URL;
|
|
43
|
-
}
|
|
44
|
-
exports.getMongoUrl = getMongoUrl;
|
|
45
|
-
function getMongoConnectionOptions(id, opts = {}) {
|
|
46
|
-
const seed = Math.floor(Math.random() * 10000);
|
|
47
|
-
const { dbName = "db-test", ...otherOpts } = opts;
|
|
48
|
-
const url = `${getMongoUrl()}/${dbName}-${seed}`;
|
|
49
|
-
return {
|
|
50
|
-
id,
|
|
51
|
-
url,
|
|
52
|
-
connectionOptions: {
|
|
53
|
-
directConnection: true,
|
|
54
|
-
...otherOpts
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
exports.getMongoConnectionOptions = getMongoConnectionOptions;
|
|
59
|
-
function getMongoConnectionsOptions(opts = {}) {
|
|
60
|
-
return [getMongoConnectionOptions("default", opts)];
|
|
61
|
-
}
|
|
62
|
-
exports.getMongoConnectionsOptions = getMongoConnectionsOptions;
|
|
63
|
-
//# sourceMappingURL=ContainerUtils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ContainerUtils.js","sourceRoot":"","sources":["../../../src/services/ContainerUtils.ts"],"names":[],"mappings":";;;AAAA,qDAAkF;AAalF,MAAM,GAAG,GAAG,sBAAsB,CAAC;AAEnC,6DAA6D;AAC7D,a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AK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC;IAC/C,MAAM,EAAC,MAAM,GAAG,SAAS,EAAE,GAAG,SAAS,EAAC,GAAG,IAAI,CAAC;IAChD,MAAM,GAAG,GAAG,GAAG,WAAW,EAAE,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;IAEjD,OAAO;QACL,EAAE;QACF,GAAG;QACH,iBAAiB,EAAE;YACjB,gBAAgB,EAAE,IAAI;YACtB,GAAG,SAAS;SACY;KAC3B,CAAC;AACJ,CAAC;AApBD,8DAoBC;AAED,SAAgB,0BAA0B,CAAC,OAA0B,EAAE;IACrE,OAAO,CAAC,yBAAyB,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC;AACtD,CAAC;AAFD,gEAEC"}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TestContainersMongo = void 0;
|
|
4
|
-
const common_1 = require("@tsed/common");
|
|
5
|
-
const mongoose_1 = require("@tsed/mongoose");
|
|
6
|
-
const ContainerUtils_js_1 = require("./ContainerUtils.js");
|
|
7
|
-
class TestContainersMongo {
|
|
8
|
-
static { this.startMongoServer = ContainerUtils_js_1.startMongoServer; }
|
|
9
|
-
static { this.stopMongoServer = ContainerUtils_js_1.stopMongoServer; }
|
|
10
|
-
static { this.getMongoConnectionsOptions = ContainerUtils_js_1.getMongoConnectionsOptions; }
|
|
11
|
-
static { this.getMongoConnectionOptions = ContainerUtils_js_1.getMongoConnectionOptions; }
|
|
12
|
-
static create(options = {}) {
|
|
13
|
-
return common_1.PlatformTest.create({
|
|
14
|
-
...options,
|
|
15
|
-
mongoose: (0, ContainerUtils_js_1.getMongoConnectionsOptions)()
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
static bootstrap(mod, opts = {}) {
|
|
19
|
-
return () => common_1.PlatformTest.bootstrap(mod, {
|
|
20
|
-
mongoose: (0, ContainerUtils_js_1.getMongoConnectionsOptions)(),
|
|
21
|
-
...opts
|
|
22
|
-
})();
|
|
23
|
-
}
|
|
24
|
-
static async reset(collectionName) {
|
|
25
|
-
if (typeof collectionName === "string") {
|
|
26
|
-
await TestContainersMongo.cleanCollection(collectionName);
|
|
27
|
-
}
|
|
28
|
-
return common_1.PlatformTest.reset();
|
|
29
|
-
}
|
|
30
|
-
static async cleanCollection(collectionName) {
|
|
31
|
-
const service = common_1.PlatformTest.injector.get(mongoose_1.MongooseService);
|
|
32
|
-
const { collections } = service.get("default");
|
|
33
|
-
if (!collections[collectionName]) {
|
|
34
|
-
console.error(`Collection ${collectionName} not found. Here available collection names: ${Object.keys(collections)}`);
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
await collections[collectionName].deleteMany({});
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
exports.TestContainersMongo = TestContainersMongo;
|
|
41
|
-
//# sourceMappingURL=TestContainersMongo.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TestContainersMongo.js","sourceRoot":"","sources":["../../../src/services/TestContainersMongo.ts"],"names":[],"mappings":";;;AAAA,yCAA0C;AAC1C,6CAA+C;AAC/C,2DAA6H;AAE7H,MAAa,mBAAmB;aACvB,qBAAgB,GAAG,oCAAgB,CAAC;aACpC,oBAAe,GAAG,mCAAe,CAAC;aAClC,+BAA0B,GAAG,8CAA0B,CAAC;aACxD,8BAAyB,GAAG,6CAAyB,CAAC;IAE7D,MAAM,CAAC,MAAM,CAAC,UAAuC,EAAE;QACrD,OAAO,qBAAY,CAAC,MAAM,CAAC;YACzB,GAAG,OAAO;YACV,QAAQ,EAAE,IAAA,8CAA0B,GAAE;SACvC,CAAC,CAAC;IACL,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,GAAY,EAAE,OAAoC,EAAE;QACnE,OAAO,GAAG,EAAE,CACV,qBAAY,CAAC,SAAS,CAAC,GAAG,EAAE;YAC1B,QAAQ,EAAE,IAAA,8CAA0B,GAAE;YACtC,GAAG,IAAI;SACR,CAAC,EAAE,CAAC;IACT,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,cAAuB;QACxC,IAAI,OAAO,cAAc,KAAK,QAAQ,EAAE;YACtC,MAAM,mBAAmB,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC;SAC3D;QAED,OAAO,qBAAY,CAAC,KAAK,EAAE,CAAC;IAC9B,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,cAAsB;QACjD,MAAM,OAAO,GAAG,qBAAY,CAAC,QAAQ,CAAC,GAAG,CAAkB,0BAAe,CAAE,CAAC;QAE7E,MAAM,EAAC,WAAW,EAAC,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,CAAE,CAAC;QAE9C,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,EAAE;YAChC,OAAO,CAAC,KAAK,CAAC,cAAc,cAAc,gDAAgD,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;YACtH,OAAO;SACR;QAED,MAAM,WAAW,CAAC,cAAc,CAAC,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IACnD,CAAC;;AAxCH,kDAyCC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.teardown = exports.setup = void 0;
|
|
4
|
-
const ContainerUtils_js_1 = require("../services/ContainerUtils.js");
|
|
5
|
-
async function setup() {
|
|
6
|
-
await (0, ContainerUtils_js_1.startMongoServer)();
|
|
7
|
-
}
|
|
8
|
-
exports.setup = setup;
|
|
9
|
-
async function teardown() {
|
|
10
|
-
await (0, ContainerUtils_js_1.stopMongoServer)();
|
|
11
|
-
}
|
|
12
|
-
exports.teardown = teardown;
|
|
13
|
-
//# sourceMappingURL=vi.setup.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vi.setup.js","sourceRoot":"","sources":["../../../src/setup/vi.setup.ts"],"names":[],"mappings":";;;AAAA,qEAAgF;AAEzE,KAAK,UAAU,KAAK;IACzB,MAAM,IAAA,oCAAgB,GAAE,CAAC;AAC3B,CAAC;AAFD,sBAEC;AAEM,KAAK,UAAU,QAAQ;IAC5B,MAAM,IAAA,mCAAe,GAAE,CAAC;AAC1B,CAAC;AAFD,4BAEC"}
|
package/lib/esm/package.json
DELETED
package/lib/types-esm/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./services/TestContainersMongo.js";
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { StartedMongoDBContainer } from "@testcontainers/mongodb";
|
|
3
|
-
import type { ConnectOptions } from "mongoose";
|
|
4
|
-
import type { ConnectionOptions } from "node:tls";
|
|
5
|
-
declare global {
|
|
6
|
-
namespace NodeJS {
|
|
7
|
-
interface Global {
|
|
8
|
-
TEST_CONTAINER_MONGO: StartedMongoDBContainer | null;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
export declare function startMongoServer(image?: string): Promise<{
|
|
13
|
-
container: StartedMongoDBContainer;
|
|
14
|
-
url: string;
|
|
15
|
-
}>;
|
|
16
|
-
export declare function stopMongoServer(): Promise<void>;
|
|
17
|
-
export declare function getMongoUrl(): string;
|
|
18
|
-
export declare function getMongoConnectionOptions(id: string, opts?: ConnectOptions): {
|
|
19
|
-
id: string;
|
|
20
|
-
url: string;
|
|
21
|
-
connectionOptions: ConnectOptions;
|
|
22
|
-
};
|
|
23
|
-
export declare function getMongoConnectionsOptions(opts?: ConnectionOptions): {
|
|
24
|
-
id: string;
|
|
25
|
-
url: string;
|
|
26
|
-
connectionOptions: ConnectOptions;
|
|
27
|
-
}[];
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { getMongoConnectionOptions, getMongoConnectionsOptions, startMongoServer, stopMongoServer } from "./ContainerUtils.js";
|
|
2
|
-
export declare class TestContainersMongo {
|
|
3
|
-
static startMongoServer: typeof startMongoServer;
|
|
4
|
-
static stopMongoServer: typeof stopMongoServer;
|
|
5
|
-
static getMongoConnectionsOptions: typeof getMongoConnectionsOptions;
|
|
6
|
-
static getMongoConnectionOptions: typeof getMongoConnectionOptions;
|
|
7
|
-
static create(options?: Partial<TsED.Configuration>): Promise<void>;
|
|
8
|
-
static bootstrap(mod: unknown, opts?: Partial<TsED.Configuration>): () => Promise<void>;
|
|
9
|
-
static reset(collectionName?: string): Promise<void>;
|
|
10
|
-
static cleanCollection(collectionName: string): Promise<void>;
|
|
11
|
-
}
|