@terreno/test 0.23.1 → 0.25.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/biome.jsonc +20 -0
- package/dist/cache/mongoTestCache.js +3 -3
- package/dist/index.d.ts +10 -10
- package/dist/index.js +18 -18
- package/dist/mongo/connection.test.js +1 -1
- package/dist/preload/registerBackendPreload.js +1 -1
- package/dist/transaction/testTransaction.js +6 -5
- package/dist/utils/waitForDocuments.d.ts +1 -1
- package/package.json +1 -1
- package/src/cache/mongoTestCache.ts +3 -3
- package/src/http/authAsUser.test.ts +3 -3
- package/src/index.ts +29 -27
- package/src/mongo/connection.test.ts +1 -2
- package/src/mongo/connection.ts +2 -1
- package/src/preload/registerBackendPreload.ts +6 -6
- package/src/transaction/testTransaction.ts +4 -3
- package/src/utils/waitForDocuments.ts +1 -5
package/biome.jsonc
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"root": true,
|
|
3
|
+
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
|
|
4
|
+
"extends": ["../biome.jsonc"],
|
|
5
|
+
"files": {
|
|
6
|
+
"includes": [
|
|
7
|
+
"package.json",
|
|
8
|
+
"src/**/*.ts",
|
|
9
|
+
"src/**/*.tsx",
|
|
10
|
+
"!!**/node_modules",
|
|
11
|
+
"!!node_modules",
|
|
12
|
+
"!!**/dist",
|
|
13
|
+
"!!dist",
|
|
14
|
+
"!!**/build",
|
|
15
|
+
"!!build",
|
|
16
|
+
"!!**/coverage",
|
|
17
|
+
"!!coverage"
|
|
18
|
+
]
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -116,8 +116,8 @@ var mongoose_1 = __importDefault(require("mongoose"));
|
|
|
116
116
|
var testLogger_1 = require("../logging/testLogger");
|
|
117
117
|
var connection_1 = require("../mongo/connection");
|
|
118
118
|
var mongoServer_1 = require("../mongo/mongoServer");
|
|
119
|
-
var ensureAllIndexes_1 = require("../utils/ensureAllIndexes");
|
|
120
119
|
var testTransaction_1 = require("../transaction/testTransaction");
|
|
120
|
+
var ensureAllIndexes_1 = require("../utils/ensureAllIndexes");
|
|
121
121
|
var HASH_FILE = "source-hash.txt";
|
|
122
122
|
var CACHED_DATA_FILE = "cached-data.json";
|
|
123
123
|
var CACHED_COLLECTIONS_FILE = "cached-collections.json";
|
|
@@ -348,8 +348,8 @@ var loadTestDataIntoDb = function (cachedCollections) { return __awaiter(void 0,
|
|
|
348
348
|
continue;
|
|
349
349
|
}
|
|
350
350
|
convertedDocs = docs.map(function (doc) { return convertValue(doc); });
|
|
351
|
-
restorePromises.push(mongoose_1.default.connection
|
|
352
|
-
.collection(collectionName)
|
|
351
|
+
restorePromises.push(mongoose_1.default.connection
|
|
352
|
+
.db.collection(collectionName)
|
|
353
353
|
.insertMany(convertedDocs, { ordered: false }));
|
|
354
354
|
}
|
|
355
355
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { createMongoTestCache, type MongoTestCacheController, type MongoTestCacheOptions, } from "./cache/mongoTestCache";
|
|
2
2
|
export { setTerrenoTestEnv, type TerrenoTestEnvOptions } from "./env/setTerrenoTestEnv";
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export { abortTestTransaction, getTestSession, installTransactionPatches, resetTestSessionAfterReconnect, startTestTransaction, } from "./transaction/testTransaction";
|
|
7
|
-
export { createLogSilencer, registerLogSilencing, type SilenceLogsController, type SilenceLogsOptions } from "./logging/silenceLogs";
|
|
3
|
+
export { type AuthAsUserOptions, type AuthUserCredentials, authAsUser } from "./http/authAsUser";
|
|
4
|
+
export { type GetBaseServerOptions, getBaseServer } from "./http/getBaseServer";
|
|
5
|
+
export { createLogSilencer, registerLogSilencing, type SilenceLogsController, type SilenceLogsOptions, } from "./logging/silenceLogs";
|
|
8
6
|
export { registerSentryBunMock } from "./mocks/sentryBun";
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
7
|
+
export { buildDatabaseUri, DEFAULT_LOCAL_MONGO_URI, type EnsureTestMongooseConnectedOptions, ensureTestMongooseConnected, type SplitMongoUriResult, splitMongoUri, } from "./mongo/connection";
|
|
8
|
+
export { ensureMongoBinary } from "./mongo/ensureMongoBinary";
|
|
9
|
+
export { getMongoServerUri, initializeModels, type MemoryMongoHandle, type MongoServerOptions, restartMongoServer, startMongoServer, stopMongoServer, waitForDatabaseReady, } from "./mongo/mongoServer";
|
|
10
|
+
export { type BackendPreloadOptions, registerBackendPreload, registerSimpleMongoPreload, type SimpleMongoPreloadOptions, } from "./preload/registerBackendPreload";
|
|
11
|
+
export { abortTestTransaction, getTestSession, installTransactionPatches, resetTestSessionAfterReconnect, startTestTransaction, } from "./transaction/testTransaction";
|
|
11
12
|
export { ensureAllIndexes } from "./utils/ensureAllIndexes";
|
|
12
13
|
export { timeout } from "./utils/timeout";
|
|
13
|
-
export { waitForDocument, waitForDocuments,
|
|
14
|
-
export { registerBackendPreload, registerSimpleMongoPreload, type BackendPreloadOptions, type SimpleMongoPreloadOptions, } from "./preload/registerBackendPreload";
|
|
14
|
+
export { type WaitForDocumentsOptions, waitForDocument, waitForDocuments, } from "./utils/waitForDocuments";
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "
|
|
3
|
+
exports.waitForDocuments = exports.waitForDocument = exports.timeout = exports.ensureAllIndexes = exports.startTestTransaction = exports.resetTestSessionAfterReconnect = exports.installTransactionPatches = exports.getTestSession = exports.abortTestTransaction = exports.registerSimpleMongoPreload = exports.registerBackendPreload = exports.waitForDatabaseReady = exports.stopMongoServer = exports.startMongoServer = exports.restartMongoServer = exports.initializeModels = exports.getMongoServerUri = exports.ensureMongoBinary = exports.splitMongoUri = exports.ensureTestMongooseConnected = exports.DEFAULT_LOCAL_MONGO_URI = exports.buildDatabaseUri = exports.registerSentryBunMock = exports.registerLogSilencing = exports.createLogSilencer = exports.getBaseServer = exports.authAsUser = exports.setTerrenoTestEnv = exports.createMongoTestCache = void 0;
|
|
4
|
+
var mongoTestCache_1 = require("./cache/mongoTestCache");
|
|
5
|
+
Object.defineProperty(exports, "createMongoTestCache", { enumerable: true, get: function () { return mongoTestCache_1.createMongoTestCache; } });
|
|
6
6
|
var setTerrenoTestEnv_1 = require("./env/setTerrenoTestEnv");
|
|
7
7
|
Object.defineProperty(exports, "setTerrenoTestEnv", { enumerable: true, get: function () { return setTerrenoTestEnv_1.setTerrenoTestEnv; } });
|
|
8
|
+
var authAsUser_1 = require("./http/authAsUser");
|
|
9
|
+
Object.defineProperty(exports, "authAsUser", { enumerable: true, get: function () { return authAsUser_1.authAsUser; } });
|
|
10
|
+
var getBaseServer_1 = require("./http/getBaseServer");
|
|
11
|
+
Object.defineProperty(exports, "getBaseServer", { enumerable: true, get: function () { return getBaseServer_1.getBaseServer; } });
|
|
12
|
+
var silenceLogs_1 = require("./logging/silenceLogs");
|
|
13
|
+
Object.defineProperty(exports, "createLogSilencer", { enumerable: true, get: function () { return silenceLogs_1.createLogSilencer; } });
|
|
14
|
+
Object.defineProperty(exports, "registerLogSilencing", { enumerable: true, get: function () { return silenceLogs_1.registerLogSilencing; } });
|
|
15
|
+
var sentryBun_1 = require("./mocks/sentryBun");
|
|
16
|
+
Object.defineProperty(exports, "registerSentryBunMock", { enumerable: true, get: function () { return sentryBun_1.registerSentryBunMock; } });
|
|
8
17
|
var connection_1 = require("./mongo/connection");
|
|
9
|
-
Object.defineProperty(exports, "DEFAULT_LOCAL_MONGO_URI", { enumerable: true, get: function () { return connection_1.DEFAULT_LOCAL_MONGO_URI; } });
|
|
10
18
|
Object.defineProperty(exports, "buildDatabaseUri", { enumerable: true, get: function () { return connection_1.buildDatabaseUri; } });
|
|
19
|
+
Object.defineProperty(exports, "DEFAULT_LOCAL_MONGO_URI", { enumerable: true, get: function () { return connection_1.DEFAULT_LOCAL_MONGO_URI; } });
|
|
11
20
|
Object.defineProperty(exports, "ensureTestMongooseConnected", { enumerable: true, get: function () { return connection_1.ensureTestMongooseConnected; } });
|
|
12
21
|
Object.defineProperty(exports, "splitMongoUri", { enumerable: true, get: function () { return connection_1.splitMongoUri; } });
|
|
22
|
+
var ensureMongoBinary_1 = require("./mongo/ensureMongoBinary");
|
|
23
|
+
Object.defineProperty(exports, "ensureMongoBinary", { enumerable: true, get: function () { return ensureMongoBinary_1.ensureMongoBinary; } });
|
|
13
24
|
var mongoServer_1 = require("./mongo/mongoServer");
|
|
14
25
|
Object.defineProperty(exports, "getMongoServerUri", { enumerable: true, get: function () { return mongoServer_1.getMongoServerUri; } });
|
|
15
26
|
Object.defineProperty(exports, "initializeModels", { enumerable: true, get: function () { return mongoServer_1.initializeModels; } });
|
|
@@ -17,23 +28,15 @@ Object.defineProperty(exports, "restartMongoServer", { enumerable: true, get: fu
|
|
|
17
28
|
Object.defineProperty(exports, "startMongoServer", { enumerable: true, get: function () { return mongoServer_1.startMongoServer; } });
|
|
18
29
|
Object.defineProperty(exports, "stopMongoServer", { enumerable: true, get: function () { return mongoServer_1.stopMongoServer; } });
|
|
19
30
|
Object.defineProperty(exports, "waitForDatabaseReady", { enumerable: true, get: function () { return mongoServer_1.waitForDatabaseReady; } });
|
|
20
|
-
var
|
|
21
|
-
Object.defineProperty(exports, "
|
|
31
|
+
var registerBackendPreload_1 = require("./preload/registerBackendPreload");
|
|
32
|
+
Object.defineProperty(exports, "registerBackendPreload", { enumerable: true, get: function () { return registerBackendPreload_1.registerBackendPreload; } });
|
|
33
|
+
Object.defineProperty(exports, "registerSimpleMongoPreload", { enumerable: true, get: function () { return registerBackendPreload_1.registerSimpleMongoPreload; } });
|
|
22
34
|
var testTransaction_1 = require("./transaction/testTransaction");
|
|
23
35
|
Object.defineProperty(exports, "abortTestTransaction", { enumerable: true, get: function () { return testTransaction_1.abortTestTransaction; } });
|
|
24
36
|
Object.defineProperty(exports, "getTestSession", { enumerable: true, get: function () { return testTransaction_1.getTestSession; } });
|
|
25
37
|
Object.defineProperty(exports, "installTransactionPatches", { enumerable: true, get: function () { return testTransaction_1.installTransactionPatches; } });
|
|
26
38
|
Object.defineProperty(exports, "resetTestSessionAfterReconnect", { enumerable: true, get: function () { return testTransaction_1.resetTestSessionAfterReconnect; } });
|
|
27
39
|
Object.defineProperty(exports, "startTestTransaction", { enumerable: true, get: function () { return testTransaction_1.startTestTransaction; } });
|
|
28
|
-
var silenceLogs_1 = require("./logging/silenceLogs");
|
|
29
|
-
Object.defineProperty(exports, "createLogSilencer", { enumerable: true, get: function () { return silenceLogs_1.createLogSilencer; } });
|
|
30
|
-
Object.defineProperty(exports, "registerLogSilencing", { enumerable: true, get: function () { return silenceLogs_1.registerLogSilencing; } });
|
|
31
|
-
var sentryBun_1 = require("./mocks/sentryBun");
|
|
32
|
-
Object.defineProperty(exports, "registerSentryBunMock", { enumerable: true, get: function () { return sentryBun_1.registerSentryBunMock; } });
|
|
33
|
-
var authAsUser_1 = require("./http/authAsUser");
|
|
34
|
-
Object.defineProperty(exports, "authAsUser", { enumerable: true, get: function () { return authAsUser_1.authAsUser; } });
|
|
35
|
-
var getBaseServer_1 = require("./http/getBaseServer");
|
|
36
|
-
Object.defineProperty(exports, "getBaseServer", { enumerable: true, get: function () { return getBaseServer_1.getBaseServer; } });
|
|
37
40
|
var ensureAllIndexes_1 = require("./utils/ensureAllIndexes");
|
|
38
41
|
Object.defineProperty(exports, "ensureAllIndexes", { enumerable: true, get: function () { return ensureAllIndexes_1.ensureAllIndexes; } });
|
|
39
42
|
var timeout_1 = require("./utils/timeout");
|
|
@@ -41,6 +44,3 @@ Object.defineProperty(exports, "timeout", { enumerable: true, get: function () {
|
|
|
41
44
|
var waitForDocuments_1 = require("./utils/waitForDocuments");
|
|
42
45
|
Object.defineProperty(exports, "waitForDocument", { enumerable: true, get: function () { return waitForDocuments_1.waitForDocument; } });
|
|
43
46
|
Object.defineProperty(exports, "waitForDocuments", { enumerable: true, get: function () { return waitForDocuments_1.waitForDocuments; } });
|
|
44
|
-
var registerBackendPreload_1 = require("./preload/registerBackendPreload");
|
|
45
|
-
Object.defineProperty(exports, "registerBackendPreload", { enumerable: true, get: function () { return registerBackendPreload_1.registerBackendPreload; } });
|
|
46
|
-
Object.defineProperty(exports, "registerSimpleMongoPreload", { enumerable: true, get: function () { return registerBackendPreload_1.registerSimpleMongoPreload; } });
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var bun_test_1 = require("bun:test");
|
|
4
|
-
var connection_1 = require("./connection");
|
|
5
4
|
var setTerrenoTestEnv_1 = require("../env/setTerrenoTestEnv");
|
|
5
|
+
var connection_1 = require("./connection");
|
|
6
6
|
(0, bun_test_1.describe)("mongo connection helpers", function () {
|
|
7
7
|
(0, bun_test_1.it)("splitMongoUri separates base URI and query options", function () {
|
|
8
8
|
var result = (0, connection_1.splitMongoUri)("mongodb://127.0.0.1/mydb?retryWrites=true");
|
|
@@ -97,9 +97,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
97
97
|
exports.registerSimpleMongoPreload = exports.registerBackendPreload = void 0;
|
|
98
98
|
var bun_test_1 = require("bun:test");
|
|
99
99
|
var mongoose_1 = __importDefault(require("mongoose"));
|
|
100
|
-
var testLogger_1 = require("../logging/testLogger");
|
|
101
100
|
var setTerrenoTestEnv_1 = require("../env/setTerrenoTestEnv");
|
|
102
101
|
var silenceLogs_1 = require("../logging/silenceLogs");
|
|
102
|
+
var testLogger_1 = require("../logging/testLogger");
|
|
103
103
|
var sentryBun_1 = require("../mocks/sentryBun");
|
|
104
104
|
var mongoServer_1 = require("../mongo/mongoServer");
|
|
105
105
|
var testTransaction_1 = require("../transaction/testTransaction");
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// biome-ignore-all lint/suspicious/noExplicitAny: Mongoose prototype patches require dynamic signatures
|
|
2
3
|
/**
|
|
3
4
|
* Transaction-based test isolation for MongoDB.
|
|
4
5
|
*
|
|
@@ -126,7 +127,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
126
127
|
};
|
|
127
128
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
128
129
|
exports.installTransactionPatches = exports.resetTestSessionAfterReconnect = exports.abortTestTransaction = exports.startTestTransaction = exports.getTestSession = void 0;
|
|
129
|
-
var
|
|
130
|
+
var node_async_hooks_1 = require("node:async_hooks");
|
|
130
131
|
var mongoose_1 = __importDefault(require("mongoose"));
|
|
131
132
|
var currentTestSession = null;
|
|
132
133
|
var patchesInstalled = false;
|
|
@@ -137,7 +138,7 @@ var patchesInstalled = false;
|
|
|
137
138
|
* Tracks whether the current async context is already inside a serialized
|
|
138
139
|
* DB operation. When true, nested operations skip the mutex to avoid deadlocks.
|
|
139
140
|
*/
|
|
140
|
-
var serializationContext = new
|
|
141
|
+
var serializationContext = new node_async_hooks_1.AsyncLocalStorage();
|
|
141
142
|
/**
|
|
142
143
|
* Async mutex that serializes access to the MongoDB session.
|
|
143
144
|
* Only one DB operation can be in-flight at a time when a test session is active.
|
|
@@ -618,13 +619,13 @@ var installTransactionPatches = function () {
|
|
|
618
619
|
var _this = this;
|
|
619
620
|
return __generator(this, function (_a) {
|
|
620
621
|
if (currentTestSession) {
|
|
621
|
-
return [2 /*return*/, __assign(__assign({}, currentTestSession), {
|
|
622
|
+
return [2 /*return*/, __assign(__assign({}, currentTestSession), { abortTransaction: function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
622
623
|
return [2 /*return*/];
|
|
623
|
-
}); }); },
|
|
624
|
+
}); }); }, commitTransaction: function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
624
625
|
return [2 /*return*/];
|
|
625
626
|
}); }); }, endSession: function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
626
627
|
return [2 /*return*/];
|
|
627
|
-
}); }); }, id: currentTestSession.id, inTransaction: function () { var _a; return (_a = currentTestSession === null || currentTestSession === void 0 ? void 0 : currentTestSession.inTransaction()) !== null && _a !== void 0 ? _a : false; } })];
|
|
628
|
+
}); }); }, id: currentTestSession.id, inTransaction: function () { var _a; return (_a = currentTestSession === null || currentTestSession === void 0 ? void 0 : currentTestSession.inTransaction()) !== null && _a !== void 0 ? _a : false; }, startTransaction: function () { } })];
|
|
628
629
|
}
|
|
629
630
|
return [2 /*return*/, originalStartSession.call(this, options)];
|
|
630
631
|
});
|
|
@@ -8,6 +8,6 @@ export interface WaitForDocumentsOptions {
|
|
|
8
8
|
* Polls until at least `count` documents match the query.
|
|
9
9
|
* Useful when writes are asynchronous (audit logs, webhooks, etc.).
|
|
10
10
|
*/
|
|
11
|
-
export declare const waitForDocuments: <T>(model: Model<T>, query: FilterQuery<T>, count?: number, { timeoutMs, intervalMs, sort
|
|
11
|
+
export declare const waitForDocuments: <T>(model: Model<T>, query: FilterQuery<T>, count?: number, { timeoutMs, intervalMs, sort }?: WaitForDocumentsOptions) => Promise<T[]>;
|
|
12
12
|
/** Polls until a single document matches the query. */
|
|
13
13
|
export declare const waitForDocument: <T>(model: Model<T>, query: FilterQuery<T>, options?: WaitForDocumentsOptions) => Promise<T>;
|
package/package.json
CHANGED
|
@@ -7,8 +7,8 @@ import {testLogger} from "../logging/testLogger";
|
|
|
7
7
|
|
|
8
8
|
import {buildDatabaseUri} from "../mongo/connection";
|
|
9
9
|
import {restartMongoServer, startMongoServer, waitForDatabaseReady} from "../mongo/mongoServer";
|
|
10
|
-
import {ensureAllIndexes} from "../utils/ensureAllIndexes";
|
|
11
10
|
import {resetTestSessionAfterReconnect} from "../transaction/testTransaction";
|
|
11
|
+
import {ensureAllIndexes} from "../utils/ensureAllIndexes";
|
|
12
12
|
|
|
13
13
|
const HASH_FILE = "source-hash.txt";
|
|
14
14
|
const CACHED_DATA_FILE = "cached-data.json";
|
|
@@ -192,8 +192,8 @@ const loadTestDataIntoDb = async (cachedCollections: Record<string, unknown[]>):
|
|
|
192
192
|
}
|
|
193
193
|
const convertedDocs = docs.map((doc) => convertValue(doc));
|
|
194
194
|
restorePromises.push(
|
|
195
|
-
mongoose.connection
|
|
196
|
-
.collection(collectionName)
|
|
195
|
+
mongoose.connection
|
|
196
|
+
.db!.collection(collectionName)
|
|
197
197
|
.insertMany(convertedDocs as Record<string, unknown>[], {ordered: false})
|
|
198
198
|
);
|
|
199
199
|
}
|
|
@@ -33,8 +33,8 @@ describe("authAsUser", () => {
|
|
|
33
33
|
res.json({data: {}});
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
await expect(
|
|
37
|
-
authAsUser
|
|
38
|
-
)
|
|
36
|
+
await expect(authAsUser(app, {email: "user@test.com", password: "secret"})).rejects.toThrow(
|
|
37
|
+
'authAsUser: expected string token at response path "data.token"'
|
|
38
|
+
);
|
|
39
39
|
});
|
|
40
40
|
});
|
package/src/index.ts
CHANGED
|
@@ -1,31 +1,44 @@
|
|
|
1
1
|
export {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
createMongoTestCache,
|
|
3
|
+
type MongoTestCacheController,
|
|
4
|
+
type MongoTestCacheOptions,
|
|
5
|
+
} from "./cache/mongoTestCache";
|
|
4
6
|
|
|
5
7
|
export {setTerrenoTestEnv, type TerrenoTestEnvOptions} from "./env/setTerrenoTestEnv";
|
|
6
|
-
|
|
8
|
+
export {type AuthAsUserOptions, type AuthUserCredentials, authAsUser} from "./http/authAsUser";
|
|
9
|
+
export {type GetBaseServerOptions, getBaseServer} from "./http/getBaseServer";
|
|
10
|
+
export {
|
|
11
|
+
createLogSilencer,
|
|
12
|
+
registerLogSilencing,
|
|
13
|
+
type SilenceLogsController,
|
|
14
|
+
type SilenceLogsOptions,
|
|
15
|
+
} from "./logging/silenceLogs";
|
|
16
|
+
export {registerSentryBunMock} from "./mocks/sentryBun";
|
|
7
17
|
export {
|
|
8
|
-
DEFAULT_LOCAL_MONGO_URI,
|
|
9
18
|
buildDatabaseUri,
|
|
10
|
-
|
|
11
|
-
splitMongoUri,
|
|
19
|
+
DEFAULT_LOCAL_MONGO_URI,
|
|
12
20
|
type EnsureTestMongooseConnectedOptions,
|
|
21
|
+
ensureTestMongooseConnected,
|
|
13
22
|
type SplitMongoUriResult,
|
|
23
|
+
splitMongoUri,
|
|
14
24
|
} from "./mongo/connection";
|
|
15
|
-
|
|
25
|
+
export {ensureMongoBinary} from "./mongo/ensureMongoBinary";
|
|
16
26
|
export {
|
|
17
27
|
getMongoServerUri,
|
|
18
28
|
initializeModels,
|
|
29
|
+
type MemoryMongoHandle,
|
|
30
|
+
type MongoServerOptions,
|
|
19
31
|
restartMongoServer,
|
|
20
32
|
startMongoServer,
|
|
21
33
|
stopMongoServer,
|
|
22
34
|
waitForDatabaseReady,
|
|
23
|
-
type MemoryMongoHandle,
|
|
24
|
-
type MongoServerOptions,
|
|
25
35
|
} from "./mongo/mongoServer";
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
36
|
+
export {
|
|
37
|
+
type BackendPreloadOptions,
|
|
38
|
+
registerBackendPreload,
|
|
39
|
+
registerSimpleMongoPreload,
|
|
40
|
+
type SimpleMongoPreloadOptions,
|
|
41
|
+
} from "./preload/registerBackendPreload";
|
|
29
42
|
export {
|
|
30
43
|
abortTestTransaction,
|
|
31
44
|
getTestSession,
|
|
@@ -33,21 +46,10 @@ export {
|
|
|
33
46
|
resetTestSessionAfterReconnect,
|
|
34
47
|
startTestTransaction,
|
|
35
48
|
} from "./transaction/testTransaction";
|
|
36
|
-
|
|
37
|
-
export {createLogSilencer, registerLogSilencing, type SilenceLogsController, type SilenceLogsOptions} from "./logging/silenceLogs";
|
|
38
|
-
|
|
39
|
-
export {registerSentryBunMock} from "./mocks/sentryBun";
|
|
40
|
-
|
|
41
|
-
export {authAsUser, type AuthAsUserOptions, type AuthUserCredentials} from "./http/authAsUser";
|
|
42
|
-
export {getBaseServer, type GetBaseServerOptions} from "./http/getBaseServer";
|
|
43
|
-
|
|
44
49
|
export {ensureAllIndexes} from "./utils/ensureAllIndexes";
|
|
45
50
|
export {timeout} from "./utils/timeout";
|
|
46
|
-
export {waitForDocument, waitForDocuments, type WaitForDocumentsOptions} from "./utils/waitForDocuments";
|
|
47
|
-
|
|
48
51
|
export {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
} from "./preload/registerBackendPreload";
|
|
52
|
+
type WaitForDocumentsOptions,
|
|
53
|
+
waitForDocument,
|
|
54
|
+
waitForDocuments,
|
|
55
|
+
} from "./utils/waitForDocuments";
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {describe, expect, it} from "bun:test";
|
|
2
|
-
|
|
3
|
-
import {buildDatabaseUri, splitMongoUri} from "./connection";
|
|
4
2
|
import {setTerrenoTestEnv} from "../env/setTerrenoTestEnv";
|
|
3
|
+
import {buildDatabaseUri, splitMongoUri} from "./connection";
|
|
5
4
|
|
|
6
5
|
describe("mongo connection helpers", () => {
|
|
7
6
|
it("splitMongoUri separates base URI and query options", () => {
|
package/src/mongo/connection.ts
CHANGED
|
@@ -52,7 +52,8 @@ export const ensureTestMongooseConnected = async (
|
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
const uri =
|
|
55
|
+
const uri =
|
|
56
|
+
process.env.TERRENO_TEST_MONGODB_URI?.trim() || options.defaultUri || DEFAULT_LOCAL_MONGO_URI;
|
|
56
57
|
try {
|
|
57
58
|
await mongoose.connect(uri);
|
|
58
59
|
} catch (error) {
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import {afterAll, afterEach, beforeAll, beforeEach, jest, mock, setSystemTime} from "bun:test";
|
|
2
2
|
import mongoose from "mongoose";
|
|
3
|
-
|
|
4
|
-
import {testLogger} from "../logging/testLogger";
|
|
5
|
-
|
|
6
3
|
import {setTerrenoTestEnv, type TerrenoTestEnvOptions} from "../env/setTerrenoTestEnv";
|
|
7
4
|
import {
|
|
8
5
|
createLogSilencer,
|
|
@@ -10,12 +7,13 @@ import {
|
|
|
10
7
|
type SilenceLogsController,
|
|
11
8
|
type SilenceLogsOptions,
|
|
12
9
|
} from "../logging/silenceLogs";
|
|
10
|
+
import {testLogger} from "../logging/testLogger";
|
|
13
11
|
import {registerSentryBunMock} from "../mocks/sentryBun";
|
|
14
12
|
import {
|
|
15
13
|
initializeModels,
|
|
14
|
+
type MongoServerOptions,
|
|
16
15
|
startMongoServer,
|
|
17
16
|
stopMongoServer,
|
|
18
|
-
type MongoServerOptions,
|
|
19
17
|
} from "../mongo/mongoServer";
|
|
20
18
|
import {
|
|
21
19
|
abortTestTransaction,
|
|
@@ -143,8 +141,10 @@ export interface SimpleMongoPreloadOptions
|
|
|
143
141
|
|
|
144
142
|
export const registerSimpleMongoPreload = (options: SimpleMongoPreloadOptions = {}): void => {
|
|
145
143
|
let memoryMongo: {getUri: () => string; stop: () => Promise<boolean>} | undefined;
|
|
146
|
-
const {
|
|
147
|
-
|
|
144
|
+
const {
|
|
145
|
+
defaultLocalMongoUri = "mongodb://127.0.0.1/terreno?&connectTimeoutMS=360000",
|
|
146
|
+
...preloadOptions
|
|
147
|
+
} = options;
|
|
148
148
|
|
|
149
149
|
registerBackendPreload({
|
|
150
150
|
...preloadOptions,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// biome-ignore-all lint/suspicious/noExplicitAny: Mongoose prototype patches require dynamic signatures
|
|
1
2
|
/**
|
|
2
3
|
* Transaction-based test isolation for MongoDB.
|
|
3
4
|
*
|
|
@@ -38,7 +39,7 @@
|
|
|
38
39
|
* NOT patched. Only Mongoose-level operations are covered.
|
|
39
40
|
*/
|
|
40
41
|
|
|
41
|
-
import {AsyncLocalStorage} from "async_hooks";
|
|
42
|
+
import {AsyncLocalStorage} from "node:async_hooks";
|
|
42
43
|
import type {ClientSession} from "mongoose";
|
|
43
44
|
import mongoose from "mongoose";
|
|
44
45
|
|
|
@@ -448,12 +449,12 @@ export const installTransactionPatches = (): void => {
|
|
|
448
449
|
if (currentTestSession) {
|
|
449
450
|
return {
|
|
450
451
|
...currentTestSession,
|
|
451
|
-
startTransaction: () => {},
|
|
452
|
-
commitTransaction: async () => {},
|
|
453
452
|
abortTransaction: async () => {},
|
|
453
|
+
commitTransaction: async () => {},
|
|
454
454
|
endSession: async () => {},
|
|
455
455
|
id: currentTestSession.id,
|
|
456
456
|
inTransaction: () => currentTestSession?.inTransaction() ?? false,
|
|
457
|
+
startTransaction: () => {},
|
|
457
458
|
};
|
|
458
459
|
}
|
|
459
460
|
return originalStartSession.call(this, options);
|
|
@@ -14,11 +14,7 @@ export const waitForDocuments = async <T>(
|
|
|
14
14
|
model: Model<T>,
|
|
15
15
|
query: FilterQuery<T>,
|
|
16
16
|
count = 1,
|
|
17
|
-
{
|
|
18
|
-
timeoutMs = 5000,
|
|
19
|
-
intervalMs = 100,
|
|
20
|
-
sort,
|
|
21
|
-
}: WaitForDocumentsOptions = {}
|
|
17
|
+
{timeoutMs = 5000, intervalMs = 100, sort}: WaitForDocumentsOptions = {}
|
|
22
18
|
): Promise<T[]> => {
|
|
23
19
|
const start = Date.now();
|
|
24
20
|
while (Date.now() - start < timeoutMs) {
|