11import type { Task } from '@vitest/runner'
22import type { SnapshotSummary } from '@vitest/snapshot'
3+ import type { Formatter } from 'tinyrainbow'
34import { stripVTControlCharacters } from 'node:util'
45import { slash } from '@vitest/utils'
56import { basename , dirname , isAbsolute , relative } from 'pathe'
@@ -30,8 +31,18 @@ function getCols(delta = 0) {
3031 return Math . max ( length + delta , 0 )
3132}
3233
33- export function divider ( text ?: string , left ?: number , right ?: number ) : string {
34+ export function errorBanner ( message : string ) : string {
35+ return divider ( c . bold ( c . bgRed ( ` ${ message } ` ) ) , null , null , c . red )
36+ }
37+
38+ export function divider (
39+ text ?: string ,
40+ left ?: number | null ,
41+ right ?: number | null ,
42+ color ?: Formatter ,
43+ ) : string {
3444 const cols = getCols ( )
45+ const c = color || ( ( text : string ) => text )
3546
3647 if ( text ) {
3748 const textLength = stripVTControlCharacters ( text ) . length
@@ -44,7 +55,7 @@ export function divider(text?: string, left?: number, right?: number): string {
4455 }
4556 left = Math . max ( 0 , left )
4657 right = Math . max ( 0 , right )
47- return `${ F_LONG_DASH . repeat ( left ) } ${ text } ${ F_LONG_DASH . repeat ( right ) } `
58+ return `${ c ( F_LONG_DASH . repeat ( left ) ) } ${ text } ${ c ( F_LONG_DASH . repeat ( right ) ) } `
4859 }
4960 return F_LONG_DASH . repeat ( cols )
5061}
@@ -229,7 +240,8 @@ export function formatProjectName(name: string | undefined, suffix = ' '): strin
229240}
230241
231242export function withLabel ( color : 'red' | 'green' | 'blue' | 'cyan' | 'yellow' , label : string , message ?: string ) {
232- return `${ c . bold ( c . inverse ( c [ color ] ( ` ${ label } ` ) ) ) } ${ message ? c [ color ] ( message ) : '' } `
243+ const bgColor = `bg${ color . charAt ( 0 ) . toUpperCase ( ) } ${ color . slice ( 1 ) } ` as `bg${Capitalize < typeof color > } `
244+ return `${ c . bold ( c [ bgColor ] ( ` ${ label } ` ) ) } ${ message ? c [ color ] ( message ) : '' } `
233245}
234246
235247export function padSummaryTitle ( str : string ) : string {
0 commit comments