Skip to content

Commit

Permalink
feat: show start time in test summary (#1734)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Kidder <mikekidder@hotmail.com>
Co-authored-by: Vladimir <sheremet.va@icloud.com>
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
  • Loading branch information
4 people committed Aug 2, 2022
1 parent c18f0af commit 7e3f63b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/vitest/src/node/reporters/base.ts
Expand Up @@ -4,7 +4,7 @@ import type { ErrorWithDiff, File, Reporter, Task, TaskResultPack, UserConsoleLo
import { clearInterval, getFullName, getSuites, getTests, hasFailed, hasFailedSnapshot, isNode, relativePath, setInterval } from '../../utils'
import type { Vitest } from '../../node'
import { F_RIGHT } from '../../utils/figures'
import { divider, getStateString, getStateSymbol, pointer, renderSnapshotSummary } from './renderers/utils'
import { divider, formatTimeString, 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 All @@ -28,6 +28,7 @@ export abstract class BaseReporter implements Reporter {
private _lastRunTimeout = 0
private _lastRunTimer: NodeJS.Timer | undefined
private _lastRunCount = 0
private _timeStart = new Date()

constructor() {
this.registerUnhandledRejection()
Expand Down Expand Up @@ -158,6 +159,7 @@ export abstract class BaseReporter implements Reporter {
this.ctx.logger.clearScreen(`\n${BADGE}${TRIGGER} ${c.blue(`x${rerun}`)}\n`)
}

this._timeStart = new Date()
this.start = performance.now()
}

Expand Down Expand Up @@ -233,10 +235,11 @@ export abstract class BaseReporter implements Reporter {

logger.log(padTitle('Test Files'), getStateString(files))
logger.log(padTitle('Tests'), getStateString(tests))
logger.log(padTitle('Start at'), formatTimeString(this._timeStart))
if (this.watchFilters)
logger.log(padTitle('Time'), time(threadTime))
logger.log(padTitle('Duration'), time(threadTime))
else
logger.log(padTitle('Time'), time(executionTime) + c.gray(` (setup ${time(setupTime)}, collect ${time(collectTime)}, tests ${time(testsTime)})`))
logger.log(padTitle('Duration'), time(executionTime) + c.gray(` (setup ${time(setupTime)}, collect ${time(collectTime)}, tests ${time(testsTime)})`))

logger.log()
}
Expand Down
4 changes: 4 additions & 0 deletions packages/vitest/src/node/reporters/renderers/utils.ts
Expand Up @@ -170,3 +170,7 @@ export function elegantSpinner() {
return spinnerFrames[index]
}
}

export function formatTimeString(date: Date) {
return date.toTimeString().split(' ')[0]
}

0 comments on commit 7e3f63b

Please sign in to comment.