Skip to content

Commit

Permalink
fix(vitest): apply slowTestThreshold to all reporters (#4876)
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Jan 5, 2024
1 parent 7719e79 commit 1769c79
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
Expand Up @@ -22,6 +22,7 @@ export class TableReporter extends BaseReporter {
if (this.isTTY) {
this.rendererOptions.logger = this.ctx.logger
this.rendererOptions.showHeap = this.ctx.config.logHeapUsage
this.rendererOptions.slowTestThreshold = this.ctx.config.slowTestThreshold
const files = this.ctx.state.getFiles(this.watchFilters)
if (!this.renderer)
this.renderer = createTableRenderer(files, this.rendererOptions).start()
Expand Down
Expand Up @@ -11,10 +11,9 @@ export interface ListRendererOptions {
renderSucceed?: boolean
logger: Logger
showHeap: boolean
slowTestThreshold: number
}

const DURATION_LONG = 300

const outputMap = new WeakMap<Task, string>()

function formatFilepath(path: string) {
Expand Down Expand Up @@ -121,7 +120,7 @@ export function renderTree(tasks: Task[], options: ListRendererOptions, level =
suffix += ` ${c.dim(c.gray('[skipped]'))}`

if (task.result?.duration != null) {
if (task.result.duration > DURATION_LONG)
if (task.result.duration > options.slowTestThreshold)
suffix += c.yellow(` ${Math.round(task.result.duration)}${c.dim('ms')}`)
}

Expand Down
1 change: 1 addition & 0 deletions packages/vitest/src/node/reporters/default.ts
Expand Up @@ -33,6 +33,7 @@ export class DefaultReporter extends BaseReporter {
if (this.isTTY) {
this.rendererOptions.logger = this.ctx.logger
this.rendererOptions.showHeap = this.ctx.config.logHeapUsage
this.rendererOptions.slowTestThreshold = this.ctx.config.slowTestThreshold
this.rendererOptions.mode = this.mode
const files = this.ctx.state.getFiles(this.watchFilters)
if (!this.renderer)
Expand Down
5 changes: 2 additions & 3 deletions packages/vitest/src/node/reporters/renderers/listRenderer.ts
Expand Up @@ -11,11 +11,10 @@ export interface ListRendererOptions {
renderSucceed?: boolean
logger: Logger
showHeap: boolean
slowTestThreshold: number
mode: VitestRunMode
}

const DURATION_LONG = 300

const outputMap = new WeakMap<Task, string>()

function formatFilepath(path: string) {
Expand Down Expand Up @@ -115,7 +114,7 @@ export function renderTree(tasks: Task[], options: ListRendererOptions, level =
suffix += c.yellow(` (repeat x${task.result.repeatCount})`)

if (task.result?.duration != null) {
if (task.result.duration > DURATION_LONG)
if (task.result.duration > options.slowTestThreshold)
suffix += c.yellow(` ${Math.round(task.result.duration)}${c.dim('ms')}`)
}

Expand Down

0 comments on commit 1769c79

Please sign in to comment.