Skip to content

Commit

Permalink
fix(vitest): handle function config inside defineWorkspace (#5089)
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa authored Feb 5, 2024
1 parent 4a821b8 commit 0bf5253
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
19 changes: 15 additions & 4 deletions packages/vitest/src/node/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ViteNodeRunner } from 'vite-node/client'
import { SnapshotManager } from '@vitest/snapshot/manager'
import type { CancelReason, File } from '@vitest/runner'
import { ViteNodeServer } from 'vite-node/server'
import type { defineWorkspace } from 'vitest/config'
import type { ArgumentsType, CoverageProvider, OnServerRestartHandler, Reporter, ResolvedConfig, UserConfig, UserWorkspaceConfig, VitestRunMode } from '../types'
import { hasFailed, noop, slash, toArray } from '../utils'
import { getCoverageProvider } from '../integrations/coverage'
Expand Down Expand Up @@ -215,7 +216,7 @@ export class Vitest {
return [await this.createCoreProject()]

const workspaceModule = await this.runner.executeFile(workspaceConfigPath) as {
default: (string | UserWorkspaceConfig)[]
default: ReturnType<typeof defineWorkspace>
}

if (!workspaceModule.default || !Array.isArray(workspaceModule.default))
Expand All @@ -225,10 +226,20 @@ export class Vitest {
const projectsOptions: UserWorkspaceConfig[] = []

for (const project of workspaceModule.default) {
if (typeof project === 'string')
if (typeof project === 'string') {
workspaceGlobMatches.push(project.replace('<rootDir>', this.config.root))
else
projectsOptions.push(project)
}
else if (typeof project === 'function') {
projectsOptions.push(await project({
command: this.server.config.command,
mode: this.server.config.mode,
isPreview: false,
isSsrBuild: false,
}))
}
else {
projectsOptions.push(await project)
}
}

const globOptions: fg.Options = {
Expand Down
8 changes: 4 additions & 4 deletions test/workspaces/vitest.workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ import type { Plugin } from 'vite'
export default defineWorkspace([
'space_2',
'./space_*/*.config.ts',
{
async () => ({
test: {
name: 'happy-dom',
root: './space_shared',
environment: 'happy-dom',
setupFiles: ['./setup.jsdom.ts'],
},
},
{
}),
Promise.resolve({
test: {
name: 'node',
root: './space_shared',
environment: 'node',
setupFiles: ['./setup.node.ts'],
},
},
}),

// Projects testing pool and poolOptions
{
Expand Down

0 comments on commit 0bf5253

Please sign in to comment.