@@ -105,18 +105,17 @@ export class WorkerMain extends ProcessRunner {
105105 }
106106
107107 override async gracefullyClose ( ) {
108- if ( this . _isMissingProject ) {
109- // Never set anything up and we can crash on attempting cleanup
110- return ;
111- }
112-
113108 try {
114109 await this . _stop ( ) ;
110+ if ( this . _isMissingProject ) {
111+ // We never set anything up and we can crash on attempting cleanup
112+ return ;
113+ }
115114 // Ignore top-level errors, they are already inside TestInfo.errors.
116115 const fakeTestInfo = new TestInfoImpl ( this . _config , this . _project , this . _params , undefined , 0 , ( ) => { } , ( ) => { } , ( ) => { } ) ;
117116 const runnable = { type : 'teardown' } as const ;
118117 // We have to load the project to get the right deadline below.
119- await fakeTestInfo . _runAsStage ( { title : 'worker cleanup' , runnable } , ( ) => this . _load ( ) ) . catch ( ( ) => { } ) ;
118+ await fakeTestInfo . _runAsStage ( { title : 'worker cleanup' , runnable } , ( ) => this . _loadIfNeeded ( ) ) . catch ( ( ) => { } ) ;
120119 await this . _fixtureRunner . teardownScope ( 'test' , fakeTestInfo , runnable ) . catch ( ( ) => { } ) ;
121120 await this . _fixtureRunner . teardownScope ( 'worker' , fakeTestInfo , runnable ) . catch ( ( ) => { } ) ;
122121 // Close any other browsers launched in this process. This includes anything launched
@@ -193,43 +192,33 @@ export class WorkerMain extends ProcessRunner {
193192 void this . _stop ( ) ;
194193 }
195194
196- private async _load ( ) : Promise < {
197- config : FullConfigInternal ,
198- project : FullProjectInternal ,
199- poolBuilder : PoolBuilder ,
200- } | undefined > {
195+ private async _loadIfNeeded ( ) {
201196 if ( this . _config )
202- return { config : this . _config , project : this . _project , poolBuilder : this . _poolBuilder } ;
197+ return ;
203198
204199 this . _config = await deserializeConfig ( this . _params . config ) ;
205200 const project = this . _config . projects . find ( p => p . id === this . _params . projectId ) ;
206- if ( ! project )
207- return undefined ;
201+ if ( ! project ) {
202+ this . _isMissingProject = true ;
203+ throw new Error ( `Project with name "${ this . _params . projectId } " not found. Make sure project name does not change` ) ;
204+ }
208205 this . _project = project ;
209206 this . _poolBuilder = PoolBuilder . createForWorker ( this . _project ) ;
210-
211- return { config : this . _config , project : this . _project , poolBuilder : this . _poolBuilder } ;
212207 }
213208
214209 async runTestGroup ( runPayload : RunPayload ) {
215210 this . _runFinished = new ManualPromise < void > ( ) ;
216211 const entries = new Map ( runPayload . entries . map ( e => [ e . testId , e ] ) ) ;
217212 let fatalUnknownTestIds : string [ ] | undefined ;
218213 try {
219- const workerState = await this . _load ( ) ;
220- if ( ! workerState ) {
221- this . _isMissingProject = true ;
222- void this . _stop ( ) ;
223- return ;
224- }
225- const { config, project, poolBuilder } = workerState ;
226- const fileSuite = await loadTestFile ( runPayload . file , config . config . rootDir ) ;
227- const suite = bindFileSuiteToProject ( project , fileSuite ) ;
214+ await this . _loadIfNeeded ( ) ;
215+ const fileSuite = await loadTestFile ( runPayload . file , this . _config . config . rootDir ) ;
216+ const suite = bindFileSuiteToProject ( this . _project , fileSuite ) ;
228217 if ( this . _params . repeatEachIndex )
229- applyRepeatEachIndex ( project , suite , this . _params . repeatEachIndex ) ;
218+ applyRepeatEachIndex ( this . _project , suite , this . _params . repeatEachIndex ) ;
230219 const hasEntries = filterTestsRemoveEmptySuites ( suite , test => entries . has ( test . id ) ) ;
231220 if ( hasEntries ) {
232- poolBuilder . buildPools ( suite ) ;
221+ this . _poolBuilder . buildPools ( suite ) ;
233222 this . _activeSuites = new Map ( ) ;
234223 this . _didRunFullCleanup = false ;
235224 const tests = suite . allTests ( ) ;
@@ -258,7 +247,6 @@ export class WorkerMain extends ProcessRunner {
258247 fatalErrors : this . _fatalErrors ,
259248 skipTestsDueToSetupFailure : [ ] ,
260249 fatalUnknownTestIds,
261- missingProjectById : this . _isMissingProject ? this . _params . projectId : undefined
262250 } ;
263251 for ( const test of this . _skipRemainingTestsInSuite ?. allTests ( ) || [ ] ) {
264252 if ( entries . has ( test . id ) )
0 commit comments