[Frontend][UnitTests] Migrate frontend unit tests to vitest

This commit is contained in:
Aaro Koivukangas
2026-08-14 14:03:21 +03:00
parent 1da147503b
commit 7d3b7b8227
5 changed files with 403 additions and 517 deletions
+378 -509
View File
File diff suppressed because it is too large Load Diff
+3 -3
View File
@@ -7,7 +7,7 @@
"build": "tsc --noEmit && NODE_OPTIONS=\"--max-old-space-size=4096\" vite build", "build": "tsc --noEmit && NODE_OPTIONS=\"--max-old-space-size=4096\" vite build",
"preview": "vite preview", "preview": "vite preview",
"tsc": "tsc", "tsc": "tsc",
"test:unit": "node --import tsx --test './tests/unit/**/*test.ts' --test-reporter spec --test-force-exit", "test:unit": "vitest ./tests/unit",
"test:component": "playwright test -c playwright-ct.config.ts" "test:component": "playwright test -c playwright-ct.config.ts"
}, },
"dependencies": { "dependencies": {
@@ -48,8 +48,8 @@
"@types/react-dom": "^18.3.7", "@types/react-dom": "^18.3.7",
"@vitejs/plugin-react": "^6.0.3", "@vitejs/plugin-react": "^6.0.3",
"babel-plugin-react-compiler": "1.0.0", "babel-plugin-react-compiler": "1.0.0",
"tsx": "4.22.4",
"typescript": "^7.0.2", "typescript": "^7.0.2",
"vite": "^8.1.4" "vite": "^8.1.4",
"vitest": "4.1.9"
} }
} }
@@ -1,5 +1,4 @@
import assert from 'node:assert/strict' import { describe, it, assert } from 'vitest'
import { describe, it } from 'node:test'
import { makeTableStats } from '@/util/creditsProduced' import { makeTableStats } from '@/util/creditsProduced'
@@ -1,11 +1,9 @@
import assert from 'node:assert/strict'
import { describe, it } from 'node:test'
import { getProgressCriteria } from '@/redux/populations/criteriaProgress' import { getProgressCriteria } from '@/redux/populations/criteriaProgress'
import { CreditTypeCode, ProgressCriteria } from '@oodikone/shared/types' import { CreditTypeCode, ProgressCriteria } from '@oodikone/shared/types'
import { StudentStudyPlan } from '@oodikone/shared/types/studentData' import { StudentStudyPlan } from '@oodikone/shared/types/studentData'
import { PopulationCourseStatsCredit } from '@/redux/populations/util' import { PopulationCourseStatsCredit } from '@/redux/populations/util'
import { describe, it, assert } from 'vitest'
const createCriteria = (overrides: Partial<ProgressCriteria> = {}): ProgressCriteria => ({ const createCriteria = (overrides: Partial<ProgressCriteria> = {}): ProgressCriteria => ({
allCourseGroups: { allCourseGroups: {
+20
View File
@@ -0,0 +1,20 @@
import path from 'path'
import { defineConfig } from 'vitest/config'
// oxlint-disable-next-line no-default-export
export default defineConfig({
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
test: {
reporters: ['tree'],
exclude: ['./dist', 'node_modules'],
pool: 'threads',
testTimeout: 10_000, // 10s timeout
sequence: {
concurrent: true, // Enable parallel tests by default
},
},
})