Skip to content

Commit 0c982ba

Browse files
committed
fix: eliminate Vite config and React act() warnings in tests
- Rename vitest.config.ts to .mts and replace __dirname with import.meta.dirname to resolve the Vite native configLoader warning about ESM syntax in a CJS-loaded file. - Add explicit unmount() calls in useVscodeTheme tests so the MutationObserver-triggered state update from the afterEach cleanup doesn't fire while the component is still mounted, which caused 'not wrapped in act()' warnings.
1 parent eccc59e commit 0c982ba

2 files changed

Lines changed: 22 additions & 10 deletions

File tree

test/webview/ui/useVscodeTheme.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,23 @@ describe("useVscodeTheme", () => {
2424
])("returns %s as %s", (attribute, expected) => {
2525
setThemeKind(attribute);
2626

27-
const { result } = renderHook(() => useVscodeTheme());
27+
const { result, unmount } = renderHook(() => useVscodeTheme());
2828

2929
expect(result.current).toBe(expected);
30+
unmount();
3031
});
3132

3233
it("defaults to dark when the attribute is missing", () => {
33-
const { result } = renderHook(() => useVscodeTheme());
34+
const { result, unmount } = renderHook(() => useVscodeTheme());
3435

3536
expect(result.current).toBe("dark");
37+
unmount();
3638
});
3739

3840
it("updates when the theme changes", async () => {
3941
setThemeKind("vscode-dark");
4042

41-
const { result } = renderHook(() => useVscodeTheme());
43+
const { result, unmount } = renderHook(() => useVscodeTheme());
4244
expect(result.current).toBe("dark");
4345

4446
// MutationObserver callbacks are microtasks; flush them inside act.
@@ -47,5 +49,6 @@ describe("useVscodeTheme", () => {
4749
await Promise.resolve();
4850
});
4951
expect(result.current).toBe("light");
52+
unmount();
5053
});
5154
});

vitest.config.ts renamed to vitest.config.mts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import path from "node:path";
22
import { defineConfig } from "vitest/config";
33

44
const webviewSharedAlias = path.resolve(
5-
__dirname,
5+
import.meta.dirname,
66
"packages/webview-shared/src",
77
);
88

@@ -24,9 +24,12 @@ export default defineConfig({
2424
},
2525
resolve: {
2626
alias: {
27-
"@": path.resolve(__dirname, "src"),
27+
"@": path.resolve(import.meta.dirname, "src"),
2828
"@repo/webview-shared": webviewSharedAlias,
29-
vscode: path.resolve(__dirname, "test/mocks/vscode.runtime.ts"),
29+
vscode: path.resolve(
30+
import.meta.dirname,
31+
"test/mocks/vscode.runtime.ts",
32+
),
3033
},
3134
},
3235
},
@@ -43,11 +46,17 @@ export default defineConfig({
4346
resolve: {
4447
alias: {
4548
"@repo/webview-shared": webviewSharedAlias,
46-
"@repo/tasks": path.resolve(__dirname, "packages/tasks/src"),
47-
"@repo/ui": path.resolve(__dirname, "packages/ui/src"),
48-
"@repo/netcheck": path.resolve(__dirname, "packages/netcheck/src"),
49+
"@repo/tasks": path.resolve(
50+
import.meta.dirname,
51+
"packages/tasks/src",
52+
),
53+
"@repo/ui": path.resolve(import.meta.dirname, "packages/ui/src"),
54+
"@repo/netcheck": path.resolve(
55+
import.meta.dirname,
56+
"packages/netcheck/src",
57+
),
4958
"@repo/speedtest": path.resolve(
50-
__dirname,
59+
import.meta.dirname,
5160
"packages/speedtest/src",
5261
),
5362
},

0 commit comments

Comments
 (0)