I am migrating my project from jest to vitest and I wanna exclude certain files and folders for both test and coverage, I am following the docs but "exclude" does not seem working, whenever I run some test, vitest throws an error that is coming from config folder and I don't have any test files there, inside the config folder I have bunch of config files including setupTests.ts and i18n specific config, the error is coming from the i18n.ts file. I am using vite 3 and Below is my vite config file, How else can I exclude files and folders?
Environment:
- Windows 11
- Node 16.14.0
- Vite 3.1.0
- Vitest 0.23.4
- List item
Edit: So it turns out the issue is in the setupTests.ts file where I am mocking the react-i18next, typescript was throwing an error when I tried to do "const actual = await vi.importActual(''react-i18next''); return {...actual, ...}" ignoring typescript works.
vi.mock('react-i18next', () => ({
...vi.importActual('react-i18next'), // this didn't work
useTranslation: () => [(key: any) => key],
}));
vi.mock('react-i18next', () => {
const acutal = vi.importActual('react-i18next'), // this didn't work either
return {
...actual,
useTranslation: () => [(key: any) => key],
};
});
vi.mock('react-i18next', async () => {
const actual = await vi.importActual('react-i18next'); // this works
return {
// @ts-ignore // have to put this here as typescript was complaining
...actual,
useTranslation: () => [(key: any) => key],
};
});
vite.config.ts
/// <reference types="vitest" />
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import tsconfigPaths from 'vite-tsconfig-paths';
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
react(),
tsconfigPaths(),
],
test: {
globals: true,
environment: 'jsdom',
setupFiles: './src/config/setupTests.ts',
css: true,
mockReset: true,
restoreMocks: true,
clearMocks: true,
include: ['./src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
exclude: [
'**/node_modules/**',
'**/dist/**',
'**/cypress/**',
'**/.{idea,git,cache,output,temp}/**',
'./src/config/**',
],
coverage: {
exclude: ['./src/config'],
},
},
}); ```