1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-23 22:36:32 +02:00

Chore: Silence expected warning while running tests in lib/ (#12450)

This commit is contained in:
Henry Heino
2025-06-10 16:13:13 -07:00
committed by GitHub
parent 7a611ac5c5
commit 303ccce7d2
2 changed files with 23 additions and 3 deletions

View File

@@ -1190,4 +1190,22 @@ export const runWithFakeTimers = async (callback: ()=> Promise<void>) => {
}
};
export const withWarningSilenced = async <T> (warningRegex: RegExp, task: ()=> Promise<T>): Promise<T> => {
// See https://jestjs.io/docs/jest-object#spied-methods-and-the-using-keyword, which
// shows how to use .spyOn to hide warnings
let warningMock;
try {
warningMock = jest.spyOn(console, 'warn');
warningMock.mockImplementation((message, ...args) => {
const fullMessage = [message, ...args].join(' ');
if (!fullMessage.match(warningRegex)) {
console.error(`Unexpected warning: ${message}`, ...args);
}
});
return await task();
} finally {
warningMock.mockRestore();
}
};
export { supportDir, createNoteAndResource, createTempFile, createTestShareData, simulateReadOnlyShareEnv, waitForFolderCount, afterAllCleanUp, exportDir, synchronizerStart, afterEachCleanUp, syncTargetName, setSyncTargetName, syncDir, createTempDir, isNetworkSyncTarget, kvStore, expectThrow, logger, expectNotThrow, resourceService, resourceFetcher, tempFilePath, allSyncTargetItemsEncrypted, msleep, setupDatabase, revisionService, setupDatabaseAndSynchronizer, db, synchronizer, fileApi, sleep, clearDatabase, switchClient, syncTargetId, objectsEqual, checkThrowAsync, checkThrow, encryptionService, loadEncryptionMasterKey, fileContentEqual, decryptionWorker, currentClientId, id, ids, sortedIds, at, createNTestNotes, createNTestFolders, createNTestTags, TestApp };