chore: remove TestInfoImpl._stages (#32285)

This is a preparation to a bigger stages cleanup.
This commit is contained in:
Dmitry Gozman 2024-08-23 06:16:18 -07:00 committed by GitHub
parent 3fb33e7144
commit 9a5b72d02a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 16 deletions

View file

@ -69,7 +69,6 @@ export class TestInfoImpl implements TestInfo {
readonly _configInternal: FullConfigInternal; readonly _configInternal: FullConfigInternal;
private readonly _steps: TestStepInternal[] = []; private readonly _steps: TestStepInternal[] = [];
_onDidFinishTestFunction: (() => Promise<void>) | undefined; _onDidFinishTestFunction: (() => Promise<void>) | undefined;
private readonly _stages: TestStage[] = [];
_hasNonRetriableError = false; _hasNonRetriableError = false;
_hasUnhandledError = false; _hasUnhandledError = false;
_allowSkips = false; _allowSkips = false;
@ -227,10 +226,14 @@ export class TestInfoImpl implements TestInfo {
} }
} }
private _findLastStageStep() { private _findLastStageStep(steps: TestStepInternal[]): TestStepInternal | undefined {
for (let i = this._stages.length - 1; i >= 0; i--) { // Find the deepest step that is marked as isStage and has not finished yet.
if (this._stages[i].step) for (let i = steps.length - 1; i >= 0; i--) {
return this._stages[i].step; const child = this._findLastStageStep(steps[i].steps);
if (child)
return child;
if (steps[i].isStage && !steps[i].endWallTime)
return steps[i];
} }
} }
@ -240,12 +243,12 @@ export class TestInfoImpl implements TestInfo {
let parentStep: TestStepInternal | undefined; let parentStep: TestStepInternal | undefined;
if (data.isStage) { if (data.isStage) {
// Predefined stages form a fixed hierarchy - use the current one as parent. // Predefined stages form a fixed hierarchy - use the current one as parent.
parentStep = this._findLastStageStep(); parentStep = this._findLastStageStep(this._steps);
} else { } else {
parentStep = zones.zoneData<TestStepInternal>('stepZone'); parentStep = zones.zoneData<TestStepInternal>('stepZone');
if (!parentStep) { if (!parentStep) {
// If no parent step on stack, assume the current stage as parent. // If no parent step on stack, assume the current stage as parent.
parentStep = this._findLastStageStep(); parentStep = this._findLastStageStep(this._steps);
} }
} }
@ -341,7 +344,6 @@ export class TestInfoImpl implements TestInfo {
debugTest(`started stage "${stage.title}"${location}`); debugTest(`started stage "${stage.title}"${location}`);
} }
stage.step = stage.stepInfo ? this._addStep({ ...stage.stepInfo, title: stage.title, isStage: true }) : undefined; stage.step = stage.stepInfo ? this._addStep({ ...stage.stepInfo, title: stage.title, isStage: true }) : undefined;
this._stages.push(stage);
try { try {
await this._timeoutManager.withRunnable(stage.runnable, async () => { await this._timeoutManager.withRunnable(stage.runnable, async () => {
@ -376,9 +378,6 @@ export class TestInfoImpl implements TestInfo {
stage.step?.complete({ error }); stage.step?.complete({ error });
throw error; throw error;
} finally { } finally {
if (this._stages[this._stages.length - 1] !== stage)
throw new Error(`Internal error: inconsistent stages!`);
this._stages.pop();
debugTest(`finished stage "${stage.title}"`); debugTest(`finished stage "${stage.title}"`);
} }
} }
@ -388,11 +387,8 @@ export class TestInfoImpl implements TestInfo {
} }
_currentHookType() { _currentHookType() {
for (let i = this._stages.length - 1; i >= 0; i--) { const type = this._timeoutManager.currentSlotType();
const type = this._stages[i].runnable?.type; return ['beforeAll', 'afterAll', 'beforeEach', 'afterEach'].includes(type) ? type : undefined;
if (type && ['beforeAll', 'afterAll', 'beforeEach', 'afterEach'].includes(type))
return type;
}
} }
_setDebugMode() { _setDebugMode() {

View file

@ -142,6 +142,10 @@ export class TimeoutManager {
return this._running ? this._running.deadline : kMaxDeadline; return this._running ? this._running.deadline : kMaxDeadline;
} }
currentSlotType() {
return this._running ? this._running.runnable.type : 'test';
}
private _createTimeoutError(running: Running): Error { private _createTimeoutError(running: Running): Error {
let message = ''; let message = '';
const timeout = running.slot.timeout; const timeout = running.slot.timeout;