Skip to content

Commit

Permalink
fix: correctly invalidate the test tree if the test file changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Sep 26, 2024
1 parent baf6157 commit bcfef17
Showing 1 changed file with 2 additions and 20 deletions.
22 changes: 2 additions & 20 deletions src/worker/vitest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,10 @@ export class Vitest implements VitestMethods {
return await this.ctx.globTestFiles(filters)
}

private coverageProcessedFiles = new Set<string>()

private invalidateTree(mod: any, seen = new Set()) {
if (seen.has(mod)) {
return
}
if (this.coverageProcessedFiles.has(mod.file)) {
return
}
this.coverageProcessedFiles.add(mod.file)
seen.add(mod)
this.ctx.server.moduleGraph.invalidateModule(mod)
mod.clientImportedModules.forEach((mod: any) => {
Expand All @@ -146,18 +140,6 @@ export class Vitest implements VitestMethods {
if (this.debug)
await this.globTestFiles(files)

if (this.coverage.resolved) {
files.forEach((file) => {
if (!this.coverageProcessedFiles.has(file)) {
const mod = this.ctx.server.moduleGraph.getModuleById(file)
if (mod) {
this.invalidateTree(mod)
}
this.coverageProcessedFiles.add(file)
}
})
}

await this.rerunTests(files, runAllFiles)
}

Expand Down Expand Up @@ -195,9 +177,9 @@ export class Vitest implements VitestMethods {
onFilesChanged(files: string[]) {
try {
for (const file of files) {
this.updateLastChanged(file)
const needRerun = this.handleFileChanged(file)
if (needRerun.length) {
this.updateLastChanged(file)
this.scheduleRerun(needRerun)
}
}
Expand All @@ -212,10 +194,10 @@ export class Vitest implements VitestMethods {
const testFiles: string[] = []

for (const file of files) {
this.updateLastChanged(file)
const content = readFileSync(file, 'utf-8')
for (const project of this.ctx.projects) {
if (await project.isTargetFile(file, content)) {
this.updateLastChanged(file)
testFiles.push(file)
}
}
Expand Down

0 comments on commit bcfef17

Please sign in to comment.