Просмотр исходного кода

chore(01-01): install Vitest and React Testing Library

- Add vitest, @vitest/ui, jsdom as dev dependencies
- Add @testing-library/react, @testing-library/jest-dom, @testing-library/user-event
- Create vitest.config.ts with jsdom environment, globals, and coverage
- Create src/test/setup.ts with jest-dom matchers and cleanup
- Add test scripts: test, test:watch, test:ui, test:coverage
tuanchris 1 неделя назад
Родитель
Сommit
d187f6567c
4 измененных файлов с 787 добавлено и 52 удалено
  1. 746 50
      frontend/package-lock.json
  2. 12 2
      frontend/package.json
  3. 8 0
      frontend/src/test/setup.ts
  4. 21 0
      frontend/vitest.config.ts

Разница между файлами не показана из-за своего большого размера
+ 746 - 50
frontend/package-lock.json


+ 12 - 2
frontend/package.json

@@ -7,7 +7,11 @@
     "dev": "vite --host",
     "build": "tsc -b && vite build",
     "lint": "eslint .",
-    "preview": "vite preview --host"
+    "preview": "vite preview --host",
+    "test": "vitest run",
+    "test:watch": "vitest",
+    "test:ui": "vitest --ui",
+    "test:coverage": "vitest run --coverage"
   },
   "dependencies": {
     "@dnd-kit/core": "^6.3.1",
@@ -41,11 +45,15 @@
   },
   "devDependencies": {
     "@eslint/js": "^9.39.1",
+    "@testing-library/jest-dom": "^6.9.1",
+    "@testing-library/react": "^16.3.2",
+    "@testing-library/user-event": "^14.6.1",
     "@types/node": "^24.10.4",
     "@types/react": "^19.2.5",
     "@types/react-color": "^3.0.13",
     "@types/react-dom": "^19.2.3",
     "@vitejs/plugin-react": "^5.1.1",
+    "@vitest/ui": "^3.2.4",
     "autoprefixer": "^10.4.23",
     "class-variance-authority": "^0.7.1",
     "clsx": "^2.1.1",
@@ -53,6 +61,7 @@
     "eslint-plugin-react-hooks": "^7.0.1",
     "eslint-plugin-react-refresh": "^0.4.24",
     "globals": "^16.5.0",
+    "jsdom": "^27.0.1",
     "lucide-react": "^0.562.0",
     "postcss": "^8.5.6",
     "shadcn": "^3.7.0",
@@ -62,6 +71,7 @@
     "typescript": "~5.9.3",
     "typescript-eslint": "^8.46.4",
     "vite": "^7.2.4",
-    "vite-plugin-pwa": "^1.2.0"
+    "vite-plugin-pwa": "^1.2.0",
+    "vitest": "^3.2.4"
   }
 }

+ 8 - 0
frontend/src/test/setup.ts

@@ -0,0 +1,8 @@
+import '@testing-library/jest-dom/vitest'
+import { cleanup } from '@testing-library/react'
+import { afterEach } from 'vitest'
+
+// Cleanup after each test
+afterEach(() => {
+  cleanup()
+})

+ 21 - 0
frontend/vitest.config.ts

@@ -0,0 +1,21 @@
+/// <reference types="vitest" />
+import { defineConfig, mergeConfig } from 'vitest/config'
+import viteConfig from './vite.config'
+
+export default mergeConfig(
+  viteConfig,
+  defineConfig({
+    test: {
+      globals: true,
+      environment: 'jsdom',
+      setupFiles: ['./src/test/setup.ts'],
+      include: ['src/**/*.{test,spec}.{ts,tsx}'],
+      coverage: {
+        provider: 'v8',
+        reporter: ['text', 'json', 'html'],
+        include: ['src/**/*.{ts,tsx}'],
+        exclude: ['src/**/*.{test,spec}.{ts,tsx}', 'src/test/**'],
+      },
+    },
+  })
+)

Некоторые файлы не были показаны из-за большого количества измененных файлов