typescript - ทำไมรายงานการครอบคลุมของ Vitest ถึงรายงานไฟล์ที่แค่ส่งออก enum?
เราดำเนินการตามนโยบายความครอบคลุมสาขา 100% เราไม่ติดตามฟังก์ชันหรือตัวบรรทัด เราพบว่านี่เป็นสมดุลที่ดีที่สุดระหว่างความครอบคลุมของโค้ดและผลผลิต ปัจจุบันเรามีปัญหาที่ vitest รายงานว่าไฟล์ต่อไปนี้มีสองสาขา:
export enum URL {
preSignedUploadUrl = '/case-document/upload/api?fileType=',
saveDocumentUploadToMongoUrl = '/case-document/upload/api?caseReference=',
}
ถ้าฉันเพิ่มการทดสอบต่อไปนี้ สาขาต่าง ๆ จะถูกครอบคลุม แต่ตามที่คุณเห็น พวกมันไม่ใช่การทดสอบหน่วยและไม่มีประโยชน์ใด ๆ
import {describe} from 'vitest'
import {URL} from '@config/urls'
describe('urls', () => {
it('has the correct URLs', () => {
expect(URL.preSignedUploadUrl).toEqual(
'/case-document/upload/api?fileType=',
)
expect(URL.saveDocumentUploadToMongoUrl).toEqual(
'/case-document/upload/api?caseReference=',
)
})
})
การตั้งค่า
const config = {
plugins: [react()],
test: {
coverage: {
provider: 'istanbul',
reporter: ['cobertura', 'json', 'html', 'text-summary'],
reportsDirectory: './coverage',
branches: 100,
all: true,
include: ['**/*.ts', '**/*.tsx'],
exclude: ['**/*.spec.ts', '**/*.spec.tsx', '.next/*'],
src: process.cwd() + '/src',
},
setupFiles: './setupTests.js',
exclude: [...configDefaults.exclude, './.next/'],
environment: 'happy-dom',
},
}
export default defineConfig(config)

