Skip to content

Commit

Permalink
add global config for timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
OlimpiaZurek committed Nov 22, 2023
1 parent f6ef8b8 commit 27d14d3
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 48 deletions.
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
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
19 changes: 7 additions & 12 deletions tests/perf-test/ReportActionCompose.perf-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

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

const runs = 20;

function ReportActionComposeWrapper() {
return (
<ComposeProviders components={[OnyxProvider, LocaleContextProvider, KeyboardStateProvider, WindowDimensionsProvider]}>
Expand All @@ -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
Expand All @@ -101,7 +99,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 +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(<ReportActionComposeWrapper />, {scenario}));
return waitForBatchedUpdates().then(() => measurePerformance(<ReportActionComposeWrapper />, {scenario, runs}));
});

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

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

test('render composer with attachement modal interactions', async () => {
Expand All @@ -160,5 +155,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}));
});
9 changes: 3 additions & 6 deletions tests/perf-test/ReportActionsList.perf-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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');
Expand All @@ -112,7 +111,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 +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');
Expand All @@ -152,5 +149,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 = 20;

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}));
});
10 changes: 5 additions & 5 deletions tests/perf-test/SelectionList.perf-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () =>
Expand Down Expand Up @@ -94,6 +92,8 @@ function SelectionListWrapper(args) {
);
}

const runs = 20;

test('should render 1 section and a thousand items', () => {
measurePerformance(<SelectionListWrapper />);
});
Expand All @@ -103,7 +103,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 +113,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 +142,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 = 20;

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

0 comments on commit 27d14d3

Please sign in to comment.