From 64f302d0cf79c1a1597472b4469288a6b014bf68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Sat, 2 Apr 2022 01:35:20 +0900 Subject: [PATCH] fix: inconsistency with globTestFiles and isTargetFile (fix #981, #982) (#1070) --- packages/vitest/src/node/core.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/vitest/src/node/core.ts b/packages/vitest/src/node/core.ts index f6a1eb890677..a4b3868e2d4b 100644 --- a/packages/vitest/src/node/core.ts +++ b/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' @@ -430,11 +430,12 @@ export class Vitest { } async isTargetFile(id: string, source?: string): Promise { - 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) }