Skip to content
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
19 changes: 15 additions & 4 deletions packages/webapp/__tests__/MostDiscussedPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { MOST_DISCUSSED_FEED_QUERY } from '@dailydotdev/shared/src/graphql/feed'
import nock from 'nock';
import React from 'react';
import type { RenderResult } from '@testing-library/react';
import { render, screen, waitFor } from '@testing-library/react';
import { render, screen } from '@testing-library/react';
import { QueryClient } from '@tanstack/react-query';
import type { LoggedUser } from '@dailydotdev/shared/src/lib/user';
import type { NextRouter } from 'next/router';
Expand All @@ -19,6 +19,17 @@ import { COMMENT_FEED_QUERY } from '@dailydotdev/shared/src/graphql/comments';
import Discussed from '../pages/discussed';
import { defaultCommentsPage } from './ProfileRepliesPage';

// Compiling the feed module graph takes seconds on a cold jest transform cache,
// so both the compile in beforeAll and the render need more than the defaults.
jest.setTimeout(30000);
const feedTimeout = 5000;

beforeAll(async () => {
// MainFeedLayout only reaches the page through next/dynamic, so without this
// its compile lands inside the first findBy* wait and eats the whole budget.
await import('@dailydotdev/shared/src/components/MainFeedLayout');
});

beforeEach(() => {
jest.restoreAllMocks();
jest.clearAllMocks();
Expand Down Expand Up @@ -92,10 +103,10 @@ function renderComponent(

it('should request most discussed feed when logged-in', async () => {
renderComponent([createCommentFeedMock()]);
await waitFor(async () => {
const elements = await screen.findAllByTestId('comment');
expect(elements.length).toBeTruthy();
const elements = await screen.findAllByTestId('comment', undefined, {
timeout: feedTimeout,
});
expect(elements.length).toBeTruthy();
});

it('should not request most discussed feed when not logged-in', async () => {
Expand Down
22 changes: 18 additions & 4 deletions packages/webapp/__tests__/MostUpvotedPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ import { mockGraphQL } from '@dailydotdev/shared/__tests__/helpers/graphql';
import { TestBootProvider } from '@dailydotdev/shared/__tests__/helpers/boot';
import Upvoted from '../pages/upvoted';

// Compiling the feed module graph takes seconds on a cold jest transform cache,
// so both the compile in beforeAll and the render need more than the defaults.
jest.setTimeout(30000);
const feedTimeout = 5000;

beforeAll(async () => {
// MainFeedLayout only reaches the page through next/dynamic, so without this
// its compile lands inside the first findBy* wait and eats the whole budget.
await import('@dailydotdev/shared/src/components/MainFeedLayout');
});

afterEach(() => {
nock.cleanAll();
});
Expand Down Expand Up @@ -92,7 +103,7 @@ it('should request most upvoted feed when logged-in', async () => {
() => {
expect(screen.getAllByTestId('postItem').length).toBeTruthy();
},
{ timeout: 3000 },
{ timeout: feedTimeout },
);
});

Expand All @@ -110,7 +121,10 @@ it('should request most upvoted feed when not', async () => {
],
undefined,
);
await waitFor(() => {
expect(screen.getAllByTestId('postItem').length).toBeTruthy();
});
await waitFor(
() => {
expect(screen.getAllByTestId('postItem').length).toBeTruthy();
},
{ timeout: feedTimeout },
);
});
20 changes: 16 additions & 4 deletions packages/webapp/__tests__/MyFeedPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,16 @@ let defaultAlerts: Alerts = { filter: true };
const updateAlerts = jest.fn();
const originalScrollTo = window.scrollTo;

beforeAll(() => {
// Compiling the feed module graph takes seconds on a cold jest transform cache,
// so both the compile in beforeAll and the render need more than the defaults.
jest.setTimeout(30000);
const feedTimeout = 5000;

beforeAll(async () => {
window.scrollTo = jest.fn();
// MainFeedLayout only reaches the page through next/dynamic, so without this
// its compile lands inside the first findBy* wait and eats the whole budget.
await import('@dailydotdev/shared/src/components/MainFeedLayout');
});

afterAll(() => {
Expand Down Expand Up @@ -144,7 +152,9 @@ it('should request user feed', async () => {
});

renderComponent([]);
const elements = await screen.findAllByTestId('postItem');
const elements = await screen.findAllByTestId('postItem', undefined, {
timeout: feedTimeout,
});
expect(elements.length).toBeTruthy();
await waitFor(() => {
expect(graphQLRequests).toHaveLength(1);
Expand Down Expand Up @@ -174,7 +184,9 @@ it('should request anonymous my feed', async () => {
],
undefined,
);
await waitForNock();
const elements = await screen.findAllByTestId('postItem');
const elements = await screen.findAllByTestId('postItem', undefined, {
timeout: feedTimeout,
});
expect(elements.length).toBeTruthy();
await waitForNock();
});
15 changes: 14 additions & 1 deletion packages/webapp/__tests__/PopularPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ import { mockGraphQL } from '@dailydotdev/shared/__tests__/helpers/graphql';
import { TestBootProvider } from '@dailydotdev/shared/__tests__/helpers/boot';
import Popular from '../pages/popular';

// Compiling the feed module graph takes seconds on a cold jest transform cache,
// so both the compile in beforeAll and the render need more than the defaults.
jest.setTimeout(30000);
const feedTimeout = 5000;

beforeAll(async () => {
// MainFeedLayout only reaches the page through next/dynamic, so without this
// its compile lands inside the first findBy* wait and eats the whole budget.
await import('@dailydotdev/shared/src/components/MainFeedLayout');
});

beforeEach(() => {
jest.restoreAllMocks();
jest.clearAllMocks();
Expand Down Expand Up @@ -86,6 +97,8 @@ it('should request anonymous popular feed', async () => {
],
undefined,
);
const elements = await screen.findAllByTestId('postItem');
const elements = await screen.findAllByTestId('postItem', undefined, {
timeout: feedTimeout,
});
expect(elements.length).toBeTruthy();
});
Loading