@@ -10,9 +10,8 @@ import type { BuilderOutput } from '@angular-devkit/architect';
1010import assert from 'node:assert' ;
1111import path from 'node:path' ;
1212import { isMatch } from 'picomatch' ;
13- import type { InlineConfig , Vitest } from 'vitest/node' ;
13+ import type { Vitest } from 'vitest/node' ;
1414import { assertIsError } from '../../../../utils/error' ;
15- import { toPosixPath } from '../../../../utils/path' ;
1615import {
1716 type FullResult ,
1817 type IncrementalResult ,
@@ -23,9 +22,7 @@ import { NormalizedUnitTestBuilderOptions } from '../../options';
2322import type { TestExecutor } from '../api' ;
2423import { setupBrowserConfiguration } from './browser-provider' ;
2524import { findVitestBaseConfig } from './configuration' ;
26- import { createVitestPlugins } from './plugins' ;
27-
28- type VitestCoverageOption = Exclude < InlineConfig [ 'coverage' ] , undefined > ;
25+ import { createVitestConfigPlugin , createVitestPlugins } from './plugins' ;
2926
3027export class VitestExecutor implements TestExecutor {
3128 private vitest : Vitest | undefined ;
@@ -89,7 +86,9 @@ export class VitestExecutor implements TestExecutor {
8986 if ( source ) {
9087 modifiedSourceFiles . add ( source ) ;
9188 }
92- vitest . invalidateFile ( toPosixPath ( path . join ( this . options . workspaceRoot , modifiedFile ) ) ) ;
89+ vitest . invalidateFile (
90+ this . normalizePath ( path . join ( this . options . workspaceRoot , modifiedFile ) ) ,
91+ ) ;
9392 }
9493
9594 const specsToRerun = [ ] ;
@@ -141,6 +140,7 @@ export class VitestExecutor implements TestExecutor {
141140 browserViewport,
142141 ui,
143142 } = this . options ;
143+ const projectName = this . projectName ;
144144
145145 let vitestNodeModule ;
146146 try {
@@ -173,12 +173,10 @@ export class VitestExecutor implements TestExecutor {
173173 ) ;
174174
175175 const testSetupFiles = this . prepareSetupFiles ( ) ;
176- const plugins = createVitestPlugins ( {
176+ const projectPlugins = createVitestPlugins ( {
177177 workspaceRoot,
178178 projectSourceRoot : this . options . projectSourceRoot ,
179- projectName : this . projectName ,
180- include : this . options . include ,
181- exclude : this . options . exclude ,
179+ projectName,
182180 buildResultFiles : this . buildResultFiles ,
183181 testFileToEntryPoint : this . testFileToEntryPoint ,
184182 } ) ;
@@ -196,7 +194,6 @@ export class VitestExecutor implements TestExecutor {
196194 runnerConfig === true
197195 ? await findVitestBaseConfig ( [ this . options . projectRoot , this . options . workspaceRoot ] )
198196 : runnerConfig ;
199- const projectName = this . projectName ;
200197
201198 return startVitest (
202199 'test' ,
@@ -212,71 +209,23 @@ export class VitestExecutor implements TestExecutor {
212209 ...debugOptions ,
213210 } ,
214211 {
215- test : {
216- coverage : await generateCoverageOption ( coverage , this . projectName ) ,
217- ...( reporters ? { reporters } : { } ) ,
218- projects : [
219- {
220- extends : externalConfigPath || true ,
221- test : {
222- name : projectName ,
223- globals : true ,
224- setupFiles : testSetupFiles ,
225- ...( this . options . exclude ? { exclude : this . options . exclude } : { } ) ,
226- browser : browserOptions . browser ,
227- // Use `jsdom` if no browsers are explicitly configured.
228- ...( browserOptions . browser ? { } : { environment : 'jsdom' } ) ,
229- ...( this . options . include ? { include : this . options . include } : { } ) ,
230- } ,
231- optimizeDeps : {
232- noDiscovery : true ,
233- } ,
234- plugins,
235- } ,
236- ] ,
237- } ,
238212 server : {
239213 // Disable the actual file watcher. The boolean watch option above should still
240214 // be enabled as it controls other internal behavior related to rerunning tests.
241215 watch : null ,
242216 } ,
217+ plugins : [
218+ createVitestConfigPlugin ( {
219+ browser : browserOptions . browser ,
220+ coverage,
221+ projectName,
222+ reporters,
223+ setupFiles : testSetupFiles ,
224+ projectPlugins,
225+ include : [ ...this . testFileToEntryPoint . keys ( ) ] ,
226+ } ) ,
227+ ] ,
243228 } ,
244229 ) ;
245230 }
246231}
247-
248- async function generateCoverageOption (
249- coverage : NormalizedUnitTestBuilderOptions [ 'coverage' ] ,
250- projectName : string ,
251- ) : Promise < VitestCoverageOption > {
252- let defaultExcludes : string [ ] = [ ] ;
253- if ( coverage . exclude ) {
254- try {
255- const vitestConfig = await import ( 'vitest/config' ) ;
256- defaultExcludes = vitestConfig . coverageConfigDefaults . exclude ;
257- } catch { }
258- }
259-
260- return {
261- enabled : coverage . enabled ,
262- excludeAfterRemap : true ,
263- include : coverage . include ,
264- reportsDirectory : toPosixPath ( path . join ( 'coverage' , projectName ) ) ,
265- thresholds : coverage . thresholds ,
266- watermarks : coverage . watermarks ,
267- // Special handling for `exclude`/`reporters` due to an undefined value causing upstream failures
268- ...( coverage . exclude
269- ? {
270- exclude : [
271- // Augment the default exclude https://vitest.dev/config/#coverage-exclude
272- // with the user defined exclusions
273- ...coverage . exclude ,
274- ...defaultExcludes ,
275- ] ,
276- }
277- : { } ) ,
278- ...( coverage . reporters
279- ? ( { reporter : coverage . reporters } satisfies VitestCoverageOption )
280- : { } ) ,
281- } ;
282- }
0 commit comments