Skip to content

Commit 4a10563

Browse files
committed
fix upgraded Vitest warnings
The upgraded test toolchain surfaced warnings for deprecated path-resolution plugin wiring, a nested module mock, and JSDOM's missing scroll API. The path warning came from keeping `vite-tsconfig-paths` after Vite added native `resolve.tsconfigPaths` support, so the plugin was both noisy and redundant. Use Vite's native `resolve.tsconfigPaths` support in both Vite and Vitest config, and remove the now-unused `vite-tsconfig-paths` dependency. Move the job-search API mock to module scope so Vitest's hoisting behavior is explicit, and provide a minimal `scrollTo` test shim for code paths that expect browser scrolling APIs.
1 parent 19d8509 commit 4a10563

6 files changed

Lines changed: 52 additions & 88 deletions

File tree

package-lock.json

Lines changed: 0 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
"typescript": "^6.0.3",
6666
"typescript-eslint": "^8.59.0",
6767
"vite": "^8.0.10",
68-
"vite-tsconfig-paths": "^6.1.1",
6968
"vitest": "^4.1.5"
7069
},
7170
"overrides": {

src/components/job-search/JobSearch.test.tsx

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,47 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
1010

1111
import { Filter, FilterTypeId, JobSearch } from "./JobSearch";
1212

13+
vi.mock("./api", () => ({
14+
fetchSuggestions: async (
15+
filterTypeId: string,
16+
query: string,
17+
selectedValues: string[],
18+
) => {
19+
if (filterTypeId === "kind") {
20+
const mockKinds = [
21+
"batch",
22+
"stream",
23+
"scheduled",
24+
"one-time",
25+
"recurring",
26+
"Chaos",
27+
"AITrainingBatch",
28+
"UtilizeNewModel",
29+
];
30+
return mockKinds
31+
.filter((kind) => kind.toLowerCase().includes(query.toLowerCase()))
32+
.filter((kind) => !selectedValues.includes(kind));
33+
} else if (filterTypeId === "queue") {
34+
const mockQueues = [
35+
"default",
36+
"high-priority",
37+
"low-priority",
38+
"batch",
39+
"realtime",
40+
];
41+
return mockQueues
42+
.filter((queue) => queue.includes(query.toLowerCase()))
43+
.filter((queue) => !selectedValues.includes(queue));
44+
} else if (filterTypeId === "priority") {
45+
const priorities = ["1", "2", "3", "4"];
46+
return priorities
47+
.filter((priority) => priority.includes(query))
48+
.filter((priority) => !selectedValues.includes(priority));
49+
}
50+
return [];
51+
},
52+
}));
53+
1354
// Add type declarations for test functions
1455
declare module "vitest" {
1556
interface Assertion<T> {
@@ -20,46 +61,6 @@ declare module "vitest" {
2061
describe("JobSearch", () => {
2162
beforeEach(() => {
2263
vi.clearAllMocks();
23-
vi.mock("./api", () => ({
24-
fetchSuggestions: async (
25-
filterTypeId: string,
26-
query: string,
27-
selectedValues: string[],
28-
) => {
29-
if (filterTypeId === "kind") {
30-
const mockKinds = [
31-
"batch",
32-
"stream",
33-
"scheduled",
34-
"one-time",
35-
"recurring",
36-
"Chaos",
37-
"AITrainingBatch",
38-
"UtilizeNewModel",
39-
];
40-
return mockKinds
41-
.filter((kind) => kind.toLowerCase().includes(query.toLowerCase()))
42-
.filter((kind) => !selectedValues.includes(kind));
43-
} else if (filterTypeId === "queue") {
44-
const mockQueues = [
45-
"default",
46-
"high-priority",
47-
"low-priority",
48-
"batch",
49-
"realtime",
50-
];
51-
return mockQueues
52-
.filter((queue) => queue.includes(query.toLowerCase()))
53-
.filter((queue) => !selectedValues.includes(queue));
54-
} else if (filterTypeId === "priority") {
55-
const priorities = ["1", "2", "3", "4"];
56-
return priorities
57-
.filter((priority) => priority.includes(query))
58-
.filter((priority) => !selectedValues.includes(priority));
59-
}
60-
return [];
61-
},
62-
}));
6364
});
6465

6566
describe("Basic Rendering & Props", () => {

src/test/setup.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ class ResizeObserverMock {
1515

1616
global.ResizeObserver = ResizeObserverMock;
1717

18+
// JSDOM does not implement scrolling APIs used by router and focus helpers.
19+
Object.defineProperty(window, "scrollTo", {
20+
configurable: true,
21+
value: () => {},
22+
writable: true,
23+
});
24+
1825
// Headless UI relies on the Web Animations API for transitions. JSDOM doesn't
1926
// implement it, and Headless UI will polyfill with warnings (and may behave
2027
// differently across versions). Provide a minimal stable polyfill.

vite.config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { tanstackRouter } from "@tanstack/router-plugin/vite";
33
import react from "@vitejs/plugin-react-swc";
44
import path from "node:path";
55
import { defineConfig } from "vite";
6-
import tsconfigPaths from "vite-tsconfig-paths";
76

87
const dagreCjsPath = path.resolve(
98
process.cwd(),
@@ -49,11 +48,11 @@ export default defineConfig({
4948
tanstackRouter({
5049
routeFileIgnorePattern: ".(const|schema|test).(ts|tsx)",
5150
}),
52-
tsconfigPaths(),
5351
],
5452
resolve: {
5553
alias: {
5654
"@dagrejs/dagre": dagreCjsPath,
5755
},
56+
tsconfigPaths: true,
5857
},
5958
});

vitest.config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import tsconfigPaths from "vite-tsconfig-paths";
21
import { defineConfig } from "vitest/config";
32

43
export default defineConfig({
5-
plugins: [tsconfigPaths()],
4+
resolve: {
5+
tsconfigPaths: true,
6+
},
67
test: {
78
environment: "jsdom",
89
globals: true,

0 commit comments

Comments
 (0)