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

Fix flaky tests #882

Merged
merged 1 commit into from
Jul 23, 2024
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: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
"sign": "npx --yes @grafana/sign-plugin@latest",
"spellcheck": "cspell -c cspell.config.json \"**/*.{ts,tsx,js,go,md,mdx,yml,yaml,json,scss,css}\"",
"test": "jest --all",
"test:accessibility": "pa11y --runner axe --reporter json http://localhost:3000/a/grafana-synthetic-monitoring-app/?page=checks > pa11y-report.json",
"test:ci": "jest --passWithNoTests --maxWorkers 4",
"test:changed": "jest --watch --onlyChanged",
"typecheck": "tsc --noEmit"
},
Expand Down
2 changes: 0 additions & 2 deletions src/components/CheckList/CheckList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ jest.mock('hooks/useNavigation', () => {
});
const useNavigationHook = require('hooks/useNavigation');

jest.setTimeout(20000);

const renderCheckList = async (checks = BASIC_CHECK_LIST, searchParams = '') => {
server.use(
apiRoute(`listChecks`, {
Expand Down
1 change: 0 additions & 1 deletion src/page/AlertingPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const useAlertsHook = require('hooks/useAlerts');
const { defaultRules } = jest.requireActual('hooks/useAlerts');
const setDefaultRules = jest.fn();
const setRules = jest.fn().mockImplementation(() => Promise.resolve({ ok: true }));
jest.setTimeout(30000);

const renderAlerting = () => {
return render(<AlertingPage />);
Expand Down
5 changes: 1 addition & 4 deletions src/page/ChecksPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ import { PLUGIN_URL_PATH } from 'components/Routing.consts';

import { CheckRouter } from './CheckRouter';

jest.setTimeout(20000);

const renderChecksPage = async () => {
const res = render(<CheckRouter />, {
path: `${PLUGIN_URL_PATH}${ROUTES.Checks}`,
route: `${PLUGIN_URL_PATH}${ROUTES.Checks}`,
});

await waitFor(() => expect(screen.getByText('Add new check')).toBeInTheDocument());
await waitFor(() => expect(screen.getByText('Add new check')).toBeInTheDocument(), { timeout: 10000 });
return res;
};

Expand Down Expand Up @@ -150,7 +148,6 @@ test(`renders retry button when unable to fetch alerts`, async () => {
);

const { user } = await renderChecksPage();
await waitFor(() => {}, { timeout: 10000 });
const refetchButton = await screen.findByLabelText('Unable to fetch alerting rules. Retry?');

server.use(
Expand Down
21 changes: 18 additions & 3 deletions src/page/__testHelpers__/checkForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { screen, within } from '@testing-library/react';
import { act, screen, waitFor, within } from '@testing-library/react';
import { UserEvent } from '@testing-library/user-event';
import { DataTestIds } from 'test/dataTestIds';
import { apiRoute, getServerRequests } from 'test/handlers';
Expand Down Expand Up @@ -33,11 +33,26 @@ export async function renderNewForm(checkType: CheckType) {
path: `${PLUGIN_URL_PATH}${ROUTES.NewCheck}/${checkTypeGroup}?checkType=${checkType}`,
});

await screen.findByTestId(DataTestIds.PAGE_READY);
await waitFor(async () => await screen.findByTestId(DataTestIds.PAGE_READY), { timeout: 10000 });

const typeButReallyPaste = async (target: Element, value: string, args?: any) => {
if (target instanceof HTMLElement) {
await act(() => {
target.focus();
});
await res.user.paste(value);
}
};

const user: UserEvent = {
...res.user,
type: typeButReallyPaste,
};

return {
...res,
read,
user,
};
}

Expand All @@ -52,7 +67,7 @@ export async function renderEditForm(check: Pick<Check, 'id' | 'settings'>) {
path: `${PLUGIN_URL_PATH}${ROUTES.EditCheck}/edit/${checkTypeGroup}/${check.id}`,
});

await screen.findByText(/^Editing/);
await waitFor(async () => await screen.findByText(/^Editing/), { timeout: 10000 });

return {
...res,
Expand Down
Loading