From e2b2cca1d9cf7304ff0b8c14001378472c92abe9 Mon Sep 17 00:00:00 2001 From: Ajibose Date: Sun, 30 Aug 2026 19:02:29 +0300 Subject: [PATCH] chore(frontend): consolidate duplicate vitest config files (#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. --- frontend/src/__tests__/vitest-config.test.ts | 20 +++++++++++++ frontend/src/test-setup.ts | 30 -------------------- frontend/vitest.config.mts | 18 ------------ 3 files changed, 20 insertions(+), 48 deletions(-) create mode 100644 frontend/src/__tests__/vitest-config.test.ts delete mode 100644 frontend/src/test-setup.ts delete mode 100644 frontend/vitest.config.mts diff --git a/frontend/src/__tests__/vitest-config.test.ts b/frontend/src/__tests__/vitest-config.test.ts new file mode 100644 index 00000000..30bcd8d5 --- /dev/null +++ b/frontend/src/__tests__/vitest-config.test.ts @@ -0,0 +1,20 @@ +import { describe, expect, it } from 'vitest'; +import fs from 'fs'; +import path from 'path'; + +// Regression guard for https://github.com/LabsCrypt/flowfi/issues/1281: +// having both vitest.config.ts and vitest.config.mts at the same time makes +// the resolved test config ambiguous (Vite/Vitest pick one based on +// extension resolution order, which is not obvious to contributors and can +// silently disable the "other" config's environment, setup file, and +// coverage thresholds). Only one vitest.config.* should ever exist. +describe('vitest config', () => { + it('has exactly one vitest.config.* file in the frontend package', () => { + const frontendRoot = path.resolve(__dirname, '..', '..'); + const configFiles = fs + .readdirSync(frontendRoot) + .filter((f) => /^vitest\.config\.(ts|mts|cts|js|mjs|cjs)$/.test(f)); + + expect(configFiles).toEqual(['vitest.config.ts']); + }); +}); diff --git a/frontend/src/test-setup.ts b/frontend/src/test-setup.ts deleted file mode 100644 index 3310558c..00000000 --- a/frontend/src/test-setup.ts +++ /dev/null @@ -1,30 +0,0 @@ -import '@testing-library/jest-dom'; -import { vi } from 'vitest'; - -const localStorageMock = (() => { - let store: Record = {}; - return { - getItem: vi.fn((key: string) => store[key] || null), - setItem: vi.fn((key: string, value: string) => { - store[key] = value.toString(); - }), - clear: vi.fn(() => { - store = {}; - }), - removeItem: vi.fn((key: string) => { - delete store[key]; - }), - key: vi.fn((index: number) => Object.keys(store)[index] || null), - length: 0, - }; -})(); - -vi.stubGlobal('localStorage', localStorageMock); -if (typeof window !== 'undefined') { - Object.defineProperty(window, 'localStorage', { - value: localStorageMock, - configurable: true, - writable: true, - }); -} - diff --git a/frontend/vitest.config.mts b/frontend/vitest.config.mts deleted file mode 100644 index 1e79ea10..00000000 --- a/frontend/vitest.config.mts +++ /dev/null @@ -1,18 +0,0 @@ -import { defineConfig } from 'vitest/config'; -import react from '@vitejs/plugin-react'; -import path from 'path'; - -export default defineConfig({ - // @ts-expect-error type mismatch between vite versions in monorepo - plugins: [react()], - resolve: { - alias: { - '@': path.resolve(__dirname, './src'), - }, - }, - test: { - environment: 'jsdom', - globals: true, - setupFiles: ['./src/test-setup.ts'], - }, -});