Skip to content

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

  1. Coverage สำหรับโปรเจ็กต์ใน workspace ทำงานได้ทันทีโดยไม่ต้องตั้งค่าเพิ่มเติม
  2. หากเปิดใช้ตัวเลือก all และใช้ไฟล์นามสกุลที่ไม่ใช่แบบมาตรฐานในบางโปรเจ็กต์ จำเป็นต้องเพิ่ม plugin ที่รองรับนามสกุลนั้นในไฟล์ตั้งค่าหลัก (root configuration)
  3. ตัวอย่างเช่น หากมีแพ็คเกจที่ใช้ไฟล์ Vue และมีไฟล์ตั้งค่าของตัวเอง แต่บางไฟล์ไม่ได้ถูก import ในการทดสอบ การวิเคราะห์ coverage อาจล้มเหลวเมื่อพยายามวิเคราะห์ไฟล์ที่ไม่ได้ใช้
  4. เหตุผลคือ coverage จะอ้างอิงการตั้งค่าหลัก ไม่ใช่การตั้งค่าของแต่ละโปรเจ็กต์

Released under the MIT License