@terreno/test 0.30.0 → 56.0.0-beta.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.
|
@@ -246,6 +246,14 @@ var getReconnectUri = function (publishedUriEnvVar, baseDatabaseName) {
|
|
|
246
246
|
}
|
|
247
247
|
return (0, connection_1.buildDatabaseUri)({ databaseName: mongoose_1.default.connection.name || baseDatabaseName, uri: uri });
|
|
248
248
|
};
|
|
249
|
+
/** Throws when the driver has no database handle, so callers treat it like a failed ping. */
|
|
250
|
+
var requireDb = function () {
|
|
251
|
+
var db = mongoose_1.default.connection.db;
|
|
252
|
+
if (!db) {
|
|
253
|
+
throw new Error("[mongoTestCache] mongoose connection has no database handle");
|
|
254
|
+
}
|
|
255
|
+
return db;
|
|
256
|
+
};
|
|
249
257
|
var ensureConnectionReady = function (publishedUriEnvVar, baseDatabaseName) { return __awaiter(void 0, void 0, void 0, function () {
|
|
250
258
|
var maxQuickAttempts, delayMs, attempt, state, _a, _b;
|
|
251
259
|
return __generator(this, function (_c) {
|
|
@@ -262,7 +270,7 @@ var ensureConnectionReady = function (publishedUriEnvVar, baseDatabaseName) { re
|
|
|
262
270
|
_c.label = 2;
|
|
263
271
|
case 2:
|
|
264
272
|
_c.trys.push([2, 4, , 5]);
|
|
265
|
-
return [4 /*yield*/,
|
|
273
|
+
return [4 /*yield*/, requireDb().admin().command({ ping: 1 })];
|
|
266
274
|
case 3:
|
|
267
275
|
_c.sent();
|
|
268
276
|
return [2 /*return*/];
|
|
@@ -286,7 +294,7 @@ var ensureConnectionReady = function (publishedUriEnvVar, baseDatabaseName) { re
|
|
|
286
294
|
})];
|
|
287
295
|
case 9:
|
|
288
296
|
_c.sent();
|
|
289
|
-
return [4 /*yield*/,
|
|
297
|
+
return [4 /*yield*/, requireDb().admin().command({ ping: 1 })];
|
|
290
298
|
case 10:
|
|
291
299
|
_c.sent();
|
|
292
300
|
return [4 /*yield*/, (0, testTransaction_1.resetTestSessionAfterReconnect)()];
|
|
@@ -326,7 +334,7 @@ var loadTestDataIntoDb = function (cachedCollections) { return __awaiter(void 0,
|
|
|
326
334
|
try {
|
|
327
335
|
for (_a = __values(Object.keys(cachedCollections)), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
328
336
|
collectionName = _b.value;
|
|
329
|
-
clearPromises.push(
|
|
337
|
+
clearPromises.push(requireDb().collection(collectionName).deleteMany({}));
|
|
330
338
|
}
|
|
331
339
|
}
|
|
332
340
|
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
@@ -510,8 +518,10 @@ var createMongoTestCache = function (options) {
|
|
|
510
518
|
inflightSetupTestCache = null;
|
|
511
519
|
});
|
|
512
520
|
}
|
|
513
|
-
|
|
521
|
+
// Wrapped because the `finally` above clears the shared slot once it settles.
|
|
522
|
+
return [4 /*yield*/, Promise.resolve(inflightSetupTestCache)];
|
|
514
523
|
case 1:
|
|
524
|
+
// Wrapped because the `finally` above clears the shared slot once it settles.
|
|
515
525
|
_a.sent();
|
|
516
526
|
_a.label = 2;
|
|
517
527
|
case 2:
|
|
@@ -110,9 +110,11 @@ var createLogSilencer = function (options) {
|
|
|
110
110
|
var _b;
|
|
111
111
|
winston_1.default.clear();
|
|
112
112
|
winston_1.default.add(silentTransport);
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
// Only reach for @terreno/api when the caller has not supplied its logger. Requiring the
|
|
114
|
+
// package from inside api's own test run would load its built dist alongside the sources
|
|
115
|
+
// under test, registering every Mongoose model twice.
|
|
116
|
+
var provided = (_b = options.additionalWinstonLoggers) !== null && _b !== void 0 ? _b : [];
|
|
117
|
+
var extraLoggers = (provided.length > 0 ? provided : [getApiWinstonLogger()]).filter(Boolean);
|
|
116
118
|
try {
|
|
117
119
|
for (var extraLoggers_1 = __values(extraLoggers), extraLoggers_1_1 = extraLoggers_1.next(); !extraLoggers_1_1.done; extraLoggers_1_1 = extraLoggers_1.next()) {
|
|
118
120
|
var extraLogger = extraLoggers_1_1.value;
|
package/package.json
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"mongodb-memory-server-global": "^11.0.1",
|
|
21
21
|
"mongoose": "8.23.0",
|
|
22
22
|
"supertest": "^7.2.2",
|
|
23
|
-
"typescript": "~
|
|
23
|
+
"typescript": "~6.0.3"
|
|
24
24
|
},
|
|
25
25
|
"homepage": "https://github.com/FlourishHealth/terreno#readme",
|
|
26
26
|
"keywords": [
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"test:ci": "bun test"
|
|
62
62
|
},
|
|
63
63
|
"types": "dist/index.d.ts",
|
|
64
|
-
"version": "0.
|
|
64
|
+
"version": "56.0.0-beta.0"
|
|
65
65
|
}
|
|
@@ -132,6 +132,15 @@ const getReconnectUri = (publishedUriEnvVar: string, baseDatabaseName: string):
|
|
|
132
132
|
return buildDatabaseUri({databaseName: mongoose.connection.name || baseDatabaseName, uri});
|
|
133
133
|
};
|
|
134
134
|
|
|
135
|
+
/** Throws when the driver has no database handle, so callers treat it like a failed ping. */
|
|
136
|
+
const requireDb = (): mongoose.mongo.Db => {
|
|
137
|
+
const {db} = mongoose.connection;
|
|
138
|
+
if (!db) {
|
|
139
|
+
throw new Error("[mongoTestCache] mongoose connection has no database handle");
|
|
140
|
+
}
|
|
141
|
+
return db;
|
|
142
|
+
};
|
|
143
|
+
|
|
135
144
|
const ensureConnectionReady = async (
|
|
136
145
|
publishedUriEnvVar: string,
|
|
137
146
|
baseDatabaseName: string
|
|
@@ -143,7 +152,7 @@ const ensureConnectionReady = async (
|
|
|
143
152
|
const state = mongoose.connection.readyState;
|
|
144
153
|
if (state === 1) {
|
|
145
154
|
try {
|
|
146
|
-
await
|
|
155
|
+
await requireDb().admin().command({ping: 1});
|
|
147
156
|
return;
|
|
148
157
|
} catch {
|
|
149
158
|
// stale connection
|
|
@@ -160,7 +169,7 @@ const ensureConnectionReady = async (
|
|
|
160
169
|
serverSelectionTimeoutMS: 2000,
|
|
161
170
|
socketTimeoutMS: 2000,
|
|
162
171
|
});
|
|
163
|
-
await
|
|
172
|
+
await requireDb().admin().command({ping: 1});
|
|
164
173
|
await resetTestSessionAfterReconnect();
|
|
165
174
|
return;
|
|
166
175
|
} catch {
|
|
@@ -180,7 +189,7 @@ const ensureConnectionReady = async (
|
|
|
180
189
|
const loadTestDataIntoDb = async (cachedCollections: Record<string, unknown[]>): Promise<void> => {
|
|
181
190
|
const clearPromises: Array<Promise<unknown>> = [];
|
|
182
191
|
for (const collectionName of Object.keys(cachedCollections)) {
|
|
183
|
-
clearPromises.push(
|
|
192
|
+
clearPromises.push(requireDb().collection(collectionName).deleteMany({}));
|
|
184
193
|
}
|
|
185
194
|
await Promise.all(clearPromises);
|
|
186
195
|
|
|
@@ -287,7 +296,8 @@ export const createMongoTestCache = (options: MongoTestCacheOptions): MongoTestC
|
|
|
287
296
|
inflightSetupTestCache = null;
|
|
288
297
|
});
|
|
289
298
|
}
|
|
290
|
-
|
|
299
|
+
// Wrapped because the `finally` above clears the shared slot once it settles.
|
|
300
|
+
await Promise.resolve(inflightSetupTestCache);
|
|
291
301
|
}
|
|
292
302
|
|
|
293
303
|
if (!cachedCollectionsInMemory) {
|
|
@@ -82,10 +82,13 @@ export const createLogSilencer = (options: SilenceLogsOptions = {}): SilenceLogs
|
|
|
82
82
|
winston.clear();
|
|
83
83
|
winston.add(silentTransport);
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
// Only reach for @terreno/api when the caller has not supplied its logger. Requiring the
|
|
86
|
+
// package from inside api's own test run would load its built dist alongside the sources
|
|
87
|
+
// under test, registering every Mongoose model twice.
|
|
88
|
+
const provided = options.additionalWinstonLoggers ?? [];
|
|
89
|
+
const extraLoggers = (provided.length > 0 ? provided : [getApiWinstonLogger()]).filter(
|
|
90
|
+
Boolean
|
|
91
|
+
) as winston.Logger[];
|
|
89
92
|
|
|
90
93
|
for (const extraLogger of extraLoggers) {
|
|
91
94
|
extraLogger.clear();
|
package/tsconfig.json
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
"downlevelIteration": true,
|
|
8
8
|
"esModuleInterop": true,
|
|
9
9
|
"forceConsistentCasingInFileNames": true,
|
|
10
|
+
"ignoreDeprecations": "6.0",
|
|
10
11
|
"jsx": "react",
|
|
11
12
|
"lib": ["es2017", "dom", "es2017.object"],
|
|
12
13
|
"module": "commonjs",
|
|
@@ -20,11 +21,13 @@
|
|
|
20
21
|
"outDir": "./dist",
|
|
21
22
|
"preserveConstEnums": true,
|
|
22
23
|
"removeComments": false,
|
|
24
|
+
"rootDir": "./src",
|
|
23
25
|
"skipLibCheck": true,
|
|
24
26
|
"strict": true,
|
|
25
27
|
"strictFunctionTypes": true,
|
|
26
28
|
"strictNullChecks": true,
|
|
27
|
-
"target": "es5"
|
|
29
|
+
"target": "es5",
|
|
30
|
+
"types": ["bun", "node"]
|
|
28
31
|
},
|
|
29
32
|
"exclude": ["node_modules", "src/mongo/ensureMongoBinary.ts"],
|
|
30
33
|
"include": ["src/**/*.ts"]
|