@@ -152,7 +152,9 @@ export class Vitest {
152
152
}
153
153
154
154
private async resolveWorkspace ( options : UserConfig , cliOptions : UserConfig ) {
155
- const configDir = dirname ( this . server . config . configFile || this . config . root )
155
+ const configDir = this . server . config . configFile
156
+ ? dirname ( this . server . config . configFile )
157
+ : this . config . root
156
158
const rootFiles = await fs . readdir ( configDir )
157
159
const workspaceConfigName = workspaceFiles . find ( ( configFile ) => {
158
160
return rootFiles . includes ( configFile )
@@ -161,21 +163,21 @@ export class Vitest {
161
163
if ( ! workspaceConfigName )
162
164
return [ await this . createCoreWorkspace ( options ) ]
163
165
164
- const workspacesConfigPath = join ( configDir , workspaceConfigName )
166
+ const workspaceConfigPath = join ( configDir , workspaceConfigName )
165
167
166
- const workspacesModule = await this . runner . executeFile ( workspacesConfigPath ) as {
168
+ const workspaceModule = await this . runner . executeFile ( workspaceConfigPath ) as {
167
169
default : ( string | UserWorkspaceConfig ) [ ]
168
170
}
169
171
170
- if ( ! workspacesModule . default || ! Array . isArray ( workspacesModule . default ) )
171
- throw new Error ( `Workspace config file ${ workspacesConfigPath } must export a default array of project paths.` )
172
+ if ( ! workspaceModule . default || ! Array . isArray ( workspaceModule . default ) )
173
+ throw new Error ( `Workspace config file ${ workspaceConfigPath } must export a default array of project paths.` )
172
174
173
- const workspacesGlobMatches : string [ ] = [ ]
175
+ const workspaceGlobMatches : string [ ] = [ ]
174
176
const projectsOptions : UserWorkspaceConfig [ ] = [ ]
175
177
176
- for ( const project of workspacesModule . default ) {
178
+ for ( const project of workspaceModule . default ) {
177
179
if ( typeof project === 'string' )
178
- workspacesGlobMatches . push ( project . replace ( '<rootDir>' , this . config . root ) )
180
+ workspaceGlobMatches . push ( project . replace ( '<rootDir>' , this . config . root ) )
179
181
else
180
182
projectsOptions . push ( project )
181
183
}
@@ -189,7 +191,7 @@ export class Vitest {
189
191
ignore : [ '**/node_modules/**' ] ,
190
192
}
191
193
192
- const workspacesFs = await fg ( workspacesGlobMatches , globOptions )
194
+ const workspacesFs = await fg ( workspaceGlobMatches , globOptions )
193
195
const resolvedWorkspacesPaths = await Promise . all ( workspacesFs . filter ( ( file ) => {
194
196
if ( file . endsWith ( '/' ) ) {
195
197
// if it's a directory, check that we don't already have a workspace with a config inside
@@ -204,7 +206,7 @@ export class Vitest {
204
206
if ( filepath . endsWith ( '/' ) ) {
205
207
const filesInside = await fs . readdir ( filepath )
206
208
const configFile = configFiles . find ( config => filesInside . includes ( config ) )
207
- return configFile || filepath
209
+ return configFile ? join ( filepath , configFile ) : filepath
208
210
}
209
211
return filepath
210
212
} ) )
@@ -233,11 +235,11 @@ export class Vitest {
233
235
this . server . config . configFile === workspacePath
234
236
)
235
237
return this . createCoreWorkspace ( options )
236
- return initializeProject ( workspacePath , this , { test : cliOverrides } )
238
+ return initializeProject ( workspacePath , this , { workspaceConfigPath , test : cliOverrides } )
237
239
} )
238
240
239
241
projectsOptions . forEach ( ( options , index ) => {
240
- projects . push ( initializeProject ( index , this , mergeConfig ( options , { test : cliOverrides } ) ) )
242
+ projects . push ( initializeProject ( index , this , mergeConfig ( options , { workspaceConfigPath , test : cliOverrides } ) as any ) )
241
243
} )
242
244
243
245
if ( ! projects . length )
0 commit comments