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.
1.1 kB · 33 lines
TypeScript
12345678910111213141516171819202122232425262728293031323334import type { CoverageMap, FileCoverage } from '@vitest/istanbul-lib-coverage'import { expect } from 'vitest'import { formatSummary } from './utils'
expect.addSnapshotSerializer({ test: (val) => val.constructor?.name === 'CoverageMap', serialize: (val: CoverageMap, config, indentation, depth, refs, printer) => { return printer(formatSummary(val.getCoverageSummary()), config, indentation, depth, refs) },})
expect.addSnapshotSerializer({ test: (val) => val.constructor?.name === 'FileCoverage', serialize: (val: FileCoverage, config, indentation, depth, refs, printer) => { return printer(formatSummary(val.toSummary()), config, indentation, depth, refs) },})
expect.addSnapshotSerializer({ test: (val) => Array.isArray(val) && val.every((entry) => entry.constructor.name === 'FileCoverage'), serialize: (val: FileCoverage[], config, indentation, depth, refs, printer) => { const summary = val.reduce( (all, current) => ({ ...all, [current.path]: formatSummary(current.toSummary()), }), {}, )
return printer(summary, config, indentation, depth, refs) },})