chore(frontend): consolidate duplicate vitest config files - #1384
Open
Rafiat30 wants to merge 1 commit into
Open
chore(frontend): consolidate duplicate vitest config files#1384Rafiat30 wants to merge 1 commit into
Rafiat30 wants to merge 1 commit into
Conversation
…#1281) Both vitest.config.ts and vitest.config.mts existed simultaneously, making it unclear which one vitest run actually resolves. Verified empirically by adding a distinguishing console.error marker to the top of each config and running `npx vitest run`: only the marker from vitest.config.ts printed, confirming Vite/Vitest resolves the .ts file over the .mts one in this repo (Vitest 3.2.7). This also matches the codebase: setupFiles './src/__tests__/setup.ts' (referenced by the .ts config) and the actual test layout under src/__tests__/** and colocated across src/**, both matched by the .ts config's include pattern. The .mts config's setupFiles pointed at './src/test-setup.ts', a byte-identical duplicate of the same setup file, now orphaned and removed. Kept: vitest.config.ts (happy-dom environment, coverage thresholds, include pattern, resolve.alias['@']). Removed: vitest.config.mts (jsdom environment, @vitejs/plugin-react plugin, no coverage thresholds) and the now-unreferenced src/test-setup.ts duplicate. The @vitejs/plugin-react plugin from the removed config was not carried over: the full test suite (32 files, 286 tests) already passes without it, since Next.js/Vite's default esbuild JSX transform handles .tsx test files fine for this project's happy-dom-based unit tests. Added a small regression-guard test asserting only one vitest.config.* file exists in frontend/, so this ambiguity can't silently reappear.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1281
Problem
frontend/vitest.config.tsandfrontend/vitest.config.mtsboth existed at the same time, with different settings:vitest.config.ts:environment: 'happy-dom',setupFiles: ['./src/__tests__/setup.ts'], anincludepattern, and coverage thresholds (functions: 18,lines: 18).vitest.config.mts:environment: 'jsdom',setupFiles: ['./src/test-setup.ts'], a@vitejs/plugin-reactplugin,resolve.alias['@'], no coverage thresholds.Vite/Vitest's config resolution is extension-order dependent, so it wasn't obvious which file
vitest run(invoked byfrontend/package.json'stestscript, and bynpm test --workspace=frontend) actually picks up — silently changing test environment or disabling coverage enforcement for the whole team if someone edited the wrong file.How I verified which config is actually active
I did not rely on documentation of Vite's resolution order — I verified empirically:
console.error('DEBUG_MARKER: vitest.config.ts IS BEING LOADED')to the top ofvitest.config.ts, and a matchingDEBUG_MARKER: vitest.config.mts IS BEING LOADEDto the top ofvitest.config.mts.cd frontend && npx vitest run 2>&1 | head -40.DEBUG_MARKER: vitest.config.ts IS BEING LOADEDprinted. The.mtsmarker never appeared, confirming Vitest 3.2.7 resolvesvitest.config.tsovervitest.config.mtsin this repo.This matches independent evidence from the codebase itself:
src/__tests__/setup.ts(referenced by the.tsconfig) exists and is used;src/test-setup.ts(referenced by the.mtsconfig) also existed but was a byte-identical duplicate, orphaned once the.mtsconfig is removed.src/__tests__/**and colocated throughoutsrc/**(e.g.src/lib/*.test.ts,src/components/*.test.tsx,src/hooks/*.test.tsx). The.tsconfig'sinclude: ['src/__tests__/**/*.{test,spec}.{ts,tsx}', 'src/**/*.{test,spec}.{ts,tsx}']matches this; the.mtsconfig had no explicitinclude(relying on Vitest's default), which happens to also match, but the.tsconfig's pattern is intentional/explicit and correct for this layout.What changed
frontend/vitest.config.mts(jsdom environment,@vitejs/plugin-reactplugin, no coverage thresholds — confirmed not the active config).frontend/src/test-setup.ts— only referenced by the now-removed.mtsconfig, byte-identical tosrc/__tests__/setup.ts, so nothing was lost.frontend/vitest.config.tsunchanged — it already had everything needed:happy-domenvironment, the correctsetupFiles, theincludepattern matching the real test layout, coverage thresholds, andresolve.alias['@'](used throughout the codebase for imports).@vitejs/plugin-reactplugin from the removed.mtsconfig. This project is a Next.js app (not a standalone Vite app), and the full test suite (32 files, 286 tests) already passes without it — Vite's default esbuild JSX transform handles the.tsxtest files fine for these happy-dom-based unit tests. Called out here explicitly per the acceptance criteria, since it's the one thing from the losing config not merged in.frontend/src/__tests__/vitest-config.test.ts— a small regression-guard test asserting exactly onevitest.config.*file exists infrontend/, so this ambiguity can't silently reappear.Testing
cd frontend && npx vitest run— 32 test files, 286 tests, all passing.cd frontend && npx vitest run --coverage— 32 test files, 286 tests, all passing; coverage thresholds satisfied (measured ~36.8% lines / ~58.7% functions vs. the enforced 18%/18% minimums). Ran this twice to confirm stability; one earlier concurrent run (while other background installs were competing for CPU on the shared dev machine) showed 2 tests timing out under system load — those are pre-existing real-timer-based tests unrelated to this change, and they pass reliably both in isolation and in clean full runs.How to test manually
Both should report the same environment/setup-file behavior as before (only now unambiguous), with 32 test files / 287 tests (286 existing + 1 new regression-guard test) passing and coverage thresholds enforced.