diff --git a/jest/setup.ts b/jest/setup.ts index 41626ee3bb97..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'; @@ -40,16 +41,24 @@ 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); -}); +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(() => {}); + + // 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 jest.mock('react-native-fs', () => ({ 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 e9cee890f40f..62b74c938699 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.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());