diff --git a/package.json b/package.json index f666218f..6dedb51e 100644 --- a/package.json +++ b/package.json @@ -125,4 +125,4 @@ "wait-on": "7.2.0" }, "packageManager": "yarn@4.1.0" -} \ No newline at end of file +} diff --git a/src/App.test.tsx b/src/App.test.tsx index 4109aa34..b4ef2d83 100644 --- a/src/App.test.tsx +++ b/src/App.test.tsx @@ -3,7 +3,7 @@ import { act, fireEvent, render, screen } from '@testing-library/react'; import axios from 'axios'; import { createRoot } from 'react-dom/client'; import App, { AppSansHoc } from './App'; -import { flushPromises } from './setupTests'; +import { flushPromises } from './testUtils'; import { RegisterRouteType } from './state/scigateway.types'; vi.mock('./state/actions/loadMicroFrontends', () => ({ diff --git a/src/routing/authorisedRoute.component.test.tsx b/src/routing/authorisedRoute.component.test.tsx index ff92d6a0..fcbed642 100644 --- a/src/routing/authorisedRoute.component.test.tsx +++ b/src/routing/authorisedRoute.component.test.tsx @@ -15,7 +15,7 @@ import { siteLoadingUpdate, verifyUsernameAndPassword, } from '../state/actions/scigateway.actions'; -import { flushPromises } from '../setupTests'; +import { flushPromises } from '../testUtils'; import { Provider } from 'react-redux'; import { act, diff --git a/src/setupTests.ts b/src/setupTests.ts index 85b52fae..f220ee6c 100644 --- a/src/setupTests.ts +++ b/src/setupTests.ts @@ -22,9 +22,6 @@ Object.defineProperty(window, 'matchMedia', { })), }); -export const flushPromises = async (): Promise => - (await vi.importActual('timers')).setImmediate; - // globally mock as we never want to actually call single-spa funcs in unit tests vi.mock('single-spa', () => ({ unloadApplication: vi.fn(), diff --git a/src/state/actions/scigateway.actions.test.tsx b/src/state/actions/scigateway.actions.test.tsx index 71a94fbe..74ba9b38 100644 --- a/src/state/actions/scigateway.actions.test.tsx +++ b/src/state/actions/scigateway.actions.test.tsx @@ -46,7 +46,7 @@ import { StateType } from '../state.types'; import loadMicroFrontends from './loadMicroFrontends'; import log from 'loglevel'; import { createLocation } from 'history'; -import { flushPromises } from '../../setupTests'; +import { flushPromises } from '../../testUtils'; function mockAxiosGetResponse(message: string): void { vi.mocked(mockAxios.get).mockImplementationOnce(() => diff --git a/src/state/middleware/scigateway.middleware.test.tsx b/src/state/middleware/scigateway.middleware.test.tsx index 833ca2a1..a86887ca 100644 --- a/src/state/middleware/scigateway.middleware.test.tsx +++ b/src/state/middleware/scigateway.middleware.test.tsx @@ -25,7 +25,7 @@ import { toastr } from 'react-redux-toastr'; import { AddHelpTourStepsType } from '../scigateway.types'; import { StateType } from '../state.types'; import TestAuthProvider from '../../authentication/testAuthProvider'; -import { flushPromises } from '../../setupTests'; +import { flushPromises } from '../../testUtils'; import { authState, initialState } from '../reducers/scigateway.reducer'; import { buildTheme } from '../../theming'; import { thunk } from 'redux-thunk'; diff --git a/src/testUtils.tsx b/src/testUtils.tsx new file mode 100644 index 00000000..e6fe79f7 --- /dev/null +++ b/src/testUtils.tsx @@ -0,0 +1,2 @@ +export const flushPromises = async (): Promise => + (await vi.importActual('timers')).setImmediate; diff --git a/tsconfig.build.json b/tsconfig.build.json index 303bffc9..30a804d5 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -1,5 +1,5 @@ { "extends": "./tsconfig.base.json", // Exclude test files from build - "exclude": ["**/?*test.*", "src/setupTests.ts"], + "exclude": ["**/?*test.*", "src/setupTests.ts", "src/testUtils.tsx"], } \ No newline at end of file