Skip to content

Commit

Permalink
feat: reprint all tests, if one of the test files was deleted (#1081)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
  • Loading branch information
sheremet-va and antfu committed Apr 3, 2022
1 parent 3c965d4 commit 2ded624
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/vitest/src/node/core.ts
Expand Up @@ -329,6 +329,7 @@ export class Vitest {
if (this.state.filesMap.has(id)) {
this.state.filesMap.delete(id)
this.changedTests.delete(id)
this.report('onTestRemoved', id)
}
}
const onAdd = async(id: string) => {
Expand Down
12 changes: 12 additions & 0 deletions packages/vitest/src/node/reporters/default.ts
@@ -1,3 +1,4 @@
import c from 'picocolors'
import type { UserConsoleLog } from '../../types'
import { BaseReporter } from './base'
import type { ListRendererOptions } from './renderers/listRenderer'
Expand All @@ -7,6 +8,17 @@ export class DefaultReporter extends BaseReporter {
renderer?: ReturnType<typeof createListRenderer>
rendererOptions: ListRendererOptions = {} as any

async onTestRemoved(trigger?: string) {
await this.stopListRender()
this.ctx.console.clear()
this.ctx.log(c.yellow('Test removed...') + (trigger ? c.dim(` [ ${this.relative(trigger)} ]\n`) : ''))
const files = this.ctx.state.getFiles(this.watchFilters)
createListRenderer(files, this.rendererOptions).stop()
this.ctx.log()
await super.reportSummary(files)
super.onWatcherStart()
}

onCollected() {
if (this.isTTY) {
this.rendererOptions.outputStream = this.ctx.outputStream
Expand Down
1 change: 1 addition & 0 deletions packages/vitest/src/types/reporter.ts
Expand Up @@ -8,6 +8,7 @@ export interface Reporter {
onFinished?: (files?: File[]) => Awaitable<void>
onTaskUpdate?: (packs: TaskResultPack[]) => Awaitable<void>

onTestRemoved?: (trigger?: string) => Awaitable<void>
onWatcherStart?: () => Awaitable<void>
onWatcherRerun?: (files: string[], trigger?: string) => Awaitable<void>

Expand Down

0 comments on commit 2ded624

Please sign in to comment.