From daa28f02a404599243a734c7cf8a1d2a0ff6c96b Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Fri, 20 Oct 2023 14:31:54 -0300 Subject: [PATCH] test: fix API test flakiness (#30657) --- .../rocketchat-mongo-config/server/index.js | 19 +++++++++---------- .../server/lib/dataExport/uploadZipFile.ts | 6 ++---- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/apps/meteor/packages/rocketchat-mongo-config/server/index.js b/apps/meteor/packages/rocketchat-mongo-config/server/index.js index 80e664a9c209..65464a31095c 100644 --- a/apps/meteor/packages/rocketchat-mongo-config/server/index.js +++ b/apps/meteor/packages/rocketchat-mongo-config/server/index.js @@ -34,20 +34,19 @@ if (Object.keys(mongoConnectionOptions).length > 0) { process.env.HTTP_FORWARDED_COUNT = process.env.HTTP_FORWARDED_COUNT || '1'; -// Send emails to a "fake" stream instead of print them in console in case MAIL_URL or SMTP is not configured -if (process.env.NODE_ENV !== 'development') { - const { sendAsync } = Email; +// Just print to logs if in TEST_MODE due to a bug in Meteor 2.5: TypeError: Cannot read property '_syncSendMail' of null +if (process.env.TEST_MODE === 'true') { + Email.sendAsync = function _sendAsync(options) { + console.log('Email.sendAsync', options); + }; +} else if (process.env.NODE_ENV !== 'development') { + // Send emails to a "fake" stream instead of print them in console in case MAIL_URL or SMTP is not configured const stream = new PassThrough(); stream.on('data', () => {}); stream.on('end', () => {}); - Email.sendAsync = function _sendAsync(options) { - return sendAsync.call(this, { stream, ...options }); - }; -} -// Just print to logs if in TEST_MODE due to a bug in Meteor 2.5: TypeError: Cannot read property '_syncSendMail' of null -if (process.env.TEST_MODE === 'true') { + const { sendAsync } = Email; Email.sendAsync = function _sendAsync(options) { - console.log('Email.sendAsync', options); + return sendAsync.call(this, { stream, ...options }); }; } diff --git a/apps/meteor/server/lib/dataExport/uploadZipFile.ts b/apps/meteor/server/lib/dataExport/uploadZipFile.ts index e6a76472db7f..5fe9ea2d57dd 100644 --- a/apps/meteor/server/lib/dataExport/uploadZipFile.ts +++ b/apps/meteor/server/lib/dataExport/uploadZipFile.ts @@ -1,5 +1,5 @@ import { createReadStream } from 'fs'; -import { open, stat } from 'fs/promises'; +import { stat } from 'fs/promises'; import type { IUser } from '@rocket.chat/core-typings'; import { Users } from '@rocket.chat/models'; @@ -28,9 +28,7 @@ export const uploadZipFile = async (filePath: string, userId: IUser['_id'], expo name: newFileName, }; - const { fd } = await open(filePath); - - const stream = createReadStream('', { fd }); // @todo once upgrades to Node.js v16.x, use createReadStream from fs.promises.open + const stream = createReadStream(filePath); const userDataStore = FileUpload.getStore('UserDataFiles');