Как подключить jest к проекту на react + ts vite?
Пробовал как написано в доке jest но так у меня не работает. Постоянно вылетают ошибки то от бабеля то ts, то что-то с модулями, jsx, проблемы с import. Короче ад какой-то
jest.config.js
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
};
babel.config.js
module.exports = {
presets: ['@babel/preset-env', { targets: { node: 'current' } }],
plugins: ['@babel/plugin-transform-modules-commonjs'],
};
vite.config.ts
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import VitePluginSass from 'vite-plugin-sass';
export default defineConfig({
plugins: [react(), VitePluginSass()],
});
package.json
{
"name": "kanban-board",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"lint:fix": "yarn lint --fix",
"preview": "vite preview",
"test": "jest"
},
"dependencies": {
"@types/react-select": "^5.0.1",
"normalize.css": "^8.0.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.21.2",
"react-select": "^5.8.0",
"sass": "^1.69.7"
},
"devDependencies": {
"@babel/plugin-transform-runtime": "^7.23.7",
"@babel/preset-env": "^7.23.8",
"@babel/preset-react": "^7.23.3",
"@babel/preset-typescript": "^7.23.3",
"@testing-library/react": "^14.1.2",
"@types/react": "^18.2.43",
"@types/react-dom": "^18.2.17",
"@typescript-eslint/eslint-plugin": "^6.14.0",
"@typescript-eslint/parser": "^6.14.0",
"@vitejs/plugin-react": "^4.2.1",
"babel-jest": "^29.7.0",
"eslint": "^8.55.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.5",
"jest": "^29.7.0",
"react-test-renderer": "^18.2.0",
"ts-jest": "^29.1.1",
"typescript": "^5.3.3",
"vite": "^5.0.8",
"vite-plugin-sass": "^0.1.0"
}
}