aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web
diff options
context:
space:
mode:
authorWouter Admiraal <wouter.admiraal@sonarsource.com>2023-06-27 09:17:29 +0200
committersonartech <sonartech@sonarsource.com>2023-06-29 20:05:13 +0000
commitd4def4920788a250a674cf2c89915e46da8467b6 (patch)
tree1c73810298b19965c1d09c0adc155fa098b0eaeb /server/sonar-web
parentdc1d66355084fa919c0f734a58ea73da133aabc8 (diff)
downloadsonarqube-d4def4920788a250a674cf2c89915e46da8467b6.tar.gz
sonarqube-d4def4920788a250a674cf2c89915e46da8467b6.zip
[NO-JIRA] Use runOnlyPendingTimers together with useRealTimers
Diffstat (limited to 'server/sonar-web')
-rw-r--r--server/sonar-web/design-system/src/components/__tests__/DateRangePicker-test.tsx5
-rw-r--r--server/sonar-web/design-system/src/components/__tests__/DeferredSpinner-test.tsx5
-rw-r--r--server/sonar-web/design-system/src/components/__tests__/MultiSelectMenu-test.tsx5
-rw-r--r--server/sonar-web/design-system/src/helpers/testUtils.tsx14
-rw-r--r--server/sonar-web/src/main/js/app/components/__tests__/PageTracker-test.tsx10
-rw-r--r--server/sonar-web/src/main/js/apps/maintenance/components/__tests__/App-test.tsx15
-rw-r--r--server/sonar-web/src/main/js/apps/projectBranches/__tests__/ProjectBranchesApp-it.tsx10
-rw-r--r--server/sonar-web/src/main/js/apps/projectDump/__tests__/ProjectDumpApp-it.tsx9
-rw-r--r--server/sonar-web/src/main/js/apps/projectsManagement/__tests__/ProjectManagementApp-it.tsx5
-rw-r--r--server/sonar-web/src/main/js/apps/settings/components/authentication/__tests__/Authentication-it.tsx7
-rw-r--r--server/sonar-web/src/main/js/apps/users/__tests__/UsersApp-it.tsx5
-rw-r--r--server/sonar-web/src/main/js/components/controls/__tests__/Toggler-test.tsx5
-rw-r--r--server/sonar-web/src/main/js/components/controls/__tests__/Tooltip-test.tsx7
-rw-r--r--server/sonar-web/src/main/js/components/controls/__tests__/clipboard-test.tsx4
-rw-r--r--server/sonar-web/src/main/js/components/ui/__tests__/DeferredSpinner-test.tsx5
-rw-r--r--server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceRuleViewer-test.tsx4
-rw-r--r--server/sonar-web/src/main/js/helpers/__tests__/error-test.ts7
-rw-r--r--server/sonar-web/src/main/js/helpers/__tests__/request-test.ts9
18 files changed, 61 insertions, 70 deletions
diff --git a/server/sonar-web/design-system/src/components/__tests__/DateRangePicker-test.tsx b/server/sonar-web/design-system/src/components/__tests__/DateRangePicker-test.tsx
index 355dd21c244..6710f23ce0a 100644
--- a/server/sonar-web/design-system/src/components/__tests__/DateRangePicker-test.tsx
+++ b/server/sonar-web/design-system/src/components/__tests__/DateRangePicker-test.tsx
@@ -23,11 +23,12 @@ import { formatISO, parseISO } from 'date-fns';
import { render } from '../../helpers/testUtils';
import { DateRangePicker } from '../DateRangePicker';
-beforeAll(() => {
+beforeEach(() => {
jest.useFakeTimers().setSystemTime(parseISO('2022-06-12'));
});
-afterAll(() => {
+afterEach(() => {
+ jest.runOnlyPendingTimers();
jest.useRealTimers();
});
diff --git a/server/sonar-web/design-system/src/components/__tests__/DeferredSpinner-test.tsx b/server/sonar-web/design-system/src/components/__tests__/DeferredSpinner-test.tsx
index f78c026d694..9e5b35753b2 100644
--- a/server/sonar-web/design-system/src/components/__tests__/DeferredSpinner-test.tsx
+++ b/server/sonar-web/design-system/src/components/__tests__/DeferredSpinner-test.tsx
@@ -20,15 +20,12 @@
import { render, screen } from '@testing-library/react';
import { DeferredSpinner } from '../DeferredSpinner';
-beforeAll(() => {
+beforeEach(() => {
jest.useFakeTimers();
});
afterEach(() => {
jest.runOnlyPendingTimers();
-});
-
-afterAll(() => {
jest.useRealTimers();
});
diff --git a/server/sonar-web/design-system/src/components/__tests__/MultiSelectMenu-test.tsx b/server/sonar-web/design-system/src/components/__tests__/MultiSelectMenu-test.tsx
index e2077ecf2a0..a1c7b5800ea 100644
--- a/server/sonar-web/design-system/src/components/__tests__/MultiSelectMenu-test.tsx
+++ b/server/sonar-web/design-system/src/components/__tests__/MultiSelectMenu-test.tsx
@@ -23,11 +23,12 @@ import { MultiSelectMenu } from '../MultiSelectMenu';
const elements = ['foo', 'bar', 'baz'];
-beforeAll(() => {
+beforeEach(() => {
jest.useFakeTimers();
});
-afterAll(() => {
+afterEach(() => {
+ jest.runOnlyPendingTimers();
jest.useRealTimers();
});
diff --git a/server/sonar-web/design-system/src/helpers/testUtils.tsx b/server/sonar-web/design-system/src/helpers/testUtils.tsx
index 275881c194a..516c427ba51 100644
--- a/server/sonar-web/design-system/src/helpers/testUtils.tsx
+++ b/server/sonar-web/design-system/src/helpers/testUtils.tsx
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { render as rtlRender, RenderOptions } from '@testing-library/react';
+import { RenderOptions, render as rtlRender } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { Options as UserEventsOptions } from '@testing-library/user-event/dist/types/options';
import { InitialEntry } from 'history';
@@ -113,15 +113,3 @@ export const debounceTimer = jest
return debounced;
});
-
-export function flushPromises(usingFakeTime = false): Promise<void> {
- return new Promise((resolve) => {
- if (usingFakeTime) {
- jest.useRealTimers();
- }
- setTimeout(resolve, 0);
- if (usingFakeTime) {
- jest.useFakeTimers();
- }
- });
-}
diff --git a/server/sonar-web/src/main/js/app/components/__tests__/PageTracker-test.tsx b/server/sonar-web/src/main/js/app/components/__tests__/PageTracker-test.tsx
index a4a58383af3..10504a10e74 100644
--- a/server/sonar-web/src/main/js/app/components/__tests__/PageTracker-test.tsx
+++ b/server/sonar-web/src/main/js/app/components/__tests__/PageTracker-test.tsx
@@ -32,20 +32,16 @@ jest.mock('../../../helpers/extensionsHandler', () => ({
getWebAnalyticsPageHandlerFromCache: jest.fn().mockReturnValue(undefined),
}));
-beforeAll(() => {
+beforeEach(() => {
+ jest.clearAllMocks();
jest.useFakeTimers();
});
-afterAll(() => {
+afterEach(() => {
jest.runOnlyPendingTimers();
jest.useRealTimers();
});
-beforeEach(() => {
- jest.clearAllTimers();
- jest.clearAllMocks();
-});
-
it('should not trigger if no analytics system is given', () => {
const wrapper = shallowRender();
expect(wrapper).toMatchSnapshot();
diff --git a/server/sonar-web/src/main/js/apps/maintenance/components/__tests__/App-test.tsx b/server/sonar-web/src/main/js/apps/maintenance/components/__tests__/App-test.tsx
index dff9de6fb79..5b5ed01c8f1 100644
--- a/server/sonar-web/src/main/js/apps/maintenance/components/__tests__/App-test.tsx
+++ b/server/sonar-web/src/main/js/apps/maintenance/components/__tests__/App-test.tsx
@@ -40,8 +40,6 @@ const originalLocation = window.location;
const replace = jest.fn();
beforeAll(() => {
- jest.useFakeTimers();
-
const location = {
...window.location,
replace,
@@ -53,16 +51,21 @@ beforeAll(() => {
});
afterAll(() => {
- jest.runOnlyPendingTimers();
- jest.useRealTimers();
-
Object.defineProperty(window, 'location', {
writable: true,
value: originalLocation,
});
});
-beforeEach(jest.clearAllMocks);
+beforeEach(() => {
+ jest.clearAllMocks();
+ jest.useFakeTimers();
+});
+
+afterEach(() => {
+ jest.runOnlyPendingTimers();
+ jest.useRealTimers();
+});
describe('Maintenance', () => {
it.each([
diff --git a/server/sonar-web/src/main/js/apps/projectBranches/__tests__/ProjectBranchesApp-it.tsx b/server/sonar-web/src/main/js/apps/projectBranches/__tests__/ProjectBranchesApp-it.tsx
index 9c8ebf99afe..5b3a1650df1 100644
--- a/server/sonar-web/src/main/js/apps/projectBranches/__tests__/ProjectBranchesApp-it.tsx
+++ b/server/sonar-web/src/main/js/apps/projectBranches/__tests__/ProjectBranchesApp-it.tsx
@@ -71,18 +71,20 @@ const ui = {
getPullRequestRow: () => within(ui.pullRequestTabContent.get()).getAllByRole('row'),
};
-beforeAll(() => {
+beforeEach(() => {
jest.useFakeTimers({
advanceTimers: true,
now: new Date('2018-02-01T07:08:59Z'),
});
-});
-
-beforeEach(() => {
handler.reset();
settingsHandler.reset();
});
+afterEach(() => {
+ jest.runOnlyPendingTimers();
+ jest.useRealTimers();
+});
+
it('should show all branches', async () => {
renderProjectBranchesApp();
expect(await ui.branchTabContent.find()).toBeInTheDocument();
diff --git a/server/sonar-web/src/main/js/apps/projectDump/__tests__/ProjectDumpApp-it.tsx b/server/sonar-web/src/main/js/apps/projectDump/__tests__/ProjectDumpApp-it.tsx
index 61d838ee777..3a49a306f7a 100644
--- a/server/sonar-web/src/main/js/apps/projectDump/__tests__/ProjectDumpApp-it.tsx
+++ b/server/sonar-web/src/main/js/apps/projectDump/__tests__/ProjectDumpApp-it.tsx
@@ -56,10 +56,6 @@ const ui = {
noDumpImportMsg: byText('project_dump.no_file_to_import'),
};
-afterAll(() => {
- jest.useRealTimers();
-});
-
beforeEach(() => {
computeEngineHandler.reset();
handler.reset();
@@ -69,6 +65,11 @@ beforeEach(() => {
});
});
+afterEach(() => {
+ jest.runOnlyPendingTimers();
+ jest.useRealTimers();
+});
+
it('can export project, but can not import', async () => {
renderProjectKeyApp([Feature.ProjectImport]);
expect(await ui.exportBtn.find()).toBeInTheDocument();
diff --git a/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/ProjectManagementApp-it.tsx b/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/ProjectManagementApp-it.tsx
index 1a8fac665f0..5a0ae311096 100644
--- a/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/ProjectManagementApp-it.tsx
+++ b/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/ProjectManagementApp-it.tsx
@@ -146,7 +146,7 @@ const ui = {
}),
};
-beforeAll(() => {
+beforeEach(() => {
jest.useFakeTimers({
advanceTimers: true,
now: new Date('2019-01-05T07:08:59Z'),
@@ -154,6 +154,9 @@ beforeAll(() => {
});
afterEach(() => {
+ jest.runOnlyPendingTimers();
+ jest.useRealTimers();
+
permissionsHandler.reset();
settingsHandler.reset();
handler.reset();
diff --git a/server/sonar-web/src/main/js/apps/settings/components/authentication/__tests__/Authentication-it.tsx b/server/sonar-web/src/main/js/apps/settings/components/authentication/__tests__/Authentication-it.tsx
index 445d35ded8a..4cd48c8492b 100644
--- a/server/sonar-web/src/main/js/apps/settings/components/authentication/__tests__/Authentication-it.tsx
+++ b/server/sonar-web/src/main/js/apps/settings/components/authentication/__tests__/Authentication-it.tsx
@@ -447,6 +447,7 @@ describe('Github tab', () => {
describe('Github Provisioning', () => {
let user: UserEvent;
+
beforeEach(() => {
jest.useFakeTimers({
advanceTimers: true,
@@ -454,6 +455,12 @@ describe('Github tab', () => {
});
user = userEvent.setup();
});
+
+ afterEach(() => {
+ jest.runOnlyPendingTimers();
+ jest.useRealTimers();
+ });
+
it('should display a success status when the synchronisation is a success', async () => {
handler.addProvisioningTask({
status: TaskStatuses.Success,
diff --git a/server/sonar-web/src/main/js/apps/users/__tests__/UsersApp-it.tsx b/server/sonar-web/src/main/js/apps/users/__tests__/UsersApp-it.tsx
index 3ca72375a73..56e63dc6293 100644
--- a/server/sonar-web/src/main/js/apps/users/__tests__/UsersApp-it.tsx
+++ b/server/sonar-web/src/main/js/apps/users/__tests__/UsersApp-it.tsx
@@ -137,14 +137,15 @@ beforeEach(() => {
});
describe('different filters combinations', () => {
- beforeAll(() => {
+ beforeEach(() => {
jest.useFakeTimers({
advanceTimers: true,
now: new Date('2023-07-05T07:08:59Z'),
});
});
- afterAll(() => {
+ afterEach(() => {
+ jest.runOnlyPendingTimers();
jest.useRealTimers();
});
diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/Toggler-test.tsx b/server/sonar-web/src/main/js/components/controls/__tests__/Toggler-test.tsx
index 827d0bb6de2..f29b18a9c69 100644
--- a/server/sonar-web/src/main/js/components/controls/__tests__/Toggler-test.tsx
+++ b/server/sonar-web/src/main/js/components/controls/__tests__/Toggler-test.tsx
@@ -24,11 +24,12 @@ import * as React from 'react';
import { byRole } from '../../../helpers/testSelector';
import Toggler from '../Toggler';
-beforeAll(() => {
+beforeEach(() => {
jest.useFakeTimers();
});
-afterAll(() => {
+afterEach(() => {
+ jest.runOnlyPendingTimers();
jest.useRealTimers();
});
const ui = {
diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/Tooltip-test.tsx b/server/sonar-web/src/main/js/components/controls/__tests__/Tooltip-test.tsx
index 6ac31757831..aef69447e0e 100644
--- a/server/sonar-web/src/main/js/components/controls/__tests__/Tooltip-test.tsx
+++ b/server/sonar-web/src/main/js/components/controls/__tests__/Tooltip-test.tsx
@@ -21,11 +21,12 @@ import { shallow } from 'enzyme';
import * as React from 'react';
import Tooltip, { TooltipInner, TooltipProps } from '../Tooltip';
-beforeAll(() => {
+beforeEach(() => {
+ jest.clearAllMocks();
jest.useFakeTimers();
});
-afterAll(() => {
+afterEach(() => {
jest.runOnlyPendingTimers();
jest.useRealTimers();
});
@@ -44,8 +45,6 @@ jest.mock('lodash', () => {
});
});
-beforeEach(jest.clearAllMocks);
-
it('should render', () => {
expect(shallowRenderTooltipInner()).toMatchSnapshot();
expect(
diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/clipboard-test.tsx b/server/sonar-web/src/main/js/components/controls/__tests__/clipboard-test.tsx
index 9814b6baffc..b52d288fbc9 100644
--- a/server/sonar-web/src/main/js/components/controls/__tests__/clipboard-test.tsx
+++ b/server/sonar-web/src/main/js/components/controls/__tests__/clipboard-test.tsx
@@ -28,11 +28,11 @@ import {
ClipboardIconButtonProps,
} from '../clipboard';
-beforeAll(() => {
+beforeEach(() => {
jest.useFakeTimers();
});
-afterAll(() => {
+afterEach(() => {
jest.runOnlyPendingTimers();
jest.useRealTimers();
});
diff --git a/server/sonar-web/src/main/js/components/ui/__tests__/DeferredSpinner-test.tsx b/server/sonar-web/src/main/js/components/ui/__tests__/DeferredSpinner-test.tsx
index 6c7909d2523..0237097d9ac 100644
--- a/server/sonar-web/src/main/js/components/ui/__tests__/DeferredSpinner-test.tsx
+++ b/server/sonar-web/src/main/js/components/ui/__tests__/DeferredSpinner-test.tsx
@@ -21,15 +21,12 @@ import { render, screen } from '@testing-library/react';
import * as React from 'react';
import DeferredSpinner from '../DeferredSpinner';
-beforeAll(() => {
+beforeEach(() => {
jest.useFakeTimers();
});
afterEach(() => {
jest.runOnlyPendingTimers();
-});
-
-afterAll(() => {
jest.useRealTimers();
});
diff --git a/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceRuleViewer-test.tsx b/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceRuleViewer-test.tsx
index df9460ecaa5..986d11b0e55 100644
--- a/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceRuleViewer-test.tsx
+++ b/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceRuleViewer-test.tsx
@@ -21,11 +21,11 @@ import { shallow } from 'enzyme';
import * as React from 'react';
import WorkspaceRuleViewer, { Props } from '../WorkspaceRuleViewer';
-beforeAll(() => {
+beforeEach(() => {
jest.useFakeTimers();
});
-afterAll(() => {
+afterEach(() => {
jest.runOnlyPendingTimers();
jest.useRealTimers();
});
diff --git a/server/sonar-web/src/main/js/helpers/__tests__/error-test.ts b/server/sonar-web/src/main/js/helpers/__tests__/error-test.ts
index da720118935..8a904ccc0a3 100644
--- a/server/sonar-web/src/main/js/helpers/__tests__/error-test.ts
+++ b/server/sonar-web/src/main/js/helpers/__tests__/error-test.ts
@@ -24,15 +24,12 @@ jest.mock('../../helpers/globalMessages', () => ({
addGlobalErrorMessage: jest.fn(),
}));
-beforeAll(() => {
- jest.useFakeTimers();
-});
-
beforeEach(() => {
+ jest.useFakeTimers();
jest.clearAllMocks();
});
-afterAll(() => {
+afterEach(() => {
jest.runOnlyPendingTimers();
jest.useRealTimers();
});
diff --git a/server/sonar-web/src/main/js/helpers/__tests__/request-test.ts b/server/sonar-web/src/main/js/helpers/__tests__/request-test.ts
index 246ba04a4d9..ea446cb9d22 100644
--- a/server/sonar-web/src/main/js/helpers/__tests__/request-test.ts
+++ b/server/sonar-web/src/main/js/helpers/__tests__/request-test.ts
@@ -203,19 +203,16 @@ describe('post', () => {
});
describe('requestTryAndRepeatUntil', () => {
- beforeAll(() => {
+ beforeEach(() => {
+ jest.clearAllTimers();
jest.useFakeTimers();
});
- afterAll(() => {
+ afterEach(() => {
jest.runOnlyPendingTimers();
jest.useRealTimers();
});
- beforeEach(() => {
- jest.clearAllTimers();
- });
-
it('should repeat call until stop condition is met', async () => {
const apiCall = jest.fn().mockResolvedValue({ repeat: true });
const stopRepeat = jest.fn().mockImplementation(({ repeat }) => !repeat);