Skip to content

Commit

Permalink
Merge pull request Expensify#34641 from callstack-internal/fix/reassu…
Browse files Browse the repository at this point in the history
…re-improvements

[NoQA] Reassure performance tests improvements
  • Loading branch information
mountiny authored Jan 26, 2024
2 parents 54013d3 + 58f76ec commit d223824
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 113 deletions.
7 changes: 0 additions & 7 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3057,13 +3057,6 @@ const CONST = {
*/
MAX_OPTIONS_SELECTOR_PAGE_LENGTH: 500,

/**
* Performance test setup - run the same test multiple times to get a more accurate result
*/
PERFORMANCE_TESTS: {
RUNS: 20,
},

/**
* Bank account names
*/
Expand Down
10 changes: 4 additions & 6 deletions tests/perf-test/ModifiedExpenseMessage.perf-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import createRandomReportAction from '../utils/collections/reportActions';
import createRandomReport from '../utils/collections/reports';
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';

const runs = CONST.PERFORMANCE_TESTS.RUNS;

beforeAll(() =>
Onyx.init({
keys: ONYXKEYS,
Expand All @@ -39,10 +37,10 @@ const getMockedPolicies = (length = 500) =>
length,
);

const mockedReportsMap = getMockedReports(5000) as Record<`${typeof ONYXKEYS.COLLECTION.REPORT}`, Report>;
const mockedPoliciesMap = getMockedPolicies(5000) as Record<`${typeof ONYXKEYS.COLLECTION.POLICY}`, Policy>;
const mockedReportsMap = getMockedReports(1000) as Record<`${typeof ONYXKEYS.COLLECTION.REPORT}`, Report>;
const mockedPoliciesMap = getMockedPolicies(1000) as Record<`${typeof ONYXKEYS.COLLECTION.POLICY}`, Policy>;

test('[ModifiedExpenseMessage] getForReportAction on 5k reports and policies', async () => {
test('[ModifiedExpenseMessage] getForReportAction on 1k reports and policies', async () => {
const reportAction = {
...createRandomReportAction(1),
actionName: CONST.REPORT.ACTIONS.TYPE.MODIFIEDEXPENSE,
Expand All @@ -60,5 +58,5 @@ test('[ModifiedExpenseMessage] getForReportAction on 5k reports and policies', a
});

await waitForBatchedUpdates();
await measureFunction(() => ModifiedExpenseMessage.getForReportAction(reportAction), {runs});
await measureFunction(() => ModifiedExpenseMessage.getForReportAction(reportAction));
});
13 changes: 5 additions & 8 deletions tests/perf-test/OptionsSelector.perf-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React from 'react';
import {measurePerformance} from 'reassure';
import _ from 'underscore';
import OptionsSelector from '@src/components/OptionsSelector';
import CONST from '@src/CONST';
import variables from '@src/styles/variables';

jest.mock('../../src/components/withLocalize', () => (Component) => {
Expand Down Expand Up @@ -65,8 +64,6 @@ function OptionsSelectorWrapper(args) {
);
}

const runs = CONST.PERFORMANCE_TESTS.RUNS;

test('[OptionsSelector] should render text input with interactions', () => {
const scenario = (screen) => {
const textInput = screen.getByTestId('options-selector-input');
Expand All @@ -75,16 +72,16 @@ test('[OptionsSelector] should render text input with interactions', () => {
fireEvent.changeText(textInput, 'test3');
};

measurePerformance(<OptionsSelectorWrapper />, {scenario, runs});
measurePerformance(<OptionsSelectorWrapper />, {scenario});
});

test('[OptionsSelector] should render 1 section', () => {
measurePerformance(<OptionsSelectorWrapper />, {runs});
measurePerformance(<OptionsSelectorWrapper />);
});

test('[OptionsSelector] should render multiple sections', () => {
const sections = generateSections(mutlipleSectionsConfig);
measurePerformance(<OptionsSelectorWrapper sections={sections} />, {runs});
measurePerformance(<OptionsSelectorWrapper sections={sections} />);
});

test('[OptionsSelector] should press a list items', () => {
Expand All @@ -94,7 +91,7 @@ test('[OptionsSelector] should press a list items', () => {
fireEvent.press(screen.getByText('Item 10'));
};

measurePerformance(<OptionsSelectorWrapper />, {scenario, runs});
measurePerformance(<OptionsSelectorWrapper />, {scenario});
});

test('[OptionsSelector] should scroll and press few items', () => {
Expand Down Expand Up @@ -126,5 +123,5 @@ test('[OptionsSelector] should scroll and press few items', () => {
fireEvent.press(screen.getByText('Item 200'));
};

measurePerformance(<OptionsSelectorWrapper sections={sections} />, {scenario, runs});
measurePerformance(<OptionsSelectorWrapper sections={sections} />, {scenario});
});
29 changes: 21 additions & 8 deletions tests/perf-test/ReportActionCompose.perf-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {LocaleContextProvider} from '../../src/components/LocaleContextProvider'
import OnyxProvider from '../../src/components/OnyxProvider';
import {KeyboardStateProvider} from '../../src/components/withKeyboardState';
import {WindowDimensionsProvider} from '../../src/components/withWindowDimensions';
import CONST from '../../src/CONST';
import * as Localize from '../../src/libs/Localize';
import ONYXKEYS from '../../src/ONYXKEYS';
import ReportActionCompose from '../../src/pages/home/report/ReportActionCompose/ReportActionCompose';
Expand Down Expand Up @@ -51,6 +50,22 @@ jest.mock('../../src/libs/actions/EmojiPickerAction', () => {
};
});

jest.mock('../../src/components/withNavigationFocus', () => (Component) => {
function WithNavigationFocus(props) {
return (
<Component
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
isFocused={false}
/>
);
}

WithNavigationFocus.displayName = 'WithNavigationFocus';

return WithNavigationFocus;
});

beforeAll(() =>
Onyx.init({
keys: ONYXKEYS,
Expand All @@ -64,8 +79,6 @@ beforeEach(() => {
Onyx.merge(ONYXKEYS.NETWORK, {isOffline: false});
});

const runs = CONST.PERFORMANCE_TESTS.RUNS;

function ReportActionComposeWrapper() {
return (
<ComposeProviders components={[OnyxProvider, LocaleContextProvider, KeyboardStateProvider, WindowDimensionsProvider]}>
Expand Down Expand Up @@ -96,7 +109,7 @@ test('[ReportActionCompose] should render Composer with text input interactions'
fireEvent.press(composer);
};

return waitForBatchedUpdates().then(() => measurePerformance(<ReportActionComposeWrapper />, {scenario, runs}));
return waitForBatchedUpdates().then(() => measurePerformance(<ReportActionComposeWrapper />, {scenario}));
});

test('[ReportActionCompose] should press add attachemnt button', async () => {
Expand All @@ -108,7 +121,7 @@ test('[ReportActionCompose] should press add attachemnt button', async () => {
fireEvent.press(attachmentButton, mockEvent);
};

return waitForBatchedUpdates().then(() => measurePerformance(<ReportActionComposeWrapper />, {scenario, runs}));
return waitForBatchedUpdates().then(() => measurePerformance(<ReportActionComposeWrapper />, {scenario}));
});

test('[ReportActionCompose] should press add emoji button', async () => {
Expand All @@ -120,7 +133,7 @@ test('[ReportActionCompose] should press add emoji button', async () => {
fireEvent.press(emojiButton);
};

return waitForBatchedUpdates().then(() => measurePerformance(<ReportActionComposeWrapper />, {scenario, runs}));
return waitForBatchedUpdates().then(() => measurePerformance(<ReportActionComposeWrapper />, {scenario}));
});

test('[ReportActionCompose] should press send message button', async () => {
Expand All @@ -132,7 +145,7 @@ test('[ReportActionCompose] should press send message button', async () => {
fireEvent.press(sendButton);
};

return waitForBatchedUpdates().then(() => measurePerformance(<ReportActionComposeWrapper />, {scenario, runs}));
return waitForBatchedUpdates().then(() => measurePerformance(<ReportActionComposeWrapper />, {scenario}));
});

test('[ReportActionCompose] render composer with attachement modal interactions', async () => {
Expand All @@ -152,5 +165,5 @@ test('[ReportActionCompose] render composer with attachement modal interactions'
fireEvent.press(assignTaskButton, mockEvent);
};

return waitForBatchedUpdates().then(() => measurePerformance(<ReportActionComposeWrapper />, {scenario, runs}));
return waitForBatchedUpdates().then(() => measurePerformance(<ReportActionComposeWrapper />, {scenario}));
});
7 changes: 2 additions & 5 deletions tests/perf-test/ReportActionsList.perf-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import ComposeProviders from '../../src/components/ComposeProviders';
import {LocaleContextProvider} from '../../src/components/LocaleContextProvider';
import OnyxProvider from '../../src/components/OnyxProvider';
import {WindowDimensionsProvider} from '../../src/components/withWindowDimensions';
import CONST from '../../src/CONST';
import * as Localize from '../../src/libs/Localize';
import ONYXKEYS from '../../src/ONYXKEYS';
import ReportActionsList from '../../src/pages/home/report/ReportActionsList';
Expand Down Expand Up @@ -97,8 +96,6 @@ function ReportActionsListWrapper() {
);
}

const runs = CONST.PERFORMANCE_TESTS.RUNS;

test('[ReportActionsList] should render ReportActionsList with 500 reportActions stored', () => {
const scenario = async () => {
await screen.findByTestId('report-actions-list');
Expand All @@ -113,7 +110,7 @@ test('[ReportActionsList] should render ReportActionsList with 500 reportActions
[ONYXKEYS.PERSONAL_DETAILS_LIST]: LHNTestUtils.fakePersonalDetails,
}),
)
.then(() => measurePerformance(<ReportActionsListWrapper />, {scenario, runs}));
.then(() => measurePerformance(<ReportActionsListWrapper />, {scenario}));
});

test('[ReportActionsList] should scroll and click some of the reports', () => {
Expand Down Expand Up @@ -151,5 +148,5 @@ test('[ReportActionsList] should scroll and click some of the reports', () => {
[ONYXKEYS.PERSONAL_DETAILS_LIST]: LHNTestUtils.fakePersonalDetails,
}),
)
.then(() => measurePerformance(<ReportActionsListWrapper />, {scenario, runs}));
.then(() => measurePerformance(<ReportActionsListWrapper />, {scenario}));
});
18 changes: 8 additions & 10 deletions tests/perf-test/ReportActionsUtils.perf-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ const reportActions = createCollection<ReportAction>(

const reportId = '1';

const runs = CONST.PERFORMANCE_TESTS.RUNS;

describe('ReportActionsUtils', () => {
beforeAll(() => {
Onyx.init({
Expand Down Expand Up @@ -65,7 +63,7 @@ describe('ReportActionsUtils', () => {
*/
test('[ReportActionsUtils] getLastVisibleAction on 10k reportActions', async () => {
await waitForBatchedUpdates();
await measureFunction(() => ReportActionsUtils.getLastVisibleAction(reportId), {runs});
await measureFunction(() => ReportActionsUtils.getLastVisibleAction(reportId));
});

test('[ReportActionsUtils] getLastVisibleAction on 10k reportActions with actionsToMerge', async () => {
Expand All @@ -91,19 +89,19 @@ describe('ReportActionsUtils', () => {
} as unknown as ReportActions;

await waitForBatchedUpdates();
await measureFunction(() => ReportActionsUtils.getLastVisibleAction(reportId, actionsToMerge), {runs});
await measureFunction(() => ReportActionsUtils.getLastVisibleAction(reportId, actionsToMerge));
});

test('[ReportActionsUtils] getMostRecentIOURequestActionID on 10k ReportActions', async () => {
const reportActionsArray = ReportActionsUtils.getSortedReportActionsForDisplay(reportActions);

await waitForBatchedUpdates();
await measureFunction(() => ReportActionsUtils.getMostRecentIOURequestActionID(reportActionsArray), {runs});
await measureFunction(() => ReportActionsUtils.getMostRecentIOURequestActionID(reportActionsArray));
});

test('[ReportActionsUtils] getLastVisibleMessage on 10k ReportActions', async () => {
await waitForBatchedUpdates();
await measureFunction(() => ReportActionsUtils.getLastVisibleMessage(reportId), {runs});
await measureFunction(() => ReportActionsUtils.getLastVisibleMessage(reportId));
});

test('[ReportActionsUtils] getLastVisibleMessage on 10k ReportActions with actionsToMerge', async () => {
Expand All @@ -129,21 +127,21 @@ describe('ReportActionsUtils', () => {
} as unknown as ReportActions;

await waitForBatchedUpdates();
await measureFunction(() => ReportActionsUtils.getLastVisibleMessage(reportId, actionsToMerge), {runs});
await measureFunction(() => ReportActionsUtils.getLastVisibleMessage(reportId, actionsToMerge));
});

test('[ReportActionsUtils] getSortedReportActionsForDisplay on 10k ReportActions', async () => {
await waitForBatchedUpdates();
await measureFunction(() => ReportActionsUtils.getSortedReportActionsForDisplay(reportActions), {runs});
await measureFunction(() => ReportActionsUtils.getSortedReportActionsForDisplay(reportActions));
});

test('[ReportActionsUtils] getLastClosedReportAction on 10k ReportActions', async () => {
await waitForBatchedUpdates();
await measureFunction(() => ReportActionsUtils.getLastClosedReportAction(reportActions), {runs});
await measureFunction(() => ReportActionsUtils.getLastClosedReportAction(reportActions));
});

test('[ReportActionsUtils] getMostRecentReportActionLastModified', async () => {
await waitForBatchedUpdates();
await measureFunction(() => ReportActionsUtils.getMostRecentReportActionLastModified(), {runs});
await measureFunction(() => ReportActionsUtils.getMostRecentReportActionLastModified());
});
});
6 changes: 2 additions & 4 deletions tests/perf-test/ReportScreen.perf-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@ function ReportScreenWrapper(args) {
);
}

const runs = CONST.PERFORMANCE_TESTS.RUNS;

test.skip('[ReportScreen] should render ReportScreen with composer interactions', () => {
const {triggerTransitionEnd, addListener} = createAddListenerMock();
const scenario = async () => {
Expand Down Expand Up @@ -222,7 +220,7 @@ test.skip('[ReportScreen] should render ReportScreen with composer interactions'
navigation={navigation}
route={mockRoute}
/>,
{scenario, runs},
{scenario},
),
);
});
Expand Down Expand Up @@ -287,7 +285,7 @@ test.skip('[ReportScreen] should press of the report item', () => {
navigation={navigation}
route={mockRoute}
/>,
{scenario, runs},
{scenario},
),
);
});
Loading

0 comments on commit d223824

Please sign in to comment.