Skip to content

Commit

Permalink
fix: inconsistency with globTestFiles and isTargetFile (fix #981, #982)…
Browse files Browse the repository at this point in the history
… (#1070)
  • Loading branch information
sapphi-red committed Apr 1, 2022
1 parent cadefe5 commit 64f302d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/vitest/src/node/core.ts
@@ -1,6 +1,6 @@
import { existsSync, promises as fs } from 'fs'
import type { ViteDevServer } from 'vite'
import { toNamespacedPath } from 'pathe'
import { relative, toNamespacedPath } from 'pathe'
import fg from 'fast-glob'
import mm from 'micromatch'
import c from 'picocolors'
Expand Down Expand Up @@ -430,11 +430,12 @@ export class Vitest {
}

async isTargetFile(id: string, source?: string): Promise<boolean> {
if (mm.isMatch(id, this.config.exclude))
const relativeId = relative(this.config.dir || this.config.root, id)
if (mm.isMatch(relativeId, this.config.exclude))
return false
if (mm.isMatch(id, this.config.include))
if (mm.isMatch(relativeId, this.config.include))
return true
if (this.config.includeSource?.length && mm.isMatch(id, this.config.includeSource)) {
if (this.config.includeSource?.length && mm.isMatch(relativeId, this.config.includeSource)) {
source = source || await fs.readFile(id, 'utf-8')
return this.isInSourceTestFile(source)
}
Expand Down

0 comments on commit 64f302d

Please sign in to comment.