Skip to content

fix: eliminate Vite config and React act() warnings in tests - #1068

Open
EhabY wants to merge 1 commit into
mainfrom
fix/test-warnings
Open

fix: eliminate Vite config and React act() warnings in tests#1068
EhabY wants to merge 1 commit into
mainfrom
fix/test-warnings

Conversation

@EhabY

@EhabY EhabY commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

What

pnpm test prints two categories of warnings:

  1. Vite config loader warning (3x): vitest.config.ts uses ESM syntax but the root package.json has "type": "commonjs", so Vite loads it as CJS and warns about the upcoming configLoader: "native" default.

  2. React act() warnings (4x in useVscodeTheme.test.ts): The afterEach cleanup mutates the DOM attribute while the previous test's hook is still mounted (RTL auto-cleanup runs after user-registered afterEach). The MutationObserver callback fires in a microtask and triggers a state update outside act().

Changes

  • Rename vitest.config.tsvitest.config.mts and replace __dirname with import.meta.dirname. This makes the config unambiguously ESM, silencing the Vite warning.

  • Add explicit unmount() calls in each useVscodeTheme test so the hook is torn down before the afterEach attribute cleanup fires. The MutationObserver callback then has no mounted component to update, eliminating the act() warnings.

Verification

  • All 152 test files / 2296 tests pass with zero warnings in the output.
  • pnpm typecheck and pnpm format:check pass.
  • pnpm lint crashes with a core dump on main too (pre-existing environment issue, not caused by this change).

Generated by Coder Agents

- 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.

- Call RTL cleanup() before resetting the DOM attribute in afterEach
  so the MutationObserver callback doesn't fire a state update on a
  still-mounted component, which caused 'not wrapped in act()' warnings.
@EhabY
EhabY force-pushed the fix/test-warnings branch from 0c982ba to 47b3b48 Compare August 6, 2026 00:16
@EhabY EhabY self-assigned this Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant