From 9b9bd4387ccd28453a695dfe3c84afd0e0909a75 Mon Sep 17 00:00:00 2001 From: Felix Kling Date: Fri, 17 Nov 2023 09:22:46 +0100 Subject: [PATCH] vitest: Fix workspace config wrt client/web/ (#58397) It appears that the workspace configuration is somehow broken because it doesn't include any tests defined in `client/web/src/`. This can be tested by filtering for a test inside this subtree, for example pnpm exec vitest RepoRevisionSidebar vitest will error saying it didn't find any tests. The list of projects it prints also doesn't include `web`. I don't know what exactly it is that makes it exclude `client/web/` but with the simpler version in this PR `client/web/` will be included. I removed `client/web/dev/` from the list because it will be included by `client/web/` too and seems to "just work" even though it has it's own configuration file. --- vitest.workspace.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/vitest.workspace.ts b/vitest.workspace.ts index 38bd39beb1d..733c5ee5a7e 100644 --- a/vitest.workspace.ts +++ b/vitest.workspace.ts @@ -1,18 +1,16 @@ -import { readFileSync, existsSync } from 'fs' +import { readFileSync } from 'fs' import path from 'path' -import glob from 'glob' import { load } from 'js-yaml' -import { defineWorkspace } from 'vitest/config' interface PnpmWorkspaceFile { packages: string[] } -const workspaceFile = load(readFileSync(path.join(__dirname, 'pnpm-workspace.yaml'), 'utf8')) as PnpmWorkspaceFile -workspaceFile.packages.push('client/web/dev') // is a tsconfig project but not a pnpm workspace package -const projectRoots = workspaceFile.packages - .flatMap(p => glob.sync(`${p}/`, { cwd: __dirname })) - .map(p => p.replace(/\/$/, '')) - .filter(dir => existsSync(path.join(dir, 'vitest.config.ts'))) -export default defineWorkspace(projectRoots) +function fromPnpmWorkspaceFile(filePath: string): string[] { + return (load(readFileSync(filePath, 'utf8')) as PnpmWorkspaceFile).packages.map(p => `${p}/vitest.config.ts`, { + cwd: __dirname, + }) +} + +export default fromPnpmWorkspaceFile(path.join(__dirname, 'pnpm-workspace.yaml'))