From bcc590888eb62af81d155206ed7b5a9408f6891a Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Tue, 29 Oct 2024 12:29:23 +0100 Subject: [PATCH] feat(experimental): expose vite on the test project as a separate field --- docs/advanced/reporters.md | 4 ++++ packages/vitest/src/node/reported-workspace-project.ts | 6 ++++++ 2 files changed, 10 insertions(+) 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()