@@ -17,8 +17,8 @@ import { WebSocketReporter } from '../api/setup'
17
17
import type { SerializedCoverageConfig } from '../runtime/config'
18
18
import type { SerializedSpec } from '../runtime/types/utils'
19
19
import type { ArgumentsType , OnServerRestartHandler , ProvidedContext , UserConsoleLog } from '../types/general'
20
- import { createPool , getFilePoolName } from './pool'
21
- import type { ProcessPool , WorkspaceSpec } from './pool'
20
+ import type { ProcessPool } from './pool'
21
+ import { WorkspaceSpec , createPool , getFilePoolName } from './pool'
22
22
import { createBenchmarkReporters , createReporters } from './reporters/utils'
23
23
import { StateManager } from './state'
24
24
import { resolveConfig } from './config/resolveConfig'
@@ -437,7 +437,7 @@ export class Vitest {
437
437
}
438
438
}
439
439
440
- private async getTestDependencies ( [ project , filepath ] : WorkspaceSpec , deps = new Set < string > ( ) ) {
440
+ private async getTestDependencies ( spec : WorkspaceSpec , deps = new Set < string > ( ) ) {
441
441
const addImports = async ( project : WorkspaceProject , filepath : string ) => {
442
442
if ( deps . has ( filepath ) ) {
443
443
return
@@ -459,8 +459,8 @@ export class Vitest {
459
459
} ) )
460
460
}
461
461
462
- await addImports ( project , filepath )
463
- deps . delete ( filepath )
462
+ await addImports ( spec . project . workspaceProject , spec . moduleId )
463
+ deps . delete ( spec . moduleId )
464
464
465
465
return deps
466
466
}
@@ -531,18 +531,18 @@ export class Vitest {
531
531
for ( const project of this . projects ) {
532
532
if ( project . isTestFile ( file ) ) {
533
533
const pool = getFilePoolName ( project , file )
534
- specs . push ( [ project , file , { pool } ] )
534
+ specs . push ( new WorkspaceSpec ( project , file , pool ) )
535
535
}
536
536
if ( project . isTypecheckFile ( file ) ) {
537
- specs . push ( [ project , file , { pool : 'typescript' } ] )
537
+ specs . push ( new WorkspaceSpec ( project , file , 'typescript' ) )
538
538
}
539
539
}
540
540
specs . forEach ( spec => this . ensureSpecCached ( spec ) )
541
541
return specs
542
542
}
543
543
544
544
async initializeGlobalSetup ( paths : WorkspaceSpec [ ] ) {
545
- const projects = new Set ( paths . map ( ( [ project ] ) => project ) )
545
+ const projects = new Set ( paths . map ( spec => spec . project . workspaceProject ) )
546
546
const coreProject = this . getCoreWorkspaceProject ( )
547
547
if ( ! projects . has ( coreProject ) ) {
548
548
projects . add ( coreProject )
@@ -566,16 +566,16 @@ export class Vitest {
566
566
async runFiles ( specs : WorkspaceSpec [ ] , allTestsRun : boolean ) {
567
567
await this . initializeDistPath ( )
568
568
569
- const filepaths = specs . map ( ( [ , file ] ) => file )
569
+ const filepaths = specs . map ( spec => spec . moduleId )
570
570
this . state . collectPaths ( filepaths )
571
571
572
572
await this . report ( 'onPathsCollected' , filepaths )
573
573
await this . report ( 'onSpecsCollected' , specs . map (
574
- ( [ project , file , options ] ) =>
574
+ spec =>
575
575
[ {
576
- name : project . config . name ,
577
- root : project . config . root ,
578
- } , file , options ] satisfies SerializedSpec ,
576
+ name : spec . project . config . name ,
577
+ root : spec . project . config . root ,
578
+ } , spec . moduleId , { pool : spec . pool } ] satisfies SerializedSpec ,
579
579
) )
580
580
581
581
// previous run
@@ -618,7 +618,7 @@ export class Vitest {
618
618
} ) ( )
619
619
. finally ( async ( ) => {
620
620
// can be duplicate files if different projects are using the same file
621
- const files = Array . from ( new Set ( specs . map ( ( [ , p ] ) => p ) ) )
621
+ const files = Array . from ( new Set ( specs . map ( spec => spec . moduleId ) ) )
622
622
const coverage = await this . coverageProvider ?. generateCoverage ( { allTestsRun } )
623
623
624
624
await this . report ( 'onFinished' , this . state . getFiles ( files ) , this . state . getUnhandledErrors ( ) , coverage )
@@ -638,7 +638,7 @@ export class Vitest {
638
638
async collectFiles ( specs : WorkspaceSpec [ ] ) {
639
639
await this . initializeDistPath ( )
640
640
641
- const filepaths = specs . map ( ( [ , file ] ) => file )
641
+ const filepaths = specs . map ( spec => spec . moduleId )
642
642
this . state . collectPaths ( filepaths )
643
643
644
644
// previous run
@@ -709,7 +709,7 @@ export class Vitest {
709
709
else { this . configOverride . project = pattern }
710
710
711
711
this . projects = this . resolvedProjects . filter ( p => p . getName ( ) === pattern )
712
- const files = ( await this . globTestFiles ( ) ) . map ( ( [ , file ] ) => file )
712
+ const files = ( await this . globTestSpecs ( ) ) . map ( spec => spec . moduleId )
713
713
await this . rerunFiles ( files , 'change project filter' )
714
714
}
715
715
@@ -1083,28 +1083,35 @@ export class Vitest {
1083
1083
}
1084
1084
1085
1085
public async getTestFilepaths ( ) {
1086
- return this . globTestFiles ( ) . then ( files => files . map ( ( [ , file ] ) => file ) )
1086
+ return this . globTestSpecs ( ) . then ( specs => specs . map ( spec => spec . moduleId ) )
1087
1087
}
1088
1088
1089
- public async globTestFiles ( filters : string [ ] = [ ] ) {
1089
+ public async globTestSpecs ( filters : string [ ] = [ ] ) {
1090
1090
const files : WorkspaceSpec [ ] = [ ]
1091
1091
await Promise . all ( this . projects . map ( async ( project ) => {
1092
1092
const { testFiles, typecheckTestFiles } = await project . globTestFiles ( filters )
1093
1093
testFiles . forEach ( ( file ) => {
1094
1094
const pool = getFilePoolName ( project , file )
1095
- const spec : WorkspaceSpec = [ project , file , { pool } ]
1095
+ const spec = new WorkspaceSpec ( project , file , pool )
1096
1096
this . ensureSpecCached ( spec )
1097
1097
files . push ( spec )
1098
1098
} )
1099
1099
typecheckTestFiles . forEach ( ( file ) => {
1100
- const spec : WorkspaceSpec = [ project , file , { pool : 'typescript' } ]
1100
+ const spec = new WorkspaceSpec ( project , file , 'typescript' )
1101
1101
this . ensureSpecCached ( spec )
1102
1102
files . push ( spec )
1103
1103
} )
1104
1104
} ) )
1105
1105
return files
1106
1106
}
1107
1107
1108
+ /**
1109
+ * @deprecated use globTestSpecs instead
1110
+ */
1111
+ public async globTestFiles ( filters : string [ ] = [ ] ) {
1112
+ return this . globTestSpecs ( filters )
1113
+ }
1114
+
1108
1115
private ensureSpecCached ( spec : WorkspaceSpec ) {
1109
1116
const file = spec [ 1 ]
1110
1117
const specs = this . _cachedSpecs . get ( file ) || [ ]
0 commit comments