From 27d14d31e7ead79fb9622b093d27a65af430af18 Mon Sep 17 00:00:00 2001 From: Github Date: Mon, 20 Nov 2023 14:06:39 +0100 Subject: [PATCH 1/2] add global config for timeouts --- jest.config.js | 2 +- .../perf-test/GooglePlacesUtils.perf-test.js | 2 -- .../ReportActionCompose.perf-test.js | 19 +++++++------------ .../perf-test/ReportActionsList.perf-test.js | 9 +++------ .../perf-test/ReportActionsUtils.perf-test.js | 2 -- tests/perf-test/ReportScreen.perf-test.js | 15 +++++---------- tests/perf-test/SelectionList.perf-test.js | 10 +++++----- tests/perf-test/SidebarLinks.perf-test.js | 14 ++++---------- tests/perf-test/setupAfterEnv.js | 7 +++++++ 9 files changed, 32 insertions(+), 48 deletions(-) create mode 100644 tests/perf-test/setupAfterEnv.js diff --git a/jest.config.js b/jest.config.js index efd72d20694f..611a0248b491 100644 --- a/jest.config.js +++ b/jest.config.js @@ -24,7 +24,7 @@ module.exports = { }, testEnvironment: 'jsdom', setupFiles: ['/jest/setup.js', './node_modules/@react-native-google-signin/google-signin/jest/build/setup.js'], - setupFilesAfterEnv: ['@testing-library/jest-native/extend-expect', '/jest/setupAfterEnv.js'], + setupFilesAfterEnv: ['@testing-library/jest-native/extend-expect', '/jest/setupAfterEnv.js', '/tests/perf-test/setupAfterEnv.js'], cacheDirectory: '/.jest-cache', moduleNameMapper: { '\\.(lottie)$': '/__mocks__/fileMock.js', diff --git a/tests/perf-test/GooglePlacesUtils.perf-test.js b/tests/perf-test/GooglePlacesUtils.perf-test.js index 92c3e0eb87b7..6c453ae9ddb3 100644 --- a/tests/perf-test/GooglePlacesUtils.perf-test.js +++ b/tests/perf-test/GooglePlacesUtils.perf-test.js @@ -1,8 +1,6 @@ import {measureFunction} from 'reassure'; import * as GooglePlacesUtils from '../../src/libs/GooglePlacesUtils'; -jest.setTimeout(60000); - const addressComponents = [ { long_name: 'Bushwick', diff --git a/tests/perf-test/ReportActionCompose.perf-test.js b/tests/perf-test/ReportActionCompose.perf-test.js index f50b378498e0..4280682c427b 100644 --- a/tests/perf-test/ReportActionCompose.perf-test.js +++ b/tests/perf-test/ReportActionCompose.perf-test.js @@ -13,8 +13,6 @@ import ReportActionCompose from '../../src/pages/home/report/ReportActionCompose import * as LHNTestUtils from '../utils/LHNTestUtils'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; -jest.setTimeout(60000); - // mock PortalStateContext jest.mock('@gorhom/portal'); @@ -69,6 +67,8 @@ beforeEach(() => { Onyx.merge(ONYXKEYS.NETWORK, {isOffline: false}); }); +const runs = 20; + function ReportActionComposeWrapper() { return ( @@ -87,8 +87,6 @@ test('should render Composer with text input interactions', async () => { const scenario = async () => { // Query for the composer const composer = await screen.findByTestId('composer'); - - expect(composer).toBeDefined(); fireEvent.changeText(composer, '@test'); // Query for the suggestions @@ -101,7 +99,7 @@ test('should render Composer with text input interactions', async () => { fireEvent.press(composer); }; - return waitForBatchedUpdates().then(() => measurePerformance(, {scenario})); + return waitForBatchedUpdates().then(() => measurePerformance(, {scenario, runs})); }); test('should press add attachemnt button', async () => { @@ -110,11 +108,10 @@ test('should press add attachemnt button', async () => { const hintAttachmentButtonText = Localize.translateLocal('reportActionCompose.addAction'); const attachmentButton = await screen.findByLabelText(hintAttachmentButtonText); - expect(attachmentButton).toBeDefined(); fireEvent.press(attachmentButton, mockEvent); }; - return waitForBatchedUpdates().then(() => measurePerformance(, {scenario})); + return waitForBatchedUpdates().then(() => measurePerformance(, {scenario, runs})); }); test('should press add emoji button', async () => { @@ -123,11 +120,10 @@ test('should press add emoji button', async () => { const hintEmojiButtonText = Localize.translateLocal('reportActionCompose.emoji'); const emojiButton = await screen.findByLabelText(hintEmojiButtonText); - expect(emojiButton).toBeDefined(); fireEvent.press(emojiButton); }; - return waitForBatchedUpdates().then(() => measurePerformance(, {scenario})); + return waitForBatchedUpdates().then(() => measurePerformance(, {scenario, runs})); }); test('should press send message button', async () => { @@ -136,11 +132,10 @@ test('should press send message button', async () => { const hintSendButtonText = Localize.translateLocal('common.send'); const sendButton = await screen.findByLabelText(hintSendButtonText); - expect(sendButton).toBeDefined(); fireEvent.press(sendButton); }; - return waitForBatchedUpdates().then(() => measurePerformance(, {scenario})); + return waitForBatchedUpdates().then(() => measurePerformance(, {scenario, runs})); }); test('render composer with attachement modal interactions', async () => { @@ -160,5 +155,5 @@ test('render composer with attachement modal interactions', async () => { fireEvent.press(assignTaskButton, mockEvent); }; - return waitForBatchedUpdates().then(() => measurePerformance(, {scenario})); + return waitForBatchedUpdates().then(() => measurePerformance(, {scenario, runs})); }); diff --git a/tests/perf-test/ReportActionsList.perf-test.js b/tests/perf-test/ReportActionsList.perf-test.js index 991ca82da1b6..fecc554010d7 100644 --- a/tests/perf-test/ReportActionsList.perf-test.js +++ b/tests/perf-test/ReportActionsList.perf-test.js @@ -17,8 +17,6 @@ import * as ReportTestUtils from '../utils/ReportTestUtils'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatchedUpdates'; -jest.setTimeout(60000); - const mockedNavigate = jest.fn(); jest.mock('../../src/components/withNavigationFocus', () => (Component) => { @@ -98,6 +96,7 @@ function ReportActionsListWrapper() { ); } +const runs = 20; test('should render ReportActionsList with 500 reportActions stored', () => { const scenario = async () => { await screen.findByTestId('report-actions-list'); @@ -112,7 +111,7 @@ test('should render ReportActionsList with 500 reportActions stored', () => { [ONYXKEYS.PERSONAL_DETAILS_LIST]: LHNTestUtils.fakePersonalDetails, }), ) - .then(() => measurePerformance(, {scenario})); + .then(() => measurePerformance(, {scenario, runs})); }); test('should scroll and click some of the reports', () => { @@ -136,8 +135,6 @@ test('should scroll and click some of the reports', () => { const scenario = async () => { const reportActionsList = await screen.findByTestId('report-actions-list'); - expect(reportActionsList).toBeDefined(); - fireEvent.scroll(reportActionsList, eventData); const hintText = Localize.translateLocal('accessibilityHints.chatMessage'); @@ -152,5 +149,5 @@ test('should scroll and click some of the reports', () => { [ONYXKEYS.PERSONAL_DETAILS_LIST]: LHNTestUtils.fakePersonalDetails, }), ) - .then(() => measurePerformance(, {scenario})); + .then(() => measurePerformance(, {scenario, runs})); }); diff --git a/tests/perf-test/ReportActionsUtils.perf-test.js b/tests/perf-test/ReportActionsUtils.perf-test.js index f643206c9f49..8e9f5570d5d8 100644 --- a/tests/perf-test/ReportActionsUtils.perf-test.js +++ b/tests/perf-test/ReportActionsUtils.perf-test.js @@ -7,8 +7,6 @@ import ONYXKEYS from '../../src/ONYXKEYS'; import * as LHNTestUtils from '../utils/LHNTestUtils'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; -jest.setTimeout(60000); - beforeAll(() => Onyx.init({ keys: ONYXKEYS, diff --git a/tests/perf-test/ReportScreen.perf-test.js b/tests/perf-test/ReportScreen.perf-test.js index 21537a7a5db7..ce4a8f76fdce 100644 --- a/tests/perf-test/ReportScreen.perf-test.js +++ b/tests/perf-test/ReportScreen.perf-test.js @@ -21,8 +21,6 @@ import * as TestHelper from '../utils/TestHelper'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatchedUpdates'; -jest.setTimeout(60000); - jest.mock('react-native-reanimated', () => ({ ...jest.requireActual('react-native-reanimated/mock'), useSharedValue: jest.fn, @@ -125,6 +123,8 @@ function ReportScreenWrapper(args) { ); } +const runs = 20; + test.skip('should render ReportScreen with composer interactions', () => { const scenario = async () => { // Query for the report list @@ -132,7 +132,6 @@ test.skip('should render ReportScreen with composer interactions', () => { // Query for the composer const composer = await screen.findByTestId('composer'); - expect(composer).toBeDefined(); // Type in the composer fireEvent.changeText(composer, 'Test message'); @@ -141,7 +140,6 @@ test.skip('should render ReportScreen with composer interactions', () => { // Query for the send button const sendButton = await screen.findByLabelText(hintSendButtonText); - expect(sendButton).toBeDefined(); // Click on the send button fireEvent.press(sendButton); @@ -149,8 +147,7 @@ test.skip('should render ReportScreen with composer interactions', () => { const hintHeaderText = Localize.translateLocal('common.back'); // Query for the header - const header = await screen.findByLabelText(hintHeaderText); - expect(header).toBeDefined(); + await screen.findByLabelText(hintHeaderText); }; const policy = { @@ -176,7 +173,7 @@ test.skip('should render ReportScreen with composer interactions', () => { }, }), ) - .then(() => measurePerformance(, {scenario})); + .then(() => measurePerformance(, {scenario, runs})); }); test.skip('should press of the report item', () => { @@ -192,8 +189,6 @@ test.skip('should press of the report item', () => { // Query for report preview buttons const reportPreviewButtons = await screen.findAllByLabelText(hintReportPreviewText); - expect(reportPreviewButtons.length).toBeDefined(); - // click on the report preview button fireEvent.press(reportPreviewButtons[0]); }; @@ -221,5 +216,5 @@ test.skip('should press of the report item', () => { }, }), ) - .then(() => measurePerformance(, {scenario})); + .then(() => measurePerformance(, {scenario, runs})); }); diff --git a/tests/perf-test/SelectionList.perf-test.js b/tests/perf-test/SelectionList.perf-test.js index 74069f782c1a..80ebf548c0b2 100644 --- a/tests/perf-test/SelectionList.perf-test.js +++ b/tests/perf-test/SelectionList.perf-test.js @@ -5,8 +5,6 @@ import _ from 'underscore'; import SelectionList from '../../src/components/SelectionList'; import variables from '../../src/styles/variables'; -jest.setTimeout(60000); - jest.mock('../../src/components/Icon/Expensicons'); jest.mock('../../src/hooks/useLocalize', () => @@ -94,6 +92,8 @@ function SelectionListWrapper(args) { ); } +const runs = 20; + test('should render 1 section and a thousand items', () => { measurePerformance(); }); @@ -103,7 +103,7 @@ test('should press a list item', () => { fireEvent.press(screen.getByText('Item 5')); }; - measurePerformance(, {scenario}); + measurePerformance(, {scenario, runs}); }); test('should render multiple selection and select 3 items', () => { @@ -113,7 +113,7 @@ test('should render multiple selection and select 3 items', () => { fireEvent.press(screen.getByText('Item 3')); }; - measurePerformance(, {scenario}); + measurePerformance(, {scenario, runs}); }); test('should scroll and select a few items', () => { @@ -142,5 +142,5 @@ test('should scroll and select a few items', () => { fireEvent.press(screen.getByText('Item 15')); }; - measurePerformance(, {scenario}); + measurePerformance(, {scenario, runs}); }); diff --git a/tests/perf-test/SidebarLinks.perf-test.js b/tests/perf-test/SidebarLinks.perf-test.js index f6819d40a48f..5d116056c7a5 100644 --- a/tests/perf-test/SidebarLinks.perf-test.js +++ b/tests/perf-test/SidebarLinks.perf-test.js @@ -9,13 +9,6 @@ import * as LHNTestUtils from '../utils/LHNTestUtils'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatchedUpdates'; -/** - * Performance tests with Reassure can require big timeouts as all runs - * for a test have to be executed within this limit. (default runs=10) - * This also includes manual garbage collection between them. - */ -jest.setTimeout(60000); - jest.mock('../../src/libs/Permissions'); jest.mock('../../src/libs/Navigation/Navigation'); jest.mock('../../src/components/Icon/Expensicons'); @@ -56,6 +49,8 @@ const getMockedReportsMap = (length = 100) => { const mockedResponseMap = getMockedReportsMap(500); +const runs = 20; + test('should render Sidebar with 500 reports stored', () => { const scenario = async () => { // Query for the sidebar @@ -78,7 +73,7 @@ test('should render Sidebar with 500 reports stored', () => { ...mockedResponseMap, }), ) - .then(() => measurePerformance(, {scenario})); + .then(() => measurePerformance(, {scenario, runs})); }); test('should scroll and click some of the items', () => { @@ -102,7 +97,6 @@ test('should scroll and click some of the items', () => { }; const lhnOptionsList = await screen.findByTestId('lhn-options-list'); - expect(lhnOptionsList).toBeDefined(); fireEvent.scroll(lhnOptionsList, eventData); @@ -123,5 +117,5 @@ test('should scroll and click some of the items', () => { ...mockedResponseMap, }), ) - .then(() => measurePerformance(, {scenario})); + .then(() => measurePerformance(, {scenario, runs})); }); diff --git a/tests/perf-test/setupAfterEnv.js b/tests/perf-test/setupAfterEnv.js new file mode 100644 index 000000000000..43536333c541 --- /dev/null +++ b/tests/perf-test/setupAfterEnv.js @@ -0,0 +1,7 @@ +/** + * Performance tests with Reassure can require big timeouts as all runs + * for a test have to be executed within this limit. (default runs=10) + * This also includes manual garbage collection between them. + */ + +jest.setTimeout(240000); // 4 minutes From 060a46c571de2844124b2a37d85b1f9c650c14c1 Mon Sep 17 00:00:00 2001 From: Github Date: Mon, 20 Nov 2023 18:28:46 +0100 Subject: [PATCH 2/2] cr fix --- src/CONST.ts | 7 +++++++ tests/perf-test/ReportActionCompose.perf-test.js | 3 ++- tests/perf-test/ReportActionsList.perf-test.js | 4 +++- tests/perf-test/ReportScreen.perf-test.js | 2 +- tests/perf-test/SelectionList.perf-test.js | 3 ++- tests/perf-test/SidebarLinks.perf-test.js | 2 +- 6 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index 22547a5954ae..47ab30589612 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -2901,6 +2901,13 @@ const CONST = { }, BACK_BUTTON_NATIVE_ID: 'backButton', + + /** + * Performance test setup - run the same test multiple times to get a more accurate result + */ + PERFORMANCE_TESTS: { + RUNS: 20, + }, } as const; export default CONST; diff --git a/tests/perf-test/ReportActionCompose.perf-test.js b/tests/perf-test/ReportActionCompose.perf-test.js index 4280682c427b..6419d8f895ef 100644 --- a/tests/perf-test/ReportActionCompose.perf-test.js +++ b/tests/perf-test/ReportActionCompose.perf-test.js @@ -7,6 +7,7 @@ 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'; @@ -67,7 +68,7 @@ beforeEach(() => { Onyx.merge(ONYXKEYS.NETWORK, {isOffline: false}); }); -const runs = 20; +const runs = CONST.PERFORMANCE_TESTS.RUNS; function ReportActionComposeWrapper() { return ( diff --git a/tests/perf-test/ReportActionsList.perf-test.js b/tests/perf-test/ReportActionsList.perf-test.js index fecc554010d7..ee0fdcb135fc 100644 --- a/tests/perf-test/ReportActionsList.perf-test.js +++ b/tests/perf-test/ReportActionsList.perf-test.js @@ -5,6 +5,7 @@ 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'; @@ -96,7 +97,8 @@ function ReportActionsListWrapper() { ); } -const runs = 20; +const runs = CONST.PERFORMANCE_TESTS.RUNS; + test('should render ReportActionsList with 500 reportActions stored', () => { const scenario = async () => { await screen.findByTestId('report-actions-list'); diff --git a/tests/perf-test/ReportScreen.perf-test.js b/tests/perf-test/ReportScreen.perf-test.js index ce4a8f76fdce..f8a44b54cc39 100644 --- a/tests/perf-test/ReportScreen.perf-test.js +++ b/tests/perf-test/ReportScreen.perf-test.js @@ -123,7 +123,7 @@ function ReportScreenWrapper(args) { ); } -const runs = 20; +const runs = CONST.PERFORMANCE_TESTS.RUNS; test.skip('should render ReportScreen with composer interactions', () => { const scenario = async () => { diff --git a/tests/perf-test/SelectionList.perf-test.js b/tests/perf-test/SelectionList.perf-test.js index 80ebf548c0b2..fd607269ec6e 100644 --- a/tests/perf-test/SelectionList.perf-test.js +++ b/tests/perf-test/SelectionList.perf-test.js @@ -3,6 +3,7 @@ import React, {useState} from 'react'; import {measurePerformance} from 'reassure'; import _ from 'underscore'; import SelectionList from '../../src/components/SelectionList'; +import CONST from '../../src/CONST'; import variables from '../../src/styles/variables'; jest.mock('../../src/components/Icon/Expensicons'); @@ -92,7 +93,7 @@ function SelectionListWrapper(args) { ); } -const runs = 20; +const runs = CONST.PERFORMANCE_TESTS.RUNS; test('should render 1 section and a thousand items', () => { measurePerformance(); diff --git a/tests/perf-test/SidebarLinks.perf-test.js b/tests/perf-test/SidebarLinks.perf-test.js index 5d116056c7a5..eef10501d2ef 100644 --- a/tests/perf-test/SidebarLinks.perf-test.js +++ b/tests/perf-test/SidebarLinks.perf-test.js @@ -49,7 +49,7 @@ const getMockedReportsMap = (length = 100) => { const mockedResponseMap = getMockedReportsMap(500); -const runs = 20; +const runs = CONST.PERFORMANCE_TESTS.RUNS; test('should render Sidebar with 500 reports stored', () => { const scenario = async () => {