@@ -11,7 +11,7 @@ import { version as viteVersion } from 'vite'
1111import { rootDir } from '../paths'
1212import { isWindows } from '../utils/env'
1313import { getWorkerMemoryLimit , stringToBytes } from '../utils/memory-limit'
14- import { groupFilesByEnv } from '../utils/test-helpers'
14+ import { getSpecificationsEnvironments } from '../utils/test-helpers'
1515import { createBrowserPool } from './pools/browser'
1616import { Pool } from './pools/pool'
1717
@@ -86,6 +86,7 @@ export function createPool(ctx: Vitest): ProcessPool {
8686 let workerId = 0
8787
8888 const sorted = await sequencer . sort ( specs )
89+ const environments = await getSpecificationsEnvironments ( specs )
8990 const groups = groupSpecs ( sorted )
9091
9192 for ( const group of groups ) {
@@ -108,16 +109,18 @@ export function createPool(ctx: Vitest): ProcessPool {
108109 continue
109110 }
110111
111- const byEnv = await groupFilesByEnv ( specs )
112- const env = Object . values ( byEnv ) [ 0 ] [ 0 ]
112+ const environment = environments . get ( specs [ 0 ] ) !
113+ if ( ! environment ) {
114+ throw new Error ( `Cannot find the environment. This is a bug in Vitest.` )
115+ }
113116
114117 taskGroup . push ( {
115118 context : {
116119 pool,
117120 config : project . serializedConfig ,
118121 files : specs . map ( spec => ( { filepath : spec . moduleId , testLocations : spec . testLines } ) ) ,
119122 invalidates,
120- environment : env . environment ,
123+ environment,
121124 projectName : project . name ,
122125 providedContext : project . getProvidedContext ( ) ,
123126 workerId : workerId ++ ,
@@ -313,7 +316,7 @@ function groupSpecs(specs: TestSpecification[]) {
313316
314317 // Tests in a single group are executed with `maxWorkers` parallelism.
315318 // Next group starts running after previous finishes - allows real sequential tests.
316- interface Groups { specs : SpecsForRunner [ ] ; maxWorkers : number }
319+ interface Groups { specs : SpecsForRunner [ ] ; maxWorkers : number ; typecheck ?: boolean }
317320 const groups : Groups [ ] = [ ]
318321
319322 // Files without file parallelism but without explicit sequence.groupOrder
@@ -349,11 +352,17 @@ function groupSpecs(specs: TestSpecification[]) {
349352 groups [ order ] . specs . push ( [ spec ] )
350353 } )
351354
352- for ( const project in typechecks ) {
353- const order = Math . max ( 0 , ...groups . keys ( ) ) + 1
355+ let order = Math . max ( 0 , ...groups . keys ( ) ) + 1
356+
357+ for ( const projectName in typechecks ) {
358+ const maxWorkers = resolveMaxWorkers ( typechecks [ projectName ] [ 0 ] . project )
359+ const previous = groups [ order - 1 ]
360+ if ( previous && previous . typecheck && maxWorkers !== previous . maxWorkers ) {
361+ order += 1
362+ }
354363
355- groups [ order ] ||= { specs : [ ] , maxWorkers : resolveMaxWorkers ( typechecks [ project ] [ 0 ] . project ) }
356- groups [ order ] . specs . push ( typechecks [ project ] )
364+ groups [ order ] ||= { specs : [ ] , maxWorkers, typecheck : true }
365+ groups [ order ] . specs . push ( typechecks [ projectName ] )
357366 }
358367
359368 if ( sequential . specs . length ) {
0 commit comments