diff --git a/.gitignore b/.gitignore index 65f85c9967dc..e6fecff012e2 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,4 @@ docs/public/user-avatars docs/public/sponsors .eslintcache docs/.vitepress/cache/ +!test/cwd/**/.cache diff --git a/packages/vitest/src/node/workspace.ts b/packages/vitest/src/node/workspace.ts index 6bef2aa640a4..52e4f0ec89ab 100644 --- a/packages/vitest/src/node/workspace.ts +++ b/packages/vitest/src/node/workspace.ts @@ -145,13 +145,13 @@ export class WorkspaceProject { async globFiles(include: string[], exclude: string[], cwd: string) { const globOptions: fg.Options = { - absolute: true, dot: true, cwd, ignore: exclude, } - return fg(include, globOptions) + const files = await fg(include, globOptions) + return files.map(file => resolve(cwd, file)) } async isTargetFile(id: string, source?: string): Promise { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 58ee55b81ae5..173fc0e1c1b9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1669,6 +1669,12 @@ importers: specifier: workspace:* version: link:../../packages/vitest + test/cwd: + devDependencies: + vitest: + specifier: workspace:* + version: link:../../packages/vitest + test/edge-runtime: devDependencies: '@edge-runtime/vm': diff --git a/test/cwd/.cache/projects/test/.cache/should-not-run.test.ts b/test/cwd/.cache/projects/test/.cache/should-not-run.test.ts new file mode 100644 index 000000000000..00d2519d3d5d --- /dev/null +++ b/test/cwd/.cache/projects/test/.cache/should-not-run.test.ts @@ -0,0 +1,5 @@ +import { expect, test } from 'vitest' + +test('should not run', () => { + expect(1).toBe(2) +}) diff --git a/test/cwd/.cache/projects/test/should-run.test.ts b/test/cwd/.cache/projects/test/should-run.test.ts new file mode 100644 index 000000000000..e59b8eb93108 --- /dev/null +++ b/test/cwd/.cache/projects/test/should-run.test.ts @@ -0,0 +1,5 @@ +import { expect, test } from 'vitest' + +test('should run', () => { + expect(1).toBe(1) +}) diff --git a/test/cwd/package.json b/test/cwd/package.json new file mode 100644 index 000000000000..5038c3661f1c --- /dev/null +++ b/test/cwd/package.json @@ -0,0 +1,10 @@ +{ + "name": "@vitest/test-cwd", + "private": true, + "scripts": { + "test": "cd $(pwd)/.cache/projects/test && vitest run" + }, + "devDependencies": { + "vitest": "workspace:*" + } +} diff --git a/test/cwd/vitest.config.ts b/test/cwd/vitest.config.ts new file mode 100644 index 000000000000..abed6b2116e1 --- /dev/null +++ b/test/cwd/vitest.config.ts @@ -0,0 +1,3 @@ +import { defineConfig } from 'vitest/config' + +export default defineConfig({})