Skip to content

Commit 3a0f2de

Browse files
authored
Merge pull request #1584 from ral-facilities/renovate/develop-major-vitest-monorepo
Update vitest monorepo to v4 (develop) (major)
2 parents fd8c6b7 + dd6a0ab commit 3a0f2de

11 files changed

+221
-324
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
"@testing-library/react": "16.3.0",
8686
"@testing-library/user-event": "14.6.1",
8787
"@types/eslint-plugin-jsx-a11y": "6.10.0",
88-
"@vitest/coverage-v8": "3.2.4",
88+
"@vitest/coverage-v8": "4.0.17",
8989
"cross-env": "10.1.0",
9090
"cypress": "14.5.4",
9191
"eslint": "9.39.1",
@@ -105,7 +105,7 @@
105105
"serve-static": "2.2.0",
106106
"start-server-and-test": "2.1.2",
107107
"typescript-eslint": "8.46.3",
108-
"vitest": "3.2.4"
108+
"vitest": "4.0.17"
109109
},
110110
"msw": {
111111
"workerDirectory": "public"

src/apiConfigProvider.component.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ const APIConfigTest: React.FC = (): React.ReactElement => {
1717

1818
describe('APIConfigProvider', () => {
1919
beforeEach(() => {
20-
global.document.dispatchEvent = vi.fn();
21-
global.CustomEvent = vi.fn();
20+
globalThis.document.dispatchEvent = vi.fn();
21+
globalThis.CustomEvent = vi.fn();
2222
});
2323

2424
afterEach(() => {

src/common/delayedLoader.component.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ const DelayedLoader = (props: DelayedLoaderProps) => {
1313
const [showLoader, setShowLoader] = React.useState(false);
1414

1515
React.useEffect(() => {
16-
let timeout: NodeJS.Timeout | null = null;
16+
// Return type reported as number by vscode, but when built seems to use NextJS.Timeout
17+
let timeout: ReturnType<typeof setTimeout> | null = null;
1718

1819
if (isLoading) {
1920
timeout = setTimeout(() => {

src/common/images/uploadImagesDialog.component.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('Upload image dialog', () => {
2929
};
3030
user = userEvent.setup();
3131
xhrPostSpy = vi.spyOn(window.XMLHttpRequest.prototype, 'open');
32-
global.URL.createObjectURL = vi.fn(() => 'mocked-url');
32+
globalThis.URL.createObjectURL = vi.fn(() => 'mocked-url');
3333
vi.spyOn(console, 'error').mockImplementation(() => {});
3434
});
3535

src/configProvider.component.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ vi.mock('./settings', () => ({
7171

7272
describe('ConfigProvider', () => {
7373
beforeEach(() => {
74-
global.document.dispatchEvent = vi.fn();
75-
global.CustomEvent = vi.fn();
74+
globalThis.document.dispatchEvent = vi.fn();
75+
globalThis.CustomEvent = vi.fn();
7676
});
7777

7878
afterEach(() => {

src/manufacturer/manufacturerTable.component.test.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ describe('Manufacturer Table', () => {
3434
await user.click(screen.getByRole('button', { name: 'Show/Hide columns' }));
3535
await user.click(screen.getByText('Created'));
3636

37+
// Ripples sometimes appear here, they seem to only be present on WSL and not on VMs & CI - wait for them to go
38+
// away so local tests don't interfere
39+
await waitFor(() =>
40+
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
41+
expect(view.container.querySelector('.MuiTouchRipple-child')).toBeNull()
42+
);
43+
3744
expect(view.asFragment()).toMatchSnapshot();
3845
});
3946

src/setupTests.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ afterEach(() => server.resetHandlers());
1818
// Clean up after the tests are finished.
1919
afterAll(() => server.close());
2020

21-
window.ResizeObserver = vi.fn().mockImplementation(() => ({
22-
disconnect: vi.fn(),
23-
observe: vi.fn(),
24-
unobserve: vi.fn(),
25-
}));
21+
window.ResizeObserver = vi.fn().mockImplementation(function (
22+
this: ResizeObserver
23+
) {
24+
this.disconnect = vi.fn();
25+
this.observe = vi.fn();
26+
this.unobserve = vi.fn();
27+
}) as unknown as typeof ResizeObserver;

src/systems/systemItemsTable.component.test.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ describe('SystemItemsTable', () => {
8585

8686
expect(await screen.findByText('Clear Filters')).toBeInTheDocument();
8787

88+
// Ripples sometimes appear here, they seem to only be present on WSL and not on VMs & CI - wait for them to go
89+
// away so local tests don't interfere
90+
await waitFor(() =>
91+
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
92+
expect(view.container.querySelector('.MuiTouchRipple-child')).toBeNull()
93+
);
94+
8895
// Rest in a snapshot
8996
expect(view.asFragment()).toMatchSnapshot();
9097
});
@@ -123,6 +130,13 @@ describe('SystemItemsTable', () => {
123130
);
124131
await user.click(screen.getByText('Created'));
125132

133+
// Ripples sometimes appear here, they seem to only be present on WSL and not on VMs & CI - wait for them to go
134+
// away so local tests don't interfere
135+
await waitFor(() =>
136+
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
137+
expect(view.container.querySelector('.MuiTouchRipple-child')).toBeNull()
138+
);
139+
126140
// Rest in a snapshot
127141
expect(view.asFragment()).toMatchSnapshot();
128142
});

src/utils.test.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,14 @@ describe('Utility functions', () => {
193193
});
194194

195195
// Mocking the ResizeObserver
196-
window.ResizeObserver = vi.fn().mockImplementation((callback) => ({
197-
observe: () => observeMock(callback),
198-
disconnect: vi.fn(),
199-
unobserve: vi.fn(),
200-
}));
196+
window.ResizeObserver = vi.fn().mockImplementation(function (
197+
this: ResizeObserver,
198+
callback: ResizeObserverCallback
199+
) {
200+
this.disconnect = vi.fn();
201+
this.observe = () => observeMock(callback);
202+
this.unobserve = vi.fn();
203+
}) as unknown as typeof ResizeObserver;
201204

202205
renderComponentWithRouterProvider(
203206
<OverflowTip>
@@ -247,11 +250,14 @@ describe('Utility functions', () => {
247250
});
248251

249252
// Mocking the ResizeObserver
250-
window.ResizeObserver = vi.fn().mockImplementation((callback) => ({
251-
observe: () => observeMock(callback),
252-
disconnect: vi.fn(),
253-
unobserve: vi.fn(),
254-
}));
253+
window.ResizeObserver = vi.fn().mockImplementation(function (
254+
this: ResizeObserver,
255+
callback: ResizeObserverCallback
256+
) {
257+
this.disconnect = vi.fn();
258+
this.observe = () => observeMock(callback);
259+
this.unobserve = vi.fn();
260+
}) as unknown as typeof ResizeObserver;
255261

256262
renderComponentWithRouterProvider(
257263
<OverflowTip>Some long text that overflows</OverflowTip>

vite.config.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,6 @@ function jsonHMR(): PluginOption {
3838
};
3939
}
4040

41-
// Obtain default coverage config from vitest when not building for production
42-
// (to avoid importing vitest during build as its a dev dependency)
43-
let vitestCoverageConfigDefaultsExclude: string[] = [];
44-
if (process.env.NODE_ENV !== 'production') {
45-
await import('vitest/config').then((vitestConfig) => {
46-
vitestCoverageConfigDefaultsExclude =
47-
vitestConfig.coverageConfigDefaults.exclude;
48-
});
49-
}
50-
5141
// https://vitejs.dev/config/
5242
export default defineConfig(({ mode }) => {
5343
const env = loadEnv(mode, process.cwd(), '');
@@ -162,10 +152,8 @@ export default defineConfig(({ mode }) => {
162152
// Extra for VSCode extension
163153
['lcov', { outputFile: 'lcov.info', silent: true }],
164154
],
155+
include: ['/src/**.{js,jsx,ts,tsx}'],
165156
exclude: [
166-
...vitestCoverageConfigDefaultsExclude,
167-
'public/*',
168-
'server/*',
169157
// Leave handlers to show up unused code
170158
'src/mocks/browser.ts',
171159
'src/mocks/server.ts',
@@ -181,7 +169,7 @@ export default defineConfig(({ mode }) => {
181169
outputFile: env.CI ? { junit: 'test-report.junit.xml' } : undefined,
182170
deps: {
183171
optimizer: {
184-
web: {
172+
client: {
185173
enabled: true,
186174
include: [
187175
'@mui/material',

0 commit comments

Comments
 (0)