Skip to content

Commit

Permalink
fix: display both ts and runtime tests in the terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Aug 13, 2024
1 parent 6aa70d6 commit ed33074
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
8 changes: 4 additions & 4 deletions packages/vitest/src/node/pools/typecheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { WorkspaceProject } from '../workspace'

export function createTypecheckPool(ctx: Vitest): ProcessPool {
const promisesMap = new WeakMap<WorkspaceProject, DeferPromise<void>>()
const rerunTriggered = new WeakMap<WorkspaceProject, boolean>()
const rerunTriggered = new WeakSet<WorkspaceProject>()

async function onParseEnd(
project: WorkspaceProject,
Expand All @@ -36,7 +36,7 @@ export function createTypecheckPool(ctx: Vitest): ProcessPool {

promisesMap.get(project)?.resolve()

rerunTriggered.set(project, false)
rerunTriggered.delete(project)

// triggered by TSC watcher, not Vitest watcher, so we need to emulate what Vitest does in this case
if (ctx.config.watch && !ctx.runningPromise) {
Expand Down Expand Up @@ -68,7 +68,7 @@ export function createTypecheckPool(ctx: Vitest): ProcessPool {
checker.onParseEnd(result => onParseEnd(project, result))

checker.onWatcherRerun(async () => {
rerunTriggered.set(project, true)
rerunTriggered.add(project)

if (!ctx.runningPromise) {
ctx.state.clearErrors()
Expand Down Expand Up @@ -123,7 +123,7 @@ export function createTypecheckPool(ctx: Vitest): ProcessPool {
// check that watcher actually triggered rerun
const _p = new Promise<boolean>((resolve) => {
const _i = setInterval(() => {
if (!project.typechecker || rerunTriggered.get(project)) {
if (!project.typechecker || rerunTriggered.has(project)) {
resolve(true)
clearInterval(_i)
}
Expand Down
8 changes: 4 additions & 4 deletions packages/vitest/src/node/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ export class StateManager {
collectFiles(project: WorkspaceProject, files: File[] = []) {
files.forEach((file) => {
const existing = this.filesMap.get(file.filepath) || []
const otherProject = existing.filter(
i => i.projectName !== file.projectName,
const otherFiles = existing.filter(
i => i.projectName !== file.projectName || i.meta.typecheck !== file.meta.typecheck,
)
const currentFile = existing.find(
i => i.projectName === file.projectName,
Expand All @@ -120,8 +120,8 @@ export class StateManager {
if (currentFile) {
file.logs = currentFile.logs
}
otherProject.push(file)
this.filesMap.set(file.filepath, otherProject)
otherFiles.push(file)
this.filesMap.set(file.filepath, otherFiles)
this.updateId(file, project)
})
}
Expand Down
6 changes: 6 additions & 0 deletions packages/vitest/src/typecheck/collect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ export async function collectTests(
const {
arguments: [messageNode],
} = node

if (!messageNode) {
// called as "test()"
return
}

const message = getNodeAsString(messageNode, request.code)

definitions.push({
Expand Down
2 changes: 1 addition & 1 deletion packages/ws-client/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class StateManager {
files.forEach((file) => {
const existing = this.filesMap.get(file.filepath) || []
const otherProject = existing.filter(
i => i.projectName !== file.projectName,
i => i.projectName !== file.projectName || i.meta.typecheck !== file.meta.typecheck,
)
const currentFile = existing.find(
i => i.projectName === file.projectName,
Expand Down

0 comments on commit ed33074

Please sign in to comment.