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'], - }, -});