From 358f0170f17c4f98e167872e59dbd3597f057102 Mon Sep 17 00:00:00 2001 From: partridgeworks <153919748+partridgeworks@users.noreply.github.com> Date: Tue, 12 Nov 2024 16:59:06 +0000 Subject: [PATCH] Reduce 'module not found' console logging Many users will only have the ability to resolve module 'firebase' or 'firebase-admin' but not necessarily both. Impacted users see repeated logging of 'Module not found, mocking skipped' messages which can cause concern, and also pollute the logs of larger test suites with many such lines. This change only logs to console in the more severe case where neither module can be found. --- src/mocks/firebase.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/mocks/firebase.js b/src/mocks/firebase.js index cdc0fec..df5dbe6 100644 --- a/src/mocks/firebase.js +++ b/src/mocks/firebase.js @@ -39,17 +39,22 @@ const firebaseStub = (overrides, options = defaultOptions) => { }; const mockFirebase = (overrides = {}, options = defaultOptions) => { - mockModuleIfFound('firebase', overrides, options); - mockModuleIfFound('firebase-admin', overrides, options); + const moduleFound = + mockModuleIfFound('firebase', overrides, options) | + mockModuleIfFound('firebase-admin', overrides, options); + + if (!moduleFound) { + console.info(`Neither 'firebase' nor 'firebase-admin' modules found, mocking skipped.`); + } }; function mockModuleIfFound(moduleName, overrides, options) { try { require.resolve(moduleName); jest.doMock(moduleName, () => firebaseStub(overrides, options)); + return true; } catch (e) { - // eslint-disable-next-line no-console - console.info(`Module ${moduleName} not found, mocking skipped.`); + return false; } }