Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(typecheck): log tests with verbose reporter, correctly show "pass" tests #2656

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 34 additions & 7 deletions packages/vitest/src/typecheck/typechecker.ts
Expand Up @@ -3,7 +3,7 @@ import type { ExecaChildProcess } from 'execa'
import { execa } from 'execa'
import { extname, resolve } from 'pathe'
import { SourceMapConsumer } from 'source-map'
import { ensurePackageInstalled } from '../utils'
import { ensurePackageInstalled, getTasks } from '../utils'
import type { Awaitable, File, ParsedStack, Task, TaskResultPack, TaskState, TscErrorInfo, Vitest } from '../types'
import { getRawErrsMapFromTsCompile, getTsconfig } from './parse'
import { createIndexMap } from './utils'
Expand Down Expand Up @@ -77,6 +77,26 @@ export class Typechecker {
return tests
}

protected markPassed(file: File) {
if (!file.result?.state) {
file.result = {
state: 'pass',
}
}
const markTasks = (tasks: Task[]): void => {
for (const task of tasks) {
if ('tasks' in task)
markTasks(task.tasks)
if (!task.result?.state && task.mode === 'run') {
task.result = {
state: 'pass',
}
}
}
}
markTasks(file.tasks)
}

protected async prepareResults(output: string) {
const typeErrors = await this.parseTscLikeOutput(output)
const testFiles = new Set(this.getFiles())
Expand All @@ -91,18 +111,20 @@ export class Typechecker {
const { file, definitions, map, parsed } = this._tests![path]
const errors = typeErrors.get(path)
files.push(file)
if (!errors)
if (!errors) {
this.markPassed(file)
return
}
const sortedDefinitions = [...definitions.sort((a, b) => b.start - a.start)]
// has no map for ".js" files that use // @ts-check
const mapConsumer = map && new SourceMapConsumer(map)
const indexMap = createIndexMap(parsed)
const markFailed = (task: Task) => {
const markState = (task: Task, state: TaskState) => {
task.result = {
state: task.mode === 'run' || task.mode === 'only' ? 'fail' : task.mode,
state: task.mode === 'run' || task.mode === 'only' ? state : task.mode,
}
if (task.suite)
markFailed(task.suite)
markState(task.suite, state)
}
errors.forEach(({ error, originalError }) => {
const originalPos = mapConsumer?.generatedPositionFor({
Expand All @@ -121,8 +143,10 @@ export class Typechecker {
}
errors.push(error)
if (state === 'fail' && suite.suite)
markFailed(suite.suite)
markState(suite.suite, 'fail')
})

this.markPassed(file)
})

typeErrors.forEach((errors, path) => {
Expand Down Expand Up @@ -247,6 +271,9 @@ export class Typechecker {
}

public getTestPacks() {
return Object.values(this._tests || {}).map(i => [i.file.id, undefined] as TaskResultPack)
return Object.values(this._tests || {})
.map(({ file }) => getTasks(file))
.flat()
.map(i => [i.id, undefined] as TaskResultPack)
}
}