Vitest
Features
- Vite's config, transformers, resolvers, and plugins.
- Use the same setup from your app to run the tests!
- Smart & instant watch mode, like HMR for tests!
- Components testing for Vue, React, Svelte, Lit and more
- Out-of-box TypeScript / JSX support
- ESM first, top level await
- Workers multi-threading via tinypool
- Filtering, timeouts, concurrent for suite and tests
- Jest Snapshot
- Chai built-in for assertions + Jest expect compatible APIs
- Tinyspy built-in for mocking
- happy-dom or jsdom for DOM mocking
- Native code coverage via c8
- Rust like in-source testing
vi.hoisted 에서 정적 import 사용 불가
"IMPORTS ARE NOT AVAILABLE" 라고 대문짝만하게 적혀있다.
Vitest 워커 수 줄이기
일회성: 실행 플래그
./npm run test:run -- --maxWorkers=4
./npm run test:run -- --maxWorkers=25% # 코어 대비 비율
./npm run test:run -- --no-file-parallelism # 파일을 하나씩 순차 실행
상시: 설정 파일
Vitest 4 에서는 예전 poolOptions.threads.maxThreads 대신 test 바로 아래의 maxWorkers 를 쓴다.
OS 수준의 리소스 상한
Vitest 설정과 무관하게 CPU·메모리를 확실하게 묶는다.
| 도구 | 효과 | 비고 |
| cgroup 으로 CPU 합계·메모리 제한 | 메모리 초과 시 테스트 프로세스만 종료, 시스템은 유지 | |
| 우선순위만 낮춤 | 코어는 다 쓰지만 다른 작업이 먼저 돌아 체감 끊김 감소 | |
| 지정한 코어에만 고정 | 코어 수 단위로 확실히 제한 |
systemd-run --user --scope -p CPUQuota=400% -p MemoryMax=12G ./npm run test:run
nice -n 19 ./npm run test:run
taskset -c 0-3 ./npm run test:run
워커별 Node 힙 제한
한도에 걸린 워커는 OOM(메모리 부족)으로 죽어 테스트가 실패한다는 점에 주의.
See also
이 문서를 가리키는 문서