1- /* eslint-disable max-lines */
2-
31import { LogEventStatus , LogEventType } from './constants/internal' ;
4- import { getStepsStack } from './context/stepsStack' ;
52import { getTestIdleTimeout } from './context/testIdleTimeout' ;
63import { E2edError } from './utils/error' ;
74import { setCustomInspectOnFunction } from './utils/fn' ;
@@ -10,15 +7,9 @@ import {getDurationWithUnits} from './utils/getDurationWithUnits';
107import { logAndGetLogEvent } from './utils/log' ;
118import { setReadonlyProperty } from './utils/object' ;
129import { addTimeoutToPromise } from './utils/promise' ;
10+ import { stepsStackStorage } from './utils/step' ;
1311
14- import type {
15- LogEvent ,
16- LogPayload ,
17- MaybePromise ,
18- Mutable ,
19- UtcTimeInMs ,
20- Void ,
21- } from './types/internal' ;
12+ import type { LogEvent , LogPayload , MaybePromise , UtcTimeInMs , Void } from './types/internal' ;
2213
2314import { test as playwrightTest } from '@playwright/test' ;
2415
@@ -33,7 +24,7 @@ type Options = Readonly<{
3324/**
3425 * Declares a test step (could calls Playwright's `test.step` function inside).
3526 */
36- // eslint-disable-next-line complexity, max-statements, max-lines-per-function
27+ // eslint-disable-next-line complexity, max-statements
3728export const step = async (
3829 name : string ,
3930 body ?: ( ) => MaybePromise < LogPayload | Void > ,
@@ -44,7 +35,6 @@ export const step = async (
4435 }
4536
4637 let logEvent : LogEvent | undefined ;
47- const stepsStack = getStepsStack ( ) ;
4838 const timeout : number = options ?. timeout ?? getTestIdleTimeout ( ) ;
4939
5040 if ( options ?. skipLogs !== true ) {
@@ -55,10 +45,6 @@ export const step = async (
5545 ) ;
5646 }
5747
58- if ( logEvent !== undefined ) {
59- ( stepsStack as Mutable < typeof stepsStack > ) . push ( logEvent ) ;
60- }
61-
6248 const errorProperties = { stepBody : body , stepName : name , stepOptions : options } ;
6349 let payload = undefined as LogPayload | Void ;
6450 let stepError : unknown ;
@@ -70,7 +56,11 @@ export const step = async (
7056 ) ;
7157
7258 const runBody = async ( ) : Promise < void > => {
73- payload = await body ?.( ) ;
59+ if ( logEvent !== undefined && typeof body === 'function' ) {
60+ await stepsStackStorage . run ( logEvent , body ) ;
61+ } else {
62+ payload = await body ?.( ) ;
63+ }
7464 } ;
7565
7666 let bodyError : unknown ;
@@ -139,20 +129,6 @@ export const step = async (
139129 setReadonlyProperty ( logEvent , 'payload' , { ...logEvent . payload , ...payload } ) ;
140130 }
141131
142- const logEventIndex = stepsStack . findIndex ( ( event ) => event === logEvent ) ;
143-
144- if ( logEventIndex === - 1 ) {
145- // eslint-disable-next-line no-unsafe-finally
146- throw new E2edError ( 'Cannot find running step in test steps stack' , {
147- runningStep : logEvent ,
148- stepBody : body ,
149- stepError,
150- stepOptions : options ,
151- } ) ;
152- }
153-
154- ( stepsStack as Mutable < typeof stepsStack > ) . splice ( logEventIndex , 1 ) ;
155-
156132 generalLog ( `Step "${ name } " completed` , {
157133 body,
158134 step : { ...logEvent , children : logEvent . children ?. map ( ( { message} ) => message ) } ,
0 commit comments