Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263import { hasFailedSnapshot } from '@vitest/ws-client'import type { Benchmark, Task, Test, TypeCheck } from 'vitest/src'import { files, testRunState } from '~/composables/client'
type Nullable<T> = T | null | undefinedtype Arrayable<T> = T | Array<T>
// filesexport const filesFailed = computed(() => files.value.filter(f => f.result?.state === 'fail'))export const filesSuccess = computed(() => files.value.filter(f => f.result?.state === 'pass'))export const filesIgnore = computed(() => files.value.filter(f => f.mode === 'skip' || f.mode === 'todo'))export const filesRunning = computed(() => files.value.filter(f => !filesFailed.value.includes(f) && !filesSuccess.value.includes(f) && !filesIgnore.value.includes(f),))export const filesSkipped = computed(() => filesIgnore.value.filter(f => f.mode === 'skip'))export const filesSnapshotFailed = computed(() => files.value.filter(hasFailedSnapshot))export const filesTodo = computed(() => filesIgnore.value.filter(f => f.mode === 'todo'))export const finished = computed(() => testRunState.value === 'idle')// testsexport const tests = computed(() => { return getTests(files.value)})export const testsFailed = computed(() => { return tests.value.filter(f => f.result?.state === 'fail')})export const testsSuccess = computed(() => { return tests.value.filter(f => f.result?.state === 'pass')})export const testsIgnore = computed(() => tests.value.filter(f => f.mode === 'skip' || f.mode === 'todo'))export const testsSkipped = computed(() => testsIgnore.value.filter(f => f.mode === 'skip'))export const testsTodo = computed(() => testsIgnore.value.filter(f => f.mode === 'todo'))export const totalTests = computed(() => testsFailed.value.length + testsSuccess.value.length)export const time = computed(() => { const t = getTests(tests.value).reduce((acc, t) => { acc += Math.max(0, t.collectDuration || 0) acc += Math.max(0, t.setupDuration || 0) acc += Math.max(0, t.result?.duration || 0) return acc }, 0)
if (t > 1000) return `${(t / 1000).toFixed(2)}s`
return `${Math.round(t)}ms`})
function toArray<T>(array?: Nullable<Arrayable<T>>): Array<T> { array = array || [] if (Array.isArray(array)) return array return [array]}
function isAtomTest(s: Task): s is Test | Benchmark | TypeCheck { return (s.type === 'test' || s.type === 'benchmark' || s.type === 'typecheck')}
function getTests(suite: Arrayable<Task>): (Test | Benchmark | TypeCheck)[] { return toArray(suite).flatMap(s => isAtomTest(s) ? [s] : s.tasks.flatMap(c => isAtomTest(c) ? [c] : getTests(c)))}