11import { DEFAULT_EXTENSIONS } from '../../constants.js' ;
22import type { IsPluginEnabled , Plugin , PluginOptions , ResolveConfig } from '../../types/config.js' ;
33import type { PackageJson } from '../../types/package-json.js' ;
4- import { type Input , toAlias , toDeferResolve , toDependency , toEntry } from '../../util/input.js' ;
4+ import { _glob } from '../../util/glob.js' ;
5+ import { type Input , toAlias , toConfig , toDeferResolve , toDependency , toEntry } from '../../util/input.js' ;
56import { join , toPosix } from '../../util/path.js' ;
67import { hasDependency } from '../../util/plugin.js' ;
78import { getEnvPackageName , getExternalReporters } from './helpers.js' ;
@@ -50,11 +51,21 @@ const findConfigDependencies = (localConfig: ViteConfig, options: PluginOptions)
5051 }
5152 }
5253
54+ const projectsDependencies : Input [ ] = [ ] ;
55+ if ( testConfig . projects !== undefined ) {
56+ for ( const projectConfig of testConfig . projects ) {
57+ if ( typeof projectConfig !== 'string' ) {
58+ projectsDependencies . push ( ...findConfigDependencies ( projectConfig , options ) ) ;
59+ }
60+ }
61+ }
62+
5363 return [
5464 ...[ ...environments , ...reporters , ...coverage ] . map ( id => toDependency ( id ) ) ,
5565 ...setupFiles ,
5666 ...globalSetup ,
5767 ...workspaceDependencies ,
68+ ...projectsDependencies ,
5869 ] ;
5970} ;
6071
@@ -67,10 +78,24 @@ const getConfigs = async (localConfig: ViteConfigOrFn | VitestWorkspaceConfig) =
6778 for ( const mode of [ 'development' , 'production' ] as MODE [ ] ) {
6879 const cfg = await config ( { command, mode, ssrBuild : undefined } ) ;
6980 configs . push ( cfg ) ;
81+ if ( cfg . test ?. projects ) {
82+ for ( const project of cfg . test . projects ) {
83+ if ( typeof project !== 'string' ) {
84+ configs . push ( project ) ;
85+ }
86+ }
87+ }
7088 }
7189 }
7290 } else {
7391 configs . push ( config ) ;
92+ if ( config . test ?. projects ) {
93+ for ( const project of config . test . projects ) {
94+ if ( typeof project !== 'string' ) {
95+ configs . push ( project ) ;
96+ }
97+ }
98+ }
7499 }
75100 }
76101 }
@@ -84,6 +109,23 @@ export const resolveConfig: ResolveConfig<ViteConfigOrFn | VitestWorkspaceConfig
84109
85110 const configs = await getConfigs ( localConfig ) ;
86111
112+ for ( const cfg of configs ) {
113+ if ( cfg . test ?. projects ) {
114+ for ( const project of cfg . test . projects ) {
115+ if ( typeof project === 'string' ) {
116+ const projectFiles = await _glob ( {
117+ cwd : options . cwd ,
118+ patterns : [ project ] ,
119+ gitignore : false ,
120+ } ) ;
121+ for ( const projectFile of projectFiles ) {
122+ inputs . add ( toConfig ( 'vitest' , projectFile , { containingFilePath : options . configFilePath } ) ) ;
123+ }
124+ }
125+ }
126+ }
127+ }
128+
87129 const addStar = ( value : string ) => ( value . endsWith ( '*' ) ? value : join ( value , '*' ) . replace ( / \/ \* \* $ / , '/*' ) ) ;
88130 const addAliases = ( aliasOptions : AliasOptions ) => {
89131 for ( const [ alias , value ] of Object . entries ( aliasOptions ) ) {
0 commit comments