From b53c0083f69c122eaac3413efc6a6b2c2e6fd30b Mon Sep 17 00:00:00 2001 From: Eliran Goshen Date: Mon, 8 Sep 2025 15:11:59 +0200 Subject: [PATCH 1/9] clearing logs --- jest/setup.ts | 15 +++++---------- jest/setupAfterEnv.ts | 8 ++++++++ tests/unit/CIGitLogicTest.ts | 5 +++++ 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/jest/setup.ts b/jest/setup.ts index 41626ee3bb97..f1e47173d677 100644 --- a/jest/setup.ts +++ b/jest/setup.ts @@ -40,16 +40,11 @@ jest.mock('react-native/Libraries/LogBox/LogBox', () => ({ }, })); -// Turn off the console logs for timing events. They are not relevant for unit tests and create a lot of noise -jest.spyOn(console, 'debug').mockImplementation((...params: string[]) => { - if (params.at(0)?.startsWith('Timing:')) { - return; - } - - // Send the message to console.log but don't re-used console.debug or else this mock method is called in an infinite loop. Instead, just prefix the output with the word "DEBUG" - // eslint-disable-next-line no-console - console.log('DEBUG', ...params); -}); +jest.spyOn(console, 'log').mockImplementation(() => {}); +jest.spyOn(console, 'info').mockImplementation(() => {}); +jest.spyOn(console, 'debug').mockImplementation(() => {}); +jest.spyOn(console, 'warn').mockImplementation(() => {}); +jest.spyOn(console, 'error').mockImplementation(() => {}); // This mock is required for mocking file systems when running tests jest.mock('react-native-fs', () => ({ diff --git a/jest/setupAfterEnv.ts b/jest/setupAfterEnv.ts index 3ce0fa37247e..efb1fac63d71 100644 --- a/jest/setupAfterEnv.ts +++ b/jest/setupAfterEnv.ts @@ -1,3 +1,11 @@ import '@testing-library/react-native'; +beforeEach(() => { + jest.spyOn(console, 'log').mockImplementation(() => {}); + jest.spyOn(console, 'info').mockImplementation(() => {}); + jest.spyOn(console, 'debug').mockImplementation(() => {}); + jest.spyOn(console, 'warn').mockImplementation(() => {}); + jest.spyOn(console, 'error').mockImplementation(() => {}); +}); + jest.useRealTimers(); diff --git a/tests/unit/CIGitLogicTest.ts b/tests/unit/CIGitLogicTest.ts index e9cee890f40f..e47e83154072 100644 --- a/tests/unit/CIGitLogicTest.ts +++ b/tests/unit/CIGitLogicTest.ts @@ -471,6 +471,11 @@ async function assertPRsMergedBetween(from: string, to: string, expected: number let startingDir: string; describe('CIGitLogic', () => { beforeAll(() => { + jest.spyOn(Log, 'log').mockImplementation(() => {}); + jest.spyOn(Log, 'info').mockImplementation(() => {}); + jest.spyOn(Log, 'success').mockImplementation(() => {}); + jest.spyOn(Log, 'warn').mockImplementation(() => {}); + Log.info('Starting setup'); startingDir = process.cwd(); initGitServer(); From 7c39b7929242a21169b11b26a40291e51e07e9fa Mon Sep 17 00:00:00 2001 From: Eliran Goshen Date: Mon, 8 Sep 2025 19:02:20 +0200 Subject: [PATCH 2/9] reverting error logs visibility --- jest/setup.ts | 1 - jest/setupAfterEnv.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/jest/setup.ts b/jest/setup.ts index f1e47173d677..319ebd39e532 100644 --- a/jest/setup.ts +++ b/jest/setup.ts @@ -44,7 +44,6 @@ jest.spyOn(console, 'log').mockImplementation(() => {}); jest.spyOn(console, 'info').mockImplementation(() => {}); jest.spyOn(console, 'debug').mockImplementation(() => {}); jest.spyOn(console, 'warn').mockImplementation(() => {}); -jest.spyOn(console, 'error').mockImplementation(() => {}); // This mock is required for mocking file systems when running tests jest.mock('react-native-fs', () => ({ diff --git a/jest/setupAfterEnv.ts b/jest/setupAfterEnv.ts index efb1fac63d71..ebd05d0d9cc4 100644 --- a/jest/setupAfterEnv.ts +++ b/jest/setupAfterEnv.ts @@ -5,7 +5,6 @@ beforeEach(() => { jest.spyOn(console, 'info').mockImplementation(() => {}); jest.spyOn(console, 'debug').mockImplementation(() => {}); jest.spyOn(console, 'warn').mockImplementation(() => {}); - jest.spyOn(console, 'error').mockImplementation(() => {}); }); jest.useRealTimers(); From 708172211462ba587c4cf0f89b6ac3f8d7bc4043 Mon Sep 17 00:00:00 2001 From: Eliran Goshen Date: Wed, 10 Sep 2025 12:56:51 +0200 Subject: [PATCH 3/9] added verbose to show all logs --- jest/setup.ts | 18 ++++++++++++++---- jest/setupAfterEnv.ts | 7 +++++++ package.json | 1 + tests/unit/CIGitLogicTest.ts | 14 +++++++++----- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/jest/setup.ts b/jest/setup.ts index 319ebd39e532..d875ec5ef833 100644 --- a/jest/setup.ts +++ b/jest/setup.ts @@ -1,4 +1,5 @@ /* eslint-disable max-classes-per-file */ +import * as core from '@actions/core'; import '@shopify/flash-list/jestSetup'; import type * as RNAppLogs from 'react-native-app-logs'; import 'react-native-gesture-handler/jestSetup'; @@ -40,10 +41,19 @@ jest.mock('react-native/Libraries/LogBox/LogBox', () => ({ }, })); -jest.spyOn(console, 'log').mockImplementation(() => {}); -jest.spyOn(console, 'info').mockImplementation(() => {}); -jest.spyOn(console, 'debug').mockImplementation(() => {}); -jest.spyOn(console, 'warn').mockImplementation(() => {}); +const isVerbose = process.argv.includes('verbose') || process.env.JEST_VERBOSE === 'true'; + +if (!isVerbose) { + jest.spyOn(console, 'log').mockImplementation(() => {}); + jest.spyOn(console, 'info').mockImplementation(() => {}); + jest.spyOn(console, 'debug').mockImplementation(() => {}); + jest.spyOn(console, 'warn').mockImplementation(() => {}); + jest.spyOn(core, 'startGroup').mockImplementation(() => {}); + jest.spyOn(core, 'endGroup').mockImplementation(() => {}); + jest.spyOn(core, 'group').mockImplementation((_title: string, fn: () => T) => fn()); + jest.spyOn(core, 'info').mockImplementation(() => {}); + jest.spyOn(core, 'setOutput').mockImplementation(() => {}); +} // This mock is required for mocking file systems when running tests jest.mock('react-native-fs', () => ({ diff --git a/jest/setupAfterEnv.ts b/jest/setupAfterEnv.ts index ebd05d0d9cc4..424b6f659115 100644 --- a/jest/setupAfterEnv.ts +++ b/jest/setupAfterEnv.ts @@ -1,6 +1,13 @@ import '@testing-library/react-native'; +const isVerbose = process.argv.includes('--verbose') || process.env.JEST_VERBOSE === 'true'; + + beforeEach(() => { + if (isVerbose) { + return; + } + jest.spyOn(console, 'log').mockImplementation(() => {}); jest.spyOn(console, 'info').mockImplementation(() => {}); jest.spyOn(console, 'debug').mockImplementation(() => {}); diff --git a/package.json b/package.json index bca01f1ea057..b48826e064d7 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "android-build": "bundle exec fastlane android build_local", "android-hybrid-build": "bundle exec fastlane android build_local_hybrid", "test": "TZ=utc NODE_OPTIONS=--experimental-vm-modules jest", + "test:verbose": "TZ=utc NODE_OPTIONS=--experimental-vm-modules JEST_VERBOSE=true jest", "test:debug": "TZ=utc NODE_OPTIONS='--inspect-brk --experimental-vm-modules' jest --runInBand", "perf-test": "NODE_OPTIONS=--experimental-vm-modules npx reassure", "typecheck": "NODE_OPTIONS=--max_old_space_size=8192 tsc", diff --git a/tests/unit/CIGitLogicTest.ts b/tests/unit/CIGitLogicTest.ts index e47e83154072..e7a902f6cb5f 100644 --- a/tests/unit/CIGitLogicTest.ts +++ b/tests/unit/CIGitLogicTest.ts @@ -24,12 +24,14 @@ const GIT_REMOTE = path.resolve(os.homedir(), 'dummyGitRemotes/DumDumRepo'); // Used to mock the Octokit GithubAPI const mockGetInput = jest.fn(); +const isVerbose = process.argv.includes('--verbose') || process.env.JEST_VERBOSE === 'true'; + type ExecSyncError = {stderr: Buffer}; function exec(command: string) { try { Log.info(command); - execSync(command, {stdio: 'inherit'}); + execSync(command, {stdio: isVerbose ? 'inherit' : 'pipe'}); } catch (error) { if ((error as ExecSyncError).stderr) { Log.error((error as ExecSyncError).stderr.toString()); @@ -471,10 +473,12 @@ async function assertPRsMergedBetween(from: string, to: string, expected: number let startingDir: string; describe('CIGitLogic', () => { beforeAll(() => { - jest.spyOn(Log, 'log').mockImplementation(() => {}); - jest.spyOn(Log, 'info').mockImplementation(() => {}); - jest.spyOn(Log, 'success').mockImplementation(() => {}); - jest.spyOn(Log, 'warn').mockImplementation(() => {}); + if (!isVerbose) { + jest.spyOn(Log, 'log').mockImplementation(() => {}); + jest.spyOn(Log, 'info').mockImplementation(() => {}); + jest.spyOn(Log, 'success').mockImplementation(() => {}); + jest.spyOn(Log, 'warn').mockImplementation(() => {}); + } Log.info('Starting setup'); startingDir = process.cwd(); From 913b73fd73696f14dc5858581651df11d7b39079 Mon Sep 17 00:00:00 2001 From: Eliran Goshen Date: Mon, 15 Sep 2025 11:11:24 +0200 Subject: [PATCH 4/9] fix prettier --- jest/setupAfterEnv.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/jest/setupAfterEnv.ts b/jest/setupAfterEnv.ts index 424b6f659115..8dcfa9ee73ce 100644 --- a/jest/setupAfterEnv.ts +++ b/jest/setupAfterEnv.ts @@ -2,7 +2,6 @@ import '@testing-library/react-native'; const isVerbose = process.argv.includes('--verbose') || process.env.JEST_VERBOSE === 'true'; - beforeEach(() => { if (isVerbose) { return; From 16e85362a8a4af7f0dab6904c02d08fc679e7f3a Mon Sep 17 00:00:00 2001 From: eliran goshen Date: Thu, 18 Sep 2025 11:33:00 +0200 Subject: [PATCH 5/9] pr fixes --- jest/setupAfterEnv.ts | 5 +++++ tests/unit/CIGitLogicTest.ts | 7 ------- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/jest/setupAfterEnv.ts b/jest/setupAfterEnv.ts index 8dcfa9ee73ce..0d02ce7c22a1 100644 --- a/jest/setupAfterEnv.ts +++ b/jest/setupAfterEnv.ts @@ -1,4 +1,5 @@ import '@testing-library/react-native'; +import * as Log from '../scripts/utils/Logger'; const isVerbose = process.argv.includes('--verbose') || process.env.JEST_VERBOSE === 'true'; @@ -11,6 +12,10 @@ beforeEach(() => { jest.spyOn(console, 'info').mockImplementation(() => {}); jest.spyOn(console, 'debug').mockImplementation(() => {}); jest.spyOn(console, 'warn').mockImplementation(() => {}); + jest.spyOn(Log, 'log').mockImplementation(() => {}); + jest.spyOn(Log, 'info').mockImplementation(() => {}); + jest.spyOn(Log, 'success').mockImplementation(() => {}); + jest.spyOn(Log, 'warn').mockImplementation(() => {}); }); jest.useRealTimers(); diff --git a/tests/unit/CIGitLogicTest.ts b/tests/unit/CIGitLogicTest.ts index e7a902f6cb5f..752f03904f2c 100644 --- a/tests/unit/CIGitLogicTest.ts +++ b/tests/unit/CIGitLogicTest.ts @@ -473,13 +473,6 @@ async function assertPRsMergedBetween(from: string, to: string, expected: number let startingDir: string; describe('CIGitLogic', () => { beforeAll(() => { - if (!isVerbose) { - jest.spyOn(Log, 'log').mockImplementation(() => {}); - jest.spyOn(Log, 'info').mockImplementation(() => {}); - jest.spyOn(Log, 'success').mockImplementation(() => {}); - jest.spyOn(Log, 'warn').mockImplementation(() => {}); - } - Log.info('Starting setup'); startingDir = process.cwd(); initGitServer(); From 98e2e430019bc54a9e840b86f4112a1f423ec949 Mon Sep 17 00:00:00 2001 From: eliran goshen Date: Fri, 19 Sep 2025 11:52:07 +0200 Subject: [PATCH 6/9] moving log mock to setup,ts --- jest/setup.ts | 15 ++++++++++----- jest/setupAfterEnv.ts | 18 ------------------ 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/jest/setup.ts b/jest/setup.ts index d875ec5ef833..ee5ebec703f8 100644 --- a/jest/setup.ts +++ b/jest/setup.ts @@ -41,18 +41,23 @@ jest.mock('react-native/Libraries/LogBox/LogBox', () => ({ }, })); -const isVerbose = process.argv.includes('verbose') || process.env.JEST_VERBOSE === 'true'; +const isVerbose = process.env.JEST_VERBOSE === 'true'; if (!isVerbose) { - jest.spyOn(console, 'log').mockImplementation(() => {}); - jest.spyOn(console, 'info').mockImplementation(() => {}); - jest.spyOn(console, 'debug').mockImplementation(() => {}); - jest.spyOn(console, 'warn').mockImplementation(() => {}); jest.spyOn(core, 'startGroup').mockImplementation(() => {}); jest.spyOn(core, 'endGroup').mockImplementation(() => {}); jest.spyOn(core, 'group').mockImplementation((_title: string, fn: () => T) => fn()); jest.spyOn(core, 'info').mockImplementation(() => {}); jest.spyOn(core, 'setOutput').mockImplementation(() => {}); + + // Make them global to override module-level console calls + global.console = { + ...console, + log: jest.fn(), + info: jest.fn(), + debug: jest.fn(), + warn: jest.fn(), + } as Console; } // This mock is required for mocking file systems when running tests diff --git a/jest/setupAfterEnv.ts b/jest/setupAfterEnv.ts index 0d02ce7c22a1..3ce0fa37247e 100644 --- a/jest/setupAfterEnv.ts +++ b/jest/setupAfterEnv.ts @@ -1,21 +1,3 @@ import '@testing-library/react-native'; -import * as Log from '../scripts/utils/Logger'; - -const isVerbose = process.argv.includes('--verbose') || process.env.JEST_VERBOSE === 'true'; - -beforeEach(() => { - if (isVerbose) { - return; - } - - jest.spyOn(console, 'log').mockImplementation(() => {}); - jest.spyOn(console, 'info').mockImplementation(() => {}); - jest.spyOn(console, 'debug').mockImplementation(() => {}); - jest.spyOn(console, 'warn').mockImplementation(() => {}); - jest.spyOn(Log, 'log').mockImplementation(() => {}); - jest.spyOn(Log, 'info').mockImplementation(() => {}); - jest.spyOn(Log, 'success').mockImplementation(() => {}); - jest.spyOn(Log, 'warn').mockImplementation(() => {}); -}); jest.useRealTimers(); From b8de7af8bdc093a9f6ec84883d08e932fdbcb1af Mon Sep 17 00:00:00 2001 From: eliran goshen Date: Fri, 19 Sep 2025 11:53:36 +0200 Subject: [PATCH 7/9] verbose fix --- tests/unit/CIGitLogicTest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/CIGitLogicTest.ts b/tests/unit/CIGitLogicTest.ts index 752f03904f2c..62b74c938699 100644 --- a/tests/unit/CIGitLogicTest.ts +++ b/tests/unit/CIGitLogicTest.ts @@ -24,7 +24,7 @@ const GIT_REMOTE = path.resolve(os.homedir(), 'dummyGitRemotes/DumDumRepo'); // Used to mock the Octokit GithubAPI const mockGetInput = jest.fn(); -const isVerbose = process.argv.includes('--verbose') || process.env.JEST_VERBOSE === 'true'; +const isVerbose = process.env.JEST_VERBOSE === 'true'; type ExecSyncError = {stderr: Buffer}; From 46712f455fa03d093e74d09ba80e195a193aa668 Mon Sep 17 00:00:00 2001 From: eliran goshen Date: Mon, 22 Sep 2025 11:56:29 +0200 Subject: [PATCH 8/9] pr fix --- jest/setup.ts | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/jest/setup.ts b/jest/setup.ts index ee5ebec703f8..515b5bf94367 100644 --- a/jest/setup.ts +++ b/jest/setup.ts @@ -1,5 +1,4 @@ /* eslint-disable max-classes-per-file */ -import * as core from '@actions/core'; import '@shopify/flash-list/jestSetup'; import type * as RNAppLogs from 'react-native-app-logs'; import 'react-native-gesture-handler/jestSetup'; @@ -44,11 +43,25 @@ jest.mock('react-native/Libraries/LogBox/LogBox', () => ({ const isVerbose = process.env.JEST_VERBOSE === 'true'; if (!isVerbose) { - jest.spyOn(core, 'startGroup').mockImplementation(() => {}); - jest.spyOn(core, 'endGroup').mockImplementation(() => {}); - jest.spyOn(core, 'group').mockImplementation((_title: string, fn: () => T) => fn()); - jest.spyOn(core, 'info').mockImplementation(() => {}); - jest.spyOn(core, 'setOutput').mockImplementation(() => {}); + jest.mock('@actions/core', () => { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + const originalCore = jest.requireActual('@actions/core'); // this is giving lint error + + const createMockFn = () => { + const mockFn = jest.fn(() => {}); + return mockFn; + }; + + // eslint-disable-next-line @typescript-eslint/no-unsafe-return + return { + ...originalCore, + startGroup: createMockFn(), + endGroup: createMockFn(), + group: jest.fn((_title: unknown, fn: unknown) => fn), + info: createMockFn(), + setOutput: createMockFn(), + }; + }); // Make them global to override module-level console calls global.console = { From 548af110db35bddbff576ba5e9d78fcadc3860b5 Mon Sep 17 00:00:00 2001 From: eliran goshen Date: Wed, 8 Oct 2025 16:28:56 +0200 Subject: [PATCH 9/9] revert to using spyOn --- jest/setup.ts | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/jest/setup.ts b/jest/setup.ts index 515b5bf94367..ee5ebec703f8 100644 --- a/jest/setup.ts +++ b/jest/setup.ts @@ -1,4 +1,5 @@ /* eslint-disable max-classes-per-file */ +import * as core from '@actions/core'; import '@shopify/flash-list/jestSetup'; import type * as RNAppLogs from 'react-native-app-logs'; import 'react-native-gesture-handler/jestSetup'; @@ -43,25 +44,11 @@ jest.mock('react-native/Libraries/LogBox/LogBox', () => ({ const isVerbose = process.env.JEST_VERBOSE === 'true'; if (!isVerbose) { - jest.mock('@actions/core', () => { - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - const originalCore = jest.requireActual('@actions/core'); // this is giving lint error - - const createMockFn = () => { - const mockFn = jest.fn(() => {}); - return mockFn; - }; - - // eslint-disable-next-line @typescript-eslint/no-unsafe-return - return { - ...originalCore, - startGroup: createMockFn(), - endGroup: createMockFn(), - group: jest.fn((_title: unknown, fn: unknown) => fn), - info: createMockFn(), - setOutput: createMockFn(), - }; - }); + jest.spyOn(core, 'startGroup').mockImplementation(() => {}); + jest.spyOn(core, 'endGroup').mockImplementation(() => {}); + jest.spyOn(core, 'group').mockImplementation((_title: string, fn: () => T) => fn()); + jest.spyOn(core, 'info').mockImplementation(() => {}); + jest.spyOn(core, 'setOutput').mockImplementation(() => {}); // Make them global to override module-level console calls global.console = {