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.
TypeScript
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576import type { BrowserInstanceOption } from 'vitest/node'import { expect } from 'vitest'
interface SummaryOptions { passed?: number}
expect.extend({ toReportPassedTest( stdout: string, testName: string, testProject?: string | BrowserInstanceOption[], ) { const checks: BrowserInstanceOption[] | undefined = Array.isArray(testProject) ? testProject : testProject && [{ browser: testProject }]
const pass = checks?.length ? checks.every(({ browser }) => { const includePattern = `✓ |${browser}| ${testName}` return stdout.includes(includePattern) }) : stdout.includes(`✓ ${testName}`)
return { pass, message: () => { const includePattern = checks?.length ? checks.map((check) => `✓ |${check.browser}| ${testName}`).join('\n') : `✓ ${testName}` return `expected ${pass ? 'not ' : ''}to have "${includePattern}" in the report.\n\nstdout:\n${stdout}` }, } }, toReportSummaryTestFiles(stdout: string, { passed }: SummaryOptions) { const includePattern = `Test Files ${passed} passed` const pass = !passed || stdout.includes(includePattern) return { pass, message: () => `expected ${pass ? 'not ' : ''}to have "${includePattern}" in the report.\n\nstdout:\n${stdout}`, } }, toReportSummaryTests(stdout: string, { passed }: SummaryOptions) { const includePattern = `Tests ${passed} passed` const pass = !passed || stdout.includes(includePattern) return { pass, message: () => `expected ${pass ? 'not ' : ''}to have "${includePattern}" in the report.\n\nstdout:\n${stdout}`, } }, toReportNoErrors(stderr: string) { const pass = !stderr return { pass, message: () => `expected ${pass ? 'not ' : ''}to have no errors.\n\nstderr:\n${stderr}`, } },})
declare module 'vitest' { interface Matchers<R> { // oxlint-disable-next-line typescript/method-signature-style toReportPassedTest(testName: string, testProject?: string | BrowserInstanceOption[]): R // oxlint-disable-next-line typescript/method-signature-style toReportSummaryTestFiles(options: SummaryOptions): R // oxlint-disable-next-line typescript/method-signature-style toReportSummaryTests(options: SummaryOptions): R // oxlint-disable-next-line typescript/method-signature-style toReportNoErrors(): R }}
export {}