[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

fix(vitest): handle function config inside `defineWorkspace` (#5089)

authored by

Hiroshi Ogawa and committed by
GitHub
(Feb 5, 2024, 1:12 PM +0100) 0bf52533 4a821b85

+19 -8
+4 -4
test/workspaces/vitest.workspace.ts
··· 6 6 export default defineWorkspace([ 7 7 'space_2', 8 8 './space_*/*.config.ts', 9 - { 9 + async () => ({ 10 10 test: { 11 11 name: 'happy-dom', 12 12 root: './space_shared', 13 13 environment: 'happy-dom', 14 14 setupFiles: ['./setup.jsdom.ts'], 15 15 }, 16 - }, 17 - { 16 + }), 17 + Promise.resolve({ 18 18 test: { 19 19 name: 'node', 20 20 root: './space_shared', 21 21 environment: 'node', 22 22 setupFiles: ['./setup.node.ts'], 23 23 }, 24 - }, 24 + }), 25 25 26 26 // Projects testing pool and poolOptions 27 27 {
+15 -4
packages/vitest/src/node/core.ts
··· 9 9 import { SnapshotManager } from '@vitest/snapshot/manager' 10 10 import type { CancelReason, File } from '@vitest/runner' 11 11 import { ViteNodeServer } from 'vite-node/server' 12 + import type { defineWorkspace } from 'vitest/config' 12 13 import type { ArgumentsType, CoverageProvider, OnServerRestartHandler, Reporter, ResolvedConfig, UserConfig, UserWorkspaceConfig, VitestRunMode } from '../types' 13 14 import { hasFailed, noop, slash, toArray } from '../utils' 14 15 import { getCoverageProvider } from '../integrations/coverage' ··· 215 216 return [await this.createCoreProject()] 216 217 217 218 const workspaceModule = await this.runner.executeFile(workspaceConfigPath) as { 218 - default: (string | UserWorkspaceConfig)[] 219 + default: ReturnType<typeof defineWorkspace> 219 220 } 220 221 221 222 if (!workspaceModule.default || !Array.isArray(workspaceModule.default)) ··· 225 226 const projectsOptions: UserWorkspaceConfig[] = [] 226 227 227 228 for (const project of workspaceModule.default) { 228 - if (typeof project === 'string') 229 + if (typeof project === 'string') { 229 230 workspaceGlobMatches.push(project.replace('<rootDir>', this.config.root)) 230 - else 231 - projectsOptions.push(project) 231 + } 232 + else if (typeof project === 'function') { 233 + projectsOptions.push(await project({ 234 + command: this.server.config.command, 235 + mode: this.server.config.mode, 236 + isPreview: false, 237 + isSsrBuild: false, 238 + })) 239 + } 240 + else { 241 + projectsOptions.push(await project) 242 + } 232 243 } 233 244 234 245 const globOptions: fg.Options = {