diff --git a/docs/advanced/reporters.md b/docs/advanced/reporters.md index faa34090ba68..d9dd0e1da6a0 100644 --- a/docs/advanced/reporters.md +++ b/docs/advanced/reporters.md @@ -402,6 +402,10 @@ declare class TestProject { * @experimental The public Vitest API is experimental and does not follow semver. */ readonly workspaceProject: WorkspaceProject + /** + * Vite's dev server instance. Every workspace project has its own server. + */ + readonly vite: ViteDevServer /** * Resolved project configuration. */ diff --git a/packages/vitest/src/node/reported-workspace-project.ts b/packages/vitest/src/node/reported-workspace-project.ts index 782b51968eba..06548785df7f 100644 --- a/packages/vitest/src/node/reported-workspace-project.ts +++ b/packages/vitest/src/node/reported-workspace-project.ts @@ -1,3 +1,4 @@ +import type { ViteDevServer } from 'vite' import type { ProvidedContext } from '../types/general' import type { Vitest } from './core' import type { ResolvedConfig, ResolvedProjectConfig, SerializedConfig } from './types/config' @@ -15,6 +16,10 @@ export class TestProject { */ public readonly workspaceProject: WorkspaceProject + /** + * Vite's dev server instance. Every workspace project has its own server. + */ + public readonly vite: ViteDevServer /** * Resolved project configuration. */ @@ -32,6 +37,7 @@ export class TestProject { constructor(workspaceProject: WorkspaceProject) { this.workspaceProject = workspaceProject this.vitest = workspaceProject.ctx + this.vite = workspaceProject.server this.globalConfig = workspaceProject.ctx.config this.config = workspaceProject.config this.name = workspaceProject.getName()