[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

refactor: use bg* colors in reporter instead of reversing (#7785)

authored by

Vladimir and committed by
GitHub
(Apr 4, 2025, 11:46 AM +0200) c45097ea ce2a06b7

+27 -19
+2 -2
packages/vitest/src/node/error.ts
··· 17 17 positionToOffset, 18 18 } from '../utils/source-map' 19 19 import { F_POINTER } from './reporters/renderers/figures' 20 - import { divider, truncateString } from './reporters/renderers/utils' 20 + import { divider, errorBanner, truncateString } from './reporters/renderers/utils' 21 21 22 22 type ErrorLogger = Pick<Logger, 'error' | 'highlight'> 23 23 ··· 246 246 } 247 247 248 248 function printErrorType(type: string, ctx: Vitest) { 249 - ctx.logger.error(`\n${c.red(divider(c.bold(c.inverse(` ${type} `))))}`) 249 + ctx.logger.error(`\n${errorBanner(type)}`) 250 250 } 251 251 252 252 const skipErrorProperties = new Set([
+3 -3
packages/vitest/src/node/logger.ts
··· 9 9 import c from 'tinyrainbow' 10 10 import { highlightCode } from '../utils/colors' 11 11 import { printError } from './error' 12 - import { divider, formatProjectName, withLabel } from './reporters/renderers/utils' 12 + import { divider, errorBanner, formatProjectName, withLabel } from './reporters/renderers/utils' 13 13 import { RandomSequencer } from './sequencers/RandomSequencer' 14 14 15 15 export interface ErrorOptions { ··· 262 262 + '\nThis might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.', 263 263 ), 264 264 ) 265 - this.error(c.red(divider(c.bold(c.inverse(' Unhandled Errors '))))) 265 + this.error(errorBanner('Unhandled Errors')) 266 266 this.error(errorMessage) 267 267 errors.forEach((err) => { 268 268 this.printError(err, { ··· 281 281 } not related to your test files.`, 282 282 ), 283 283 ) 284 - this.log(c.red(divider(c.bold(c.inverse(' Source Errors '))))) 284 + this.log(errorBanner('Source Errors')) 285 285 this.log(errorMessage) 286 286 errors.forEach((err) => { 287 287 this.printError(err, { fullStack: true })
+4 -4
packages/vitest/src/node/cli/cac.ts
··· 308 308 } 309 309 } 310 310 catch (e) { 311 - const { divider } = await import('../reporters/renderers/utils') 312 - console.error(`\n${c.red(divider(c.bold(c.inverse(' Startup Error '))))}`) 311 + const { errorBanner } = await import('../reporters/renderers/utils') 312 + console.error(`\n${errorBanner('Startup Error')}`) 313 313 console.error(e) 314 314 console.error('\n\n') 315 315 ··· 365 365 await ctx.close() 366 366 } 367 367 catch (e) { 368 - const { divider } = await import('../reporters/renderers/utils') 369 - console.error(`\n${c.red(divider(c.bold(c.inverse(' Collect Error '))))}`) 368 + const { errorBanner } = await import('../reporters/renderers/utils') 369 + console.error(`\n${errorBanner('Collect Error')}`) 370 370 console.error(e) 371 371 console.error('\n\n') 372 372
+2 -6
packages/vitest/src/node/reporters/base.ts
··· 12 12 import { isTTY } from '../../utils/env' 13 13 import { hasFailedSnapshot } from '../../utils/tasks' 14 14 import { F_CHECK, F_POINTER, F_RIGHT } from './renderers/figures' 15 - import { countTestErrors, divider, formatProjectName, formatTime, formatTimeString, getStateString, getStateSymbol, padSummaryTitle, renderSnapshotSummary, taskFail, withLabel } from './renderers/utils' 15 + import { countTestErrors, divider, errorBanner, formatProjectName, formatTime, formatTimeString, getStateString, getStateSymbol, padSummaryTitle, renderSnapshotSummary, taskFail, withLabel } from './renderers/utils' 16 16 17 17 const BADGE_PADDING = ' ' 18 18 ··· 609 609 } 610 610 611 611 this.ctx.logger.error( 612 - `${c.red(c.bold(c.inverse(' FAIL ')))} ${formatProjectName(projectName)}${name}`, 612 + `${c.bgRed(c.bold(' FAIL '))} ${formatProjectName(projectName)}${name}`, 613 613 ) 614 614 } 615 615 ··· 625 625 errorDivider() 626 626 } 627 627 } 628 - } 629 - 630 - function errorBanner(message: string) { 631 - return c.red(divider(c.bold(c.inverse(` ${message} `)))) 632 628 } 633 629 634 630 function sum<T>(items: T[], cb: (_next: T) => number | undefined) {
+1 -1
packages/vitest/src/node/reporters/basic.ts
··· 12 12 onInit(ctx: Vitest): void { 13 13 super.onInit(ctx) 14 14 15 - ctx.logger.log(c.inverse(c.bold(c.yellow(' DEPRECATED '))), c.yellow( 15 + ctx.logger.log(c.bold(c.bgYellow(' DEPRECATED ')), c.yellow( 16 16 `'basic' reporter is deprecated and will be removed in Vitest v3.\n` 17 17 + `Remove 'basic' from 'reporters' option. To match 'basic' reporter 100%, use configuration:\n${ 18 18 JSON.stringify({ test: { reporters: [['default', { summary: false }]] } }, null, 2)}`,
+15 -3
packages/vitest/src/node/reporters/renderers/utils.ts
··· 1 1 import type { Task } from '@vitest/runner' 2 2 import type { SnapshotSummary } from '@vitest/snapshot' 3 + import type { Formatter } from 'tinyrainbow' 3 4 import { stripVTControlCharacters } from 'node:util' 4 5 import { slash } from '@vitest/utils' 5 6 import { basename, dirname, isAbsolute, relative } from 'pathe' ··· 30 31 return Math.max(length + delta, 0) 31 32 } 32 33 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 { 34 44 const cols = getCols() 45 + const c = color || ((text: string) => text) 35 46 36 47 if (text) { 37 48 const textLength = stripVTControlCharacters(text).length ··· 44 55 } 45 56 left = Math.max(0, left) 46 57 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))}` 48 59 } 49 60 return F_LONG_DASH.repeat(cols) 50 61 } ··· 229 240 } 230 241 231 242 export 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) : ''}` 233 245 } 234 246 235 247 export function padSummaryTitle(str: string): string {