Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions jest/setup.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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[]) => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@roryabraham These logs were always hidden earlier. Now when verbose is enabled, these logs will be printed. I am assuming we're fine with that? Confirming because of the comment.

They are not relevant for unit tests and create a lot of noise

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(<T>(_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', () => ({
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/CIGitLogicTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ const GIT_REMOTE = path.resolve(os.homedir(), 'dummyGitRemotes/DumDumRepo');
// Used to mock the Octokit GithubAPI
const mockGetInput = jest.fn<string | undefined, [string]>();

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());
Expand Down
Loading