Skip to content

Commit

Permalink
feat: less verbose CI output by default (#1087)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Apr 6, 2022
1 parent eb13d34 commit a06f247
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
26 changes: 21 additions & 5 deletions packages/vitest/src/node/reporters/base.ts
Expand Up @@ -6,7 +6,7 @@ import { getFullName, getSuites, getTests, hasFailed, hasFailedSnapshot } from '
import type { Vitest } from '../../node'
import { version } from '../../../package.json'
import { F_RIGHT } from '../../utils/figures'
import { divider, getStateString, getStateSymbol, renderSnapshotSummary } from './renderers/utils'
import { divider, getStateString, getStateSymbol, pointer, renderSnapshotSummary } from './renderers/utils'

const BADGE_PADDING = ' '
const HELP_HINT = `${c.dim('press ')}${c.bold('h')}${c.dim(' to show help')}`
Expand Down Expand Up @@ -63,10 +63,26 @@ export abstract class BaseReporter implements Reporter {
return
for (const pack of packs) {
const task = this.ctx.state.idMap.get(pack[0])
if (task && task.type === 'test' && task.result?.state && task.result?.state !== 'run') {
this.ctx.log(` ${getStateSymbol(task)} ${getFullName(task)}`)
if (task.result.state === 'fail')
this.ctx.log(c.red(` ${F_RIGHT} ${(task.result.error as any)?.message}`))
if (task && 'filepath' in task && task.result?.state && task.result?.state !== 'run') {
const tests = getTests(task)
const failed = tests.filter(t => t.result?.state === 'fail')
const skipped = tests.filter(t => t.mode === 'skip' || t.mode === 'todo')
let state = c.dim(`${tests.length} test${tests.length > 1 ? 's' : ''}`)
if (failed.length)
state += ` ${c.dim('|')} ${c.red(`${failed.length} failed`)}`
if (skipped.length)
state += ` ${c.dim('|')} ${c.yellow(`${skipped.length} skipped`)}`
let suffix = c.dim(' (') + state + c.dim(')')
if (task.result.duration)
suffix += c.yellow(` ${Math.round(task.result.duration)}${c.dim('ms')}`)

this.ctx.log(` ${getStateSymbol(task)} ${task.name} ${suffix}`)

// print short errors, full errors will be at the end in summary
for (const test of failed) {
this.ctx.log(c.red(` ${pointer} ${getFullName(test)}`))
this.ctx.log(c.red(` ${F_RIGHT} ${(test.result!.error as any)?.message}`))
}
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions packages/vitest/src/node/reporters/verbose.ts
@@ -1,8 +1,26 @@
import c from 'picocolors'
import type { TaskResultPack } from '../../types'
import { getFullName } from '../../utils'
import { F_RIGHT } from '../../utils/figures'
import { DefaultReporter } from './default'
import { getStateSymbol } from './renderers/utils'

export class VerboseReporter extends DefaultReporter {
constructor() {
super()
this.rendererOptions.renderSucceed = true
}

onTaskUpdate(packs: TaskResultPack[]) {
if (this.isTTY)
return
for (const pack of packs) {
const task = this.ctx.state.idMap.get(pack[0])
if (task && task.type === 'test' && task.result?.state && task.result?.state !== 'run') {
this.ctx.log(` ${getStateSymbol(task)} ${getFullName(task)}`)
if (task.result.state === 'fail')
this.ctx.log(c.red(` ${F_RIGHT} ${(task.result.error as any)?.message}`))
}
}
}
}

0 comments on commit a06f247

Please sign in to comment.