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