Defining a Workspace
ts
export default [
'packages/*'
]
You can also reference projects with their config files:
ts
export default [
'packages/*''packages/*/vitest.config.{e2e,unit}.ts'
]
Running tests
json
{
"scripts": {
"test": "vitest"
}
}
bash
npm run test
bash
pnpm run test
bash
yarn run test
bash
bun run test
Configuration
ts
import { defineProject, mergeConfig } from 'vitest/config'
import configShared from '../vitest.shared.js'
export default mergeConfig(
configShared,
defineProject({
test: {
environment: 'jsdom',
}
})
)
Coverage
- Coverage สำหรับโปรเจ็กต์ใน workspace ทำงานได้ทันทีโดยไม่ต้องตั้งค่าเพิ่มเติม
- หากเปิดใช้ตัวเลือก
all
และใช้ไฟล์นามสกุลที่ไม่ใช่แบบมาตรฐานในบางโปรเจ็กต์ จำเป็นต้องเพิ่ม plugin ที่รองรับนามสกุลนั้นในไฟล์ตั้งค่าหลัก (root configuration) - ตัวอย่างเช่น หากมีแพ็คเกจที่ใช้ไฟล์ Vue และมีไฟล์ตั้งค่าของตัวเอง แต่บางไฟล์ไม่ได้ถูก import ในการทดสอบ การวิเคราะห์ coverage อาจล้มเหลวเมื่อพยายามวิเคราะห์ไฟล์ที่ไม่ได้ใช้
- เหตุผลคือ coverage จะอ้างอิงการตั้งค่าหลัก ไม่ใช่การตั้งค่าของแต่ละโปรเจ็กต์