Skip to content

Commit

Permalink
fix: apply check only for absolute files
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Apr 2, 2024
1 parent 2e70a3c commit d747c4c
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions packages/vitest/src/node/workspace.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { promises as fs } from 'node:fs'
import fg from 'fast-glob'
import mm from 'micromatch'
import { dirname, join, relative, resolve, toNamespacedPath } from 'pathe'
import { dirname, isAbsolute, join, relative, resolve, toNamespacedPath } from 'pathe'
import type { TransformResult, ViteDevServer, InlineConfig as ViteInlineConfig } from 'vite'
import { ViteNodeRunner } from 'vite-node/client'
import { ViteNodeServer } from 'vite-node/server'
Expand Down Expand Up @@ -257,7 +257,7 @@ export class WorkspaceProject {
return code.includes('import.meta.vitest')
}

filterFiles(testFiles: string[], filters: string[] = [], dir: string) {
filterFiles(testFiles: string[], filters: string[], dir: string) {
if (filters.length && process.platform === 'win32')
filters = filters.map(f => toNamespacedPath(f))

Expand All @@ -267,11 +267,14 @@ export class WorkspaceProject {
return filters.some((f) => {
const relativePath = f.endsWith('/') ? join(relative(dir, f), '/') : relative(dir, f)

// the file is inside the filter path, so we should always include it,
// we don't include ../file because this condition is always true if
// the file doens't exist which cause false positives
if (relativePath === '..' || relativePath === '../' || relativePath.startsWith('../..'))
return true
// if filter is a full file path, we should include it if it's in the same folder
if (isAbsolute(f)) {
// the file is inside the filter path, so we should always include it,
// we don't include ../file because this condition is always true if
// the file doens't exist which cause false positives
if (relativePath === '..' || relativePath === '../' || relativePath.startsWith('../..'))
return true
}

return testFile.includes(f.toLocaleLowerCase()) || testFile.includes(relativePath.toLocaleLowerCase())
})
Expand Down

0 comments on commit d747c4c

Please sign in to comment.