Skip to content

Commit

Permalink
fix: default reporter regression (#2292)
Browse files Browse the repository at this point in the history
* fix: default reporter regression

* chore: fix types
  • Loading branch information
antfu committed Nov 8, 2022
1 parent 922e525 commit f0b048b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
9 changes: 6 additions & 3 deletions packages/vitest/src/node/core.ts
Expand Up @@ -158,7 +158,8 @@ export class Vitest {
const checker = new Typechecker(this, testsFilesList)
this.typechecker = checker
checker.onParseEnd(async ({ files, sourceErrors }) => {
await this.report('onCollected', files)
this.state.collectFiles(checker.getTestFiles())
await this.report('onCollected')
if (!files.length)
this.logger.printNoTestFound()
else
Expand All @@ -181,12 +182,14 @@ export class Vitest {
})
checker.onParseStart(async () => {
await this.report('onInit', this)
await this.report('onCollected', checker.getTestFiles())
this.state.collectFiles(checker.getTestFiles())
await this.report('onCollected')
})
checker.onWatcherRerun(async () => {
await this.report('onWatcherRerun', testsFilesList, 'File change detected. Triggering rerun.')
await checker.collectTests()
await this.report('onCollected', checker.getTestFiles())
this.state.collectFiles(checker.getTestFiles())
await this.report('onCollected')
})
await checker.collectTests()
await checker.start()
Expand Down
7 changes: 3 additions & 4 deletions packages/vitest/src/node/reporters/default.ts
@@ -1,5 +1,5 @@
import c from 'picocolors'
import type { File, UserConsoleLog } from '../../types'
import type { UserConsoleLog } from '../../types'
import { BaseReporter } from './base'
import type { ListRendererOptions } from './renderers/listRenderer'
import { createListRenderer } from './renderers/listRenderer'
Expand All @@ -18,13 +18,12 @@ export class DefaultReporter extends BaseReporter {
super.onWatcherStart()
}

onCollected(files?: File[]) {
onCollected() {
if (this.isTTY) {
this.rendererOptions.logger = this.ctx.logger
this.rendererOptions.showHeap = this.ctx.config.logHeapUsage
this.rendererOptions.mode = this.mode
if (!files)
files = this.ctx.state.getFiles(this.watchFilters)
const files = this.ctx.state.getFiles(this.watchFilters)
if (!this.renderer)
this.renderer = createListRenderer(files, this.rendererOptions).start()
else
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/typecheck/collect.ts
Expand Up @@ -27,7 +27,7 @@ interface LocalCallDefinition {
}

export interface FileInformation {
file: ParsedFile
file: File
filepath: string
parsed: string
map: RawSourceMap | null
Expand Down
9 changes: 3 additions & 6 deletions packages/vitest/src/typecheck/typechecker.ts
Expand Up @@ -4,7 +4,7 @@ import { execa } from 'execa'
import { resolve } from 'pathe'
import { SourceMapConsumer } from 'source-map'
import { ensurePackageInstalled } from '../utils'
import type { Awaitable, File, ParsedStack, Task, TscErrorInfo, Vitest } from '../types'
import type { Awaitable, File, ParsedStack, Task, TaskState, TscErrorInfo, Vitest } from '../types'
import { getRawErrsMapFromTsCompile, getTsconfigPath } from './parse'
import { createIndexMap } from './utils'
import type { FileInformation } from './collect'
Expand Down Expand Up @@ -105,7 +105,7 @@ export class Typechecker {
const index = indexMap.get(`${originalPos.line}:${originalPos.column}`)
const definition = (index != null && sortedDefinitions.find(def => def.start <= index && def.end >= index)) || file
const suite = 'task' in definition ? definition.task : definition
const state = suite.mode === 'run' || suite.mode === 'only' ? 'fail' : suite.mode
const state: TaskState = suite.mode === 'run' || suite.mode === 'only' ? 'fail' : suite.mode
const task: Task = {
type: 'typecheck',
id: idx.toString(),
Expand Down Expand Up @@ -236,9 +236,6 @@ export class Typechecker {
}

public getTestFiles() {
return Object.values(this._tests || {}).map(({ file }) => ({
...file,
result: undefined,
}))
return Object.values(this._tests || {}).map(i => i.file)
}
}

0 comments on commit f0b048b

Please sign in to comment.