mirror of
				https://github.com/microsoft/playwright.git
				synced 2025-06-26 21:40:17 +00:00 
			
		
		
		
	chore: follow up to runnable change (#27300)
This commit is contained in:
		
							parent
							
								
									c0dc2328aa
								
							
						
					
					
						commit
						07e794eb83
					
				| @ -21,7 +21,7 @@ import type { TestInfoError, TestInfo, TestStatus, FullProject, FullConfig } fro | |||||||
| import type { AttachmentPayload, StepBeginPayload, StepEndPayload, WorkerInitParams } from '../common/ipc'; | import type { AttachmentPayload, StepBeginPayload, StepEndPayload, WorkerInitParams } from '../common/ipc'; | ||||||
| import type { TestCase } from '../common/test'; | import type { TestCase } from '../common/test'; | ||||||
| import { TimeoutManager } from './timeoutManager'; | import { TimeoutManager } from './timeoutManager'; | ||||||
| import type { RunnableType, TimeSlot, RunnableDescription } from './timeoutManager'; | import type { RunnableType, TimeSlot } from './timeoutManager'; | ||||||
| import type { Annotation, FullConfigInternal, FullProjectInternal } from '../common/config'; | import type { Annotation, FullConfigInternal, FullProjectInternal } from '../common/config'; | ||||||
| import type { Location } from '../../types/testReporter'; | import type { Location } from '../../types/testReporter'; | ||||||
| import { getContainedPath, normalizeAndSaveAttachment, serializeError, trimLongString } from '../util'; | import { getContainedPath, normalizeAndSaveAttachment, serializeError, trimLongString } from '../util'; | ||||||
| @ -228,12 +228,6 @@ export class TestInfoImpl implements TestInfo { | |||||||
|     this.duration = this._timeoutManager.defaultSlotTimings().elapsed | 0; |     this.duration = this._timeoutManager.defaultSlotTimings().elapsed | 0; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async _runWithRunnableAndFailOnError(runnable: RunnableDescription, cb: () => Promise<void>): Promise<TestInfoError | undefined> { |  | ||||||
|     return await this._timeoutManager.withRunnable(runnable, async () => { |  | ||||||
|       return await this._runAndFailOnError(cb); |  | ||||||
|     }); |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   async _runAndFailOnError(fn: () => Promise<void>, skips?: 'allowSkips'): Promise<TestInfoError | undefined> { |   async _runAndFailOnError(fn: () => Promise<void>, skips?: 'allowSkips'): Promise<TestInfoError | undefined> { | ||||||
|     try { |     try { | ||||||
|       await fn(); |       await fn(); | ||||||
|  | |||||||
| @ -24,7 +24,7 @@ export type TimeSlot = { | |||||||
|   elapsed: number; |   elapsed: number; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| export type RunnableType = 'test' | 'beforeAll' | 'afterAll' | 'beforeEach' | 'afterEach' | 'slow' | 'skip' | 'fail' | 'fixme' | 'teardown'; | export type RunnableType = 'test' | 'beforeAll' | 'afterAll' | 'beforeEach' | 'afterEach' | 'afterHooks' | 'slow' | 'skip' | 'fail' | 'fixme' | 'teardown'; | ||||||
| 
 | 
 | ||||||
| export type RunnableDescription = { | export type RunnableDescription = { | ||||||
|   type: RunnableType; |   type: RunnableType; | ||||||
| @ -59,7 +59,9 @@ export class TimeoutManager { | |||||||
| 
 | 
 | ||||||
|   async withRunnable<R>(runnable: RunnableDescription, cb: () => Promise<R>): Promise<R> { |   async withRunnable<R>(runnable: RunnableDescription, cb: () => Promise<R>): Promise<R> { | ||||||
|     const existingRunnable = this._runnable; |     const existingRunnable = this._runnable; | ||||||
|     const effectiveRunnable = { ...this._runnable, ...runnable }; |     const effectiveRunnable = { ...runnable }; | ||||||
|  |     if (!effectiveRunnable.slot) | ||||||
|  |       effectiveRunnable.slot = this._runnable.slot; | ||||||
|     this._updateRunnables(effectiveRunnable, undefined); |     this._updateRunnables(effectiveRunnable, undefined); | ||||||
|     try { |     try { | ||||||
|       return await cb(); |       return await cb(); | ||||||
| @ -129,6 +131,7 @@ export class TimeoutManager { | |||||||
|     let message = ''; |     let message = ''; | ||||||
|     const timeout = this._currentSlot().timeout; |     const timeout = this._currentSlot().timeout; | ||||||
|     switch (this._runnable.type) { |     switch (this._runnable.type) { | ||||||
|  |       case 'afterHooks': | ||||||
|       case 'test': { |       case 'test': { | ||||||
|         if (this._fixture) { |         if (this._fixture) { | ||||||
|           if (this._fixture.phase === 'setup') { |           if (this._fixture.phase === 'setup') { | ||||||
|  | |||||||
| @ -411,7 +411,7 @@ export class WorkerMain extends ProcessRunner { | |||||||
| 
 | 
 | ||||||
|     // A timed-out test gets a full additional timeout to run after hooks.
 |     // A timed-out test gets a full additional timeout to run after hooks.
 | ||||||
|     const afterHooksSlot = testInfo._didTimeout ? { timeout: this._project.project.timeout, elapsed: 0 } : undefined; |     const afterHooksSlot = testInfo._didTimeout ? { timeout: this._project.project.timeout, elapsed: 0 } : undefined; | ||||||
|     await testInfo._runAsStepWithRunnable({ category: 'hook', title: 'After Hooks', runnableType: 'afterEach', runnableSlot: afterHooksSlot }, async step => { |     await testInfo._runAsStepWithRunnable({ category: 'hook', title: 'After Hooks', runnableType: 'afterHooks', runnableSlot: afterHooksSlot }, async step => { | ||||||
|       testInfo._afterHooksStep = step; |       testInfo._afterHooksStep = step; | ||||||
|       let firstAfterHooksError: TestInfoError | undefined; |       let firstAfterHooksError: TestInfoError | undefined; | ||||||
|       await testInfo._runWithTimeout(async () => { |       await testInfo._runWithTimeout(async () => { | ||||||
| @ -433,7 +433,7 @@ export class WorkerMain extends ProcessRunner { | |||||||
|         // Teardown test-scoped fixtures. Attribute to 'test' so that users understand
 |         // Teardown test-scoped fixtures. Attribute to 'test' so that users understand
 | ||||||
|         // they should probably increase the test timeout to fix this issue.
 |         // they should probably increase the test timeout to fix this issue.
 | ||||||
|         debugTest(`tearing down test scope started`); |         debugTest(`tearing down test scope started`); | ||||||
|         const testScopeError = await testInfo._runWithRunnableAndFailOnError({ type: 'test' }, () => { |         const testScopeError = await testInfo._runAndFailOnError(() => { | ||||||
|           return this._fixtureRunner.teardownScope('test', testInfo._timeoutManager); |           return this._fixtureRunner.teardownScope('test', testInfo._timeoutManager); | ||||||
|         }); |         }); | ||||||
|         debugTest(`tearing down test scope finished`); |         debugTest(`tearing down test scope finished`); | ||||||
| @ -463,10 +463,10 @@ export class WorkerMain extends ProcessRunner { | |||||||
|           debugTest(`running full cleanup after the failure`); |           debugTest(`running full cleanup after the failure`); | ||||||
| 
 | 
 | ||||||
|           const teardownSlot = { timeout: this._project.project.timeout, elapsed: 0 }; |           const teardownSlot = { timeout: this._project.project.timeout, elapsed: 0 }; | ||||||
|           await testInfo._timeoutManager.withRunnable({ type: 'test', slot: teardownSlot }, async () => { |           await testInfo._timeoutManager.withRunnable({ type: 'teardown', slot: teardownSlot }, async () => { | ||||||
|             // Attribute to 'test' so that users understand they should probably increate the test timeout to fix this issue.
 |             // Attribute to 'test' so that users understand they should probably increate the test timeout to fix this issue.
 | ||||||
|             debugTest(`tearing down test scope started`); |             debugTest(`tearing down test scope started`); | ||||||
|             const testScopeError = await testInfo._runWithRunnableAndFailOnError({ type: 'test' }, () => { |             const testScopeError = await testInfo._runAndFailOnError(() => { | ||||||
|               return this._fixtureRunner.teardownScope('test', testInfo._timeoutManager); |               return this._fixtureRunner.teardownScope('test', testInfo._timeoutManager); | ||||||
|             }); |             }); | ||||||
|             debugTest(`tearing down test scope finished`); |             debugTest(`tearing down test scope finished`); | ||||||
| @ -479,7 +479,7 @@ export class WorkerMain extends ProcessRunner { | |||||||
| 
 | 
 | ||||||
|             // Attribute to 'teardown' because worker fixtures are not perceived as a part of a test.
 |             // Attribute to 'teardown' because worker fixtures are not perceived as a part of a test.
 | ||||||
|             debugTest(`tearing down worker scope started`); |             debugTest(`tearing down worker scope started`); | ||||||
|             const workerScopeError = await testInfo._runWithRunnableAndFailOnError({ type: 'teardown' }, () => { |             const workerScopeError = await testInfo._runAndFailOnError(() => { | ||||||
|               return this._fixtureRunner.teardownScope('worker', testInfo._timeoutManager); |               return this._fixtureRunner.teardownScope('worker', testInfo._timeoutManager); | ||||||
|             }); |             }); | ||||||
|             debugTest(`tearing down worker scope finished`); |             debugTest(`tearing down worker scope finished`); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Pavel Feldman
						Pavel Feldman