Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add "configureVitest" plugin #7349

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: add "configureVitest" plugin
sheremet-va committed Jan 23, 2025
commit e48a33b90985785088049d0fbdd3d3bd6453486c
6 changes: 6 additions & 0 deletions packages/vitest/src/node/core.ts
Original file line number Diff line number Diff line change
@@ -279,6 +279,12 @@ export class Vitest {
const projects = await this.resolveWorkspace(cliOptions)
this.resolvedProjects = projects
this.projects = projects

await Promise.all(projects.flatMap((project) => {
const hooks = project.vite.pluginContainer.getSortedPluginHooks('configureVitest')
return hooks.map(hook => hook({ project }))
}))

if (!this.projects.length) {
throw new Error(`No projects matched the filter "${toArray(resolved.project).join('", "')}".`)
}
11 changes: 11 additions & 0 deletions packages/vitest/src/node/types/vite.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
import type { HookHandler } from 'vite'
import type { TestProject } from '../project'
import type { InlineConfig } from './config'

type VitestInlineConfig = InlineConfig

interface VitestPluginContext {
project: TestProject
}

declare module 'vite' {
interface UserConfig {
/**
* Options for Vitest
*/
test?: VitestInlineConfig
}

// eslint-disable-next-line unused-imports/no-unused-vars
interface Plugin<A = any> {
configureVitest: HookHandler<(context: VitestPluginContext) => void>
}
}

export {}