@@ -32,18 +32,11 @@ export function WorkspaceVitestPlugin(
3232) {
3333 return < VitePlugin [ ] > [
3434 {
35- name : 'vitest:project' ,
35+ name : 'vitest:project:name ' ,
3636 enforce : 'post' ,
37- options ( ) {
38- this . meta . watchMode = false
39- } ,
4037 config ( viteConfig ) {
41- const defines : Record < string , any > = deleteDefineConfig ( viteConfig )
42-
4338 const testConfig = viteConfig . test || { }
4439
45- const root = testConfig . root || viteConfig . root || options . root
46-
4740 let { label : name , color } = typeof testConfig . name === 'string'
4841 ? { label : testConfig . name }
4942 : { label : '' , ...testConfig . name }
@@ -67,6 +60,56 @@ export function WorkspaceVitestPlugin(
6760 }
6861 }
6962
63+ const isUserBrowserEnabled = viteConfig . test ?. browser ?. enabled
64+ const isBrowserEnabled = isUserBrowserEnabled ?? ( viteConfig . test ?. browser && project . vitest . _cliOptions . browser ?. enabled )
65+ // keep project names to potentially filter it out
66+ const workspaceNames = [ name ]
67+ const browser = viteConfig . test ! . browser || { }
68+ if ( isBrowserEnabled && browser . name && ! browser . instances ?. length ) {
69+ // vitest injects `instances` in this case later on
70+ workspaceNames . push ( name ? `${ name } (${ browser . name } )` : browser . name )
71+ }
72+
73+ viteConfig . test ?. browser ?. instances ?. forEach ( ( instance ) => {
74+ // every instance is a potential project
75+ instance . name ??= name ? `${ name } (${ instance . browser } )` : instance . browser
76+ if ( isBrowserEnabled ) {
77+ workspaceNames . push ( instance . name )
78+ }
79+ } )
80+
81+ const filters = project . vitest . config . project
82+ // if there is `--project=...` filter, check if any of the potential projects match
83+ // if projects don't match, we ignore the test project altogether
84+ // if some of them match, they will later be filtered again by `resolveWorkspace`
85+ if ( filters . length ) {
86+ const hasProject = workspaceNames . some ( ( name ) => {
87+ return project . vitest . matchesProjectFilter ( name )
88+ } )
89+ if ( ! hasProject ) {
90+ throw new VitestFilteredOutProjectError ( )
91+ }
92+ }
93+
94+ return {
95+ test : {
96+ name : { label : name , color } ,
97+ } ,
98+ }
99+ } ,
100+ } ,
101+ {
102+ name : 'vitest:project' ,
103+ enforce : 'pre' ,
104+ options ( ) {
105+ this . meta . watchMode = false
106+ } ,
107+ config ( viteConfig ) {
108+ const defines : Record < string , any > = deleteDefineConfig ( viteConfig )
109+
110+ const testConfig = viteConfig . test || { }
111+ const root = testConfig . root || viteConfig . root || options . root
112+
70113 const resolveOptions = getDefaultResolveOptions ( )
71114 const config : ViteConfig = {
72115 root,
@@ -110,44 +153,11 @@ export function WorkspaceVitestPlugin(
110153 resolve : resolveOptions ,
111154 } ,
112155 } ,
113- test : {
114- name : { label : name , color } ,
115- } ,
156+ test : { } ,
116157 }
117158
118159 ; ( config . test as ResolvedConfig ) . defines = defines
119160
120- const isUserBrowserEnabled = viteConfig . test ?. browser ?. enabled
121- const isBrowserEnabled = isUserBrowserEnabled ?? ( viteConfig . test ?. browser && project . vitest . _cliOptions . browser ?. enabled )
122- // keep project names to potentially filter it out
123- const workspaceNames = [ name ]
124- const browser = viteConfig . test ! . browser || { }
125- if ( isBrowserEnabled && browser . name && ! browser . instances ?. length ) {
126- // vitest injects `instances` in this case later on
127- workspaceNames . push ( name ? `${ name } (${ browser . name } )` : browser . name )
128- }
129-
130- viteConfig . test ?. browser ?. instances ?. forEach ( ( instance ) => {
131- // every instance is a potential project
132- instance . name ??= name ? `${ name } (${ instance . browser } )` : instance . browser
133- if ( isBrowserEnabled ) {
134- workspaceNames . push ( instance . name )
135- }
136- } )
137-
138- const filters = project . vitest . config . project
139- // if there is `--project=...` filter, check if any of the potential projects match
140- // if projects don't match, we ignore the test project altogether
141- // if some of them match, they will later be filtered again by `resolveWorkspace`
142- if ( filters . length ) {
143- const hasProject = workspaceNames . some ( ( name ) => {
144- return project . vitest . matchesProjectFilter ( name )
145- } )
146- if ( ! hasProject ) {
147- throw new VitestFilteredOutProjectError ( )
148- }
149- }
150-
151161 const classNameStrategy
152162 = ( typeof testConfig . css !== 'boolean'
153163 && testConfig . css ?. modules ?. classNameStrategy )
@@ -181,6 +191,10 @@ export function WorkspaceVitestPlugin(
181191
182192 return config
183193 } ,
194+ } ,
195+ {
196+ name : 'vitest:project:server' ,
197+ enforce : 'post' ,
184198 async configureServer ( server ) {
185199 const options = deepMerge ( { } , configDefaults , server . config . test || { } )
186200 await project . _configureServer ( options , server )
0 commit comments