Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NoQA] add global config for timeouts #31549

Merged
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
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = {
},
testEnvironment: 'jsdom',
setupFiles: ['<rootDir>/jest/setup.js', './node_modules/@react-native-google-signin/google-signin/jest/build/setup.js'],
setupFilesAfterEnv: ['@testing-library/jest-native/extend-expect', '<rootDir>/jest/setupAfterEnv.js'],
setupFilesAfterEnv: ['@testing-library/jest-native/extend-expect', '<rootDir>/jest/setupAfterEnv.js', '<rootDir>/tests/perf-test/setupAfterEnv.js'],
cacheDirectory: '<rootDir>/.jest-cache',
moduleNameMapper: {
'\\.(lottie)$': '<rootDir>/__mocks__/fileMock.js',
Expand Down
7 changes: 7 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 0 additions & 2 deletions tests/perf-test/GooglePlacesUtils.perf-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import {measureFunction} from 'reassure';
import * as GooglePlacesUtils from '../../src/libs/GooglePlacesUtils';

jest.setTimeout(60000);

const addressComponents = [
{
long_name: 'Bushwick',
Expand Down
20 changes: 8 additions & 12 deletions tests/perf-test/ReportActionCompose.perf-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ 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';
import * as LHNTestUtils from '../utils/LHNTestUtils';
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';

jest.setTimeout(60000);

// mock PortalStateContext
jest.mock('@gorhom/portal');

Expand Down Expand Up @@ -69,6 +68,8 @@ beforeEach(() => {
Onyx.merge(ONYXKEYS.NETWORK, {isOffline: false});
});

const runs = CONST.PERFORMANCE_TESTS.RUNS;

function ReportActionComposeWrapper() {
return (
<ComposeProviders components={[OnyxProvider, LocaleContextProvider, KeyboardStateProvider, WindowDimensionsProvider]}>
Expand All @@ -87,8 +88,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
Expand All @@ -101,7 +100,7 @@ test('should render Composer with text input interactions', async () => {
fireEvent.press(composer);
};

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

test('should press add attachemnt button', async () => {
Expand All @@ -110,11 +109,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(<ReportActionComposeWrapper />, {scenario}));
return waitForBatchedUpdates().then(() => measurePerformance(<ReportActionComposeWrapper />, {scenario, runs}));
});

test('should press add emoji button', async () => {
Expand All @@ -123,11 +121,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(<ReportActionComposeWrapper />, {scenario}));
return waitForBatchedUpdates().then(() => measurePerformance(<ReportActionComposeWrapper />, {scenario, runs}));
});

test('should press send message button', async () => {
Expand All @@ -136,11 +133,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(<ReportActionComposeWrapper />, {scenario}));
return waitForBatchedUpdates().then(() => measurePerformance(<ReportActionComposeWrapper />, {scenario, runs}));
});

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

return waitForBatchedUpdates().then(() => measurePerformance(<ReportActionComposeWrapper />, {scenario}));
return waitForBatchedUpdates().then(() => measurePerformance(<ReportActionComposeWrapper />, {scenario, runs}));
});
11 changes: 5 additions & 6 deletions tests/perf-test/ReportActionsList.perf-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -17,8 +18,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) => {
Expand Down Expand Up @@ -98,6 +97,8 @@ function ReportActionsListWrapper() {
);
}

const runs = CONST.PERFORMANCE_TESTS.RUNS;

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

test('should scroll and click some of the reports', () => {
Expand All @@ -136,8 +137,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');
Expand All @@ -152,5 +151,5 @@ test('should scroll and click some of the reports', () => {
[ONYXKEYS.PERSONAL_DETAILS_LIST]: LHNTestUtils.fakePersonalDetails,
}),
)
.then(() => measurePerformance(<ReportActionsListWrapper />, {scenario}));
.then(() => measurePerformance(<ReportActionsListWrapper />, {scenario, runs}));
});
2 changes: 0 additions & 2 deletions tests/perf-test/ReportActionsUtils.perf-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 5 additions & 10 deletions tests/perf-test/ReportScreen.perf-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -125,14 +123,15 @@ function ReportScreenWrapper(args) {
);
}

const runs = CONST.PERFORMANCE_TESTS.RUNS;

test.skip('should render ReportScreen with composer interactions', () => {
const scenario = async () => {
// Query for the report list
await screen.findByTestId('report-actions-list');

// Query for the composer
const composer = await screen.findByTestId('composer');
expect(composer).toBeDefined();

// Type in the composer
fireEvent.changeText(composer, 'Test message');
Expand All @@ -141,16 +140,14 @@ 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);

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 = {
Expand All @@ -176,7 +173,7 @@ test.skip('should render ReportScreen with composer interactions', () => {
},
}),
)
.then(() => measurePerformance(<ReportScreenWrapper route={mockRoute} />, {scenario}));
.then(() => measurePerformance(<ReportScreenWrapper route={mockRoute} />, {scenario, runs}));
});

test.skip('should press of the report item', () => {
Expand All @@ -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]);
};
Expand Down Expand Up @@ -221,5 +216,5 @@ test.skip('should press of the report item', () => {
},
}),
)
.then(() => measurePerformance(<ReportScreenWrapper route={mockRoute} />, {scenario}));
.then(() => measurePerformance(<ReportScreenWrapper route={mockRoute} />, {scenario, runs}));
});
11 changes: 6 additions & 5 deletions tests/perf-test/SelectionList.perf-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ 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.setTimeout(60000);

jest.mock('../../src/components/Icon/Expensicons');

jest.mock('../../src/hooks/useLocalize', () =>
Expand Down Expand Up @@ -94,6 +93,8 @@ function SelectionListWrapper(args) {
);
}

const runs = CONST.PERFORMANCE_TESTS.RUNS;

test('should render 1 section and a thousand items', () => {
measurePerformance(<SelectionListWrapper />);
});
Expand All @@ -103,7 +104,7 @@ test('should press a list item', () => {
fireEvent.press(screen.getByText('Item 5'));
};

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

test('should render multiple selection and select 3 items', () => {
Expand All @@ -113,7 +114,7 @@ test('should render multiple selection and select 3 items', () => {
fireEvent.press(screen.getByText('Item 3'));
};

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

test('should scroll and select a few items', () => {
Expand Down Expand Up @@ -142,5 +143,5 @@ test('should scroll and select a few items', () => {
fireEvent.press(screen.getByText('Item 15'));
};

measurePerformance(<SelectionListWrapper canSelectMultiple />, {scenario});
measurePerformance(<SelectionListWrapper canSelectMultiple />, {scenario, runs});
});
14 changes: 4 additions & 10 deletions tests/perf-test/SidebarLinks.perf-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -56,6 +49,8 @@ const getMockedReportsMap = (length = 100) => {

const mockedResponseMap = getMockedReportsMap(500);

const runs = CONST.PERFORMANCE_TESTS.RUNS;

test('should render Sidebar with 500 reports stored', () => {
const scenario = async () => {
// Query for the sidebar
Expand All @@ -78,7 +73,7 @@ test('should render Sidebar with 500 reports stored', () => {
...mockedResponseMap,
}),
)
.then(() => measurePerformance(<LHNTestUtils.MockedSidebarLinks />, {scenario}));
.then(() => measurePerformance(<LHNTestUtils.MockedSidebarLinks />, {scenario, runs}));
});

test('should scroll and click some of the items', () => {
Expand All @@ -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);

Expand All @@ -123,5 +117,5 @@ test('should scroll and click some of the items', () => {
...mockedResponseMap,
}),
)
.then(() => measurePerformance(<LHNTestUtils.MockedSidebarLinks />, {scenario}));
.then(() => measurePerformance(<LHNTestUtils.MockedSidebarLinks />, {scenario, runs}));
});
7 changes: 7 additions & 0 deletions tests/perf-test/setupAfterEnv.js
Original file line number Diff line number Diff line change
@@ -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
Loading