1
1
import { DEFAULT_EXTENSIONS } from '../../constants.js' ;
2
2
import type { IsPluginEnabled , Plugin , PluginOptions , ResolveConfig } from '../../types/config.js' ;
3
3
import 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' ;
5
6
import { join , toPosix } from '../../util/path.js' ;
6
7
import { hasDependency } from '../../util/plugin.js' ;
7
8
import { getEnvPackageName , getExternalReporters } from './helpers.js' ;
@@ -50,11 +51,21 @@ const findConfigDependencies = (localConfig: ViteConfig, options: PluginOptions)
50
51
}
51
52
}
52
53
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
+
53
63
return [
54
64
...[ ...environments , ...reporters , ...coverage ] . map ( id => toDependency ( id ) ) ,
55
65
...setupFiles ,
56
66
...globalSetup ,
57
67
...workspaceDependencies ,
68
+ ...projectsDependencies ,
58
69
] ;
59
70
} ;
60
71
@@ -67,10 +78,24 @@ const getConfigs = async (localConfig: ViteConfigOrFn | VitestWorkspaceConfig) =
67
78
for ( const mode of [ 'development' , 'production' ] as MODE [ ] ) {
68
79
const cfg = await config ( { command, mode, ssrBuild : undefined } ) ;
69
80
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
+ }
70
88
}
71
89
}
72
90
} else {
73
91
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
+ }
74
99
}
75
100
}
76
101
}
@@ -84,6 +109,23 @@ export const resolveConfig: ResolveConfig<ViteConfigOrFn | VitestWorkspaceConfig
84
109
85
110
const configs = await getConfigs ( localConfig ) ;
86
111
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
+
87
129
const addStar = ( value : string ) => ( value . endsWith ( '*' ) ? value : join ( value , '*' ) . replace ( / \/ \* \* $ / , '/*' ) ) ;
88
130
const addAliases = ( aliasOptions : AliasOptions ) => {
89
131
for ( const [ alias , value ] of Object . entries ( aliasOptions ) ) {
0 commit comments