@@ -32,18 +32,11 @@ export function WorkspaceVitestPlugin(
32
32
) {
33
33
return < VitePlugin [ ] > [
34
34
{
35
- name : 'vitest:project' ,
35
+ name : 'vitest:project:name ' ,
36
36
enforce : 'post' ,
37
- options ( ) {
38
- this . meta . watchMode = false
39
- } ,
40
37
config ( viteConfig ) {
41
- const defines : Record < string , any > = deleteDefineConfig ( viteConfig )
42
-
43
38
const testConfig = viteConfig . test || { }
44
39
45
- const root = testConfig . root || viteConfig . root || options . root
46
-
47
40
let { label : name , color } = typeof testConfig . name === 'string'
48
41
? { label : testConfig . name }
49
42
: { label : '' , ...testConfig . name }
@@ -67,6 +60,56 @@ export function WorkspaceVitestPlugin(
67
60
}
68
61
}
69
62
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
+
70
113
const resolveOptions = getDefaultResolveOptions ( )
71
114
const config : ViteConfig = {
72
115
root,
@@ -110,44 +153,11 @@ export function WorkspaceVitestPlugin(
110
153
resolve : resolveOptions ,
111
154
} ,
112
155
} ,
113
- test : {
114
- name : { label : name , color } ,
115
- } ,
156
+ test : { } ,
116
157
}
117
158
118
159
; ( config . test as ResolvedConfig ) . defines = defines
119
160
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
-
151
161
const classNameStrategy
152
162
= ( typeof testConfig . css !== 'boolean'
153
163
&& testConfig . css ?. modules ?. classNameStrategy )
@@ -181,6 +191,10 @@ export function WorkspaceVitestPlugin(
181
191
182
192
return config
183
193
} ,
194
+ } ,
195
+ {
196
+ name : 'vitest:project:server' ,
197
+ enforce : 'post' ,
184
198
async configureServer ( server ) {
185
199
const options = deepMerge ( { } , configDefaults , server . config . test || { } )
186
200
await project . _configureServer ( options , server )
0 commit comments