refactor: improve async operation handling in tests and enhance error handling in MongoDB wrapper

This commit is contained in:
italo jose
2025-07-20 22:04:00 -03:00
parent dc9fecc1c2
commit a21d7cc4e4
3 changed files with 4 additions and 5 deletions

View File

@@ -4298,9 +4298,10 @@ Tinytest.addAsync(
await Collection.updateAsync({ _id: 'a' }, { $set: { num: 1 } });
await Collection.updateAsync({ _id: 'b' }, { $set: { num: 2 } });
if(Meteor.isClient) Meteor._sleepForMs(100); // wait for async operations to complete
items = await Collection.find().fetchAsync();
itemIds = items.map(_item => _item.num);
test.equal(itemIds, [1, 2]);
await Collection.removeAsync({ _id: 'a' });

View File

@@ -19,8 +19,6 @@ function connect(client) {
if (process.env.MONGO_URL && (/^mongodb(\+srv)?:\/\//.test(process.env.MONGO_URL))) {
try {
// Try to parse the connection string to check if it's valid
new URL(process.env.MONGO_URL);
connect(new MongoClient(process.env.MONGO_URL)).then(client => {
if (client) client.close();
});
@@ -33,7 +31,7 @@ const useLegacyMongo = !!Package['npm-mongo-legacy']
const oldNoDeprecationValue = process.noDeprecation;
useLegacyMongo && console.log('WARN: npm-mongo-legacy package detected, using package for mongo <= 3.6');
console.log('useLegacyMongo', useLegacyMongo);
try {
// Silence deprecation warnings introduced in a patch update to mongodb:
// https://github.com/meteor/meteor/pull/9942#discussion_r218564879

View File

@@ -74,7 +74,7 @@ export class TestCaseResults {
var frame = stack[i];
// Heuristic: use the OUTERMOST line which is in a :tests.js
// file (this is less likely to be a test helper function).
const fileName = frame.getFileName();
const fileName = frame?.getFileName ? frame.getFileName() : null;
if (fileName && fileName.match(/:tests\.js/)) {
doc.filename = fileName;
doc.line = frame.getLineNumber();