import { Test } from './testTypes' ; import { TestObserver } from './TestObserver' ; import { Step } from '../Step' ; import { TestEvent } from '@flood/element-report' ; import { StructuredError } from '../../utils/StructuredError' ; import { TimingObserver } from './TimingObserver' ; export default class LifecycleObserver implements TestObserver { constructor ( public next ) { } async before ( test ) { test . reporter . testLifecycle ( TestEvent . BeforeTest , 'test' ) ; return this . next . before ( test ) ; } async after ( test ) { await this . next . after ( test ) ; if ( test . failed ) { test . reporter . testLifecycle ( TestEvent . TestFailed , 'test' ) ; } else { test . reporter . testLifecycle ( TestEvent . TestSucceeded , 'test' ) ; } test . reporter . testLifecycle ( TestEvent . AfterTest , 'test' ) ; } async beforeStep ( test , step ) { test . reporter . testLifecycle ( TestEvent . BeforeStep , step . name , step . subTitle ) ; return this . next . beforeStep ( test , step ) ; } async onStepPassed ( test , step ) { const testObserver = this . next ; const timing = await ( testObserver as TimingObserver ) . getMeasurementTime ( test . settings . responseTimeMeasurement , true ) ; step . duration = timing ; await testObserver . onStepPassed ( test , step ) ; test . reporter . testLifecycle ( TestEvent . StepSucceeded , step . name , step . subTitle , timing ) ; } async onStepError ( test , step , error ) { const testObserver = this . next ; const timing = await ( testObserver as TimingObserver ) . getMeasurementTime ( test . settings . responseTimeMeasurement , true ) ; step . duration = timing ; await testObserver . onStepError ( test , step , error ) ; test . reporter . testLifecycle ( TestEvent . StepFailed , step . name , step . subTitle , timing , error ?. message ) ; } async onStepSkipped ( test , step ) { await this . next . onStepSkipped ( test , step ) ; test . reporter . testLifecycle ( TestEvent . StepSkipped , step . name ) ; } async onStepUnexecuted ( test , step ) { await this . next . onStepUnexecuted ( test , step ) ; test . reporter . testLifecycle ( TestEvent . StepUnexecuted , step . name ) ; } async afterStep ( test , step ) { const testObserver = this . next ; await testObserver . afterStep ( test , step ) ; const timing = await ( testObserver as TimingObserver ) . getMeasurementTime ( test . settings . responseTimeMeasurement ) ; test . reporter . testLifecycle ( TestEvent . AfterStep , step . name , step . subTitle , timing ) ; } async beforeStepAction ( test , step , command , args ? ) { await this . next . beforeStepAction ( test , step , command ) ; test . reporter . testLifecycle ( TestEvent . BeforeStepAction , command , '' , 0 , '' , args ) ; } async afterStepAction ( test , step , command , args ? ) { await this . next . afterStepAction ( test , step , command , args ) ; test . reporter . testLifecycle ( TestEvent . AfterStepAction , command , '' , 0 , '' , args ) ; } async beforeAllStep ( test ) { await this . next . beforeAllStep ( test ) ; test . reporter . testLifecycle ( TestEvent . BeforeAllStep , 'beforeAll' ) ; } async afterAllStep ( test ) { await this . next . afterAllStep ( test ) ; test . reporter . testLifecycle ( TestEvent . AfterAllStep , 'afterAll' ) ; } async beforeEachStep ( test ) { await this . next . beforeEachStep ( test ) ; test . reporter . testLifecycle ( TestEvent . BeforeEachStep , 'beforeEach' ) ; } async afterEachStep ( test ) { await this . next . afterEachStep ( test ) ; test . reporter . testLifecycle ( TestEvent . AfterEachStep , 'afterEach' ) ; } async onBeforeAllStepFinished ( test ) { await this . next . onBeforeAllStepFinished ( test ) ; test . reporter . testLifecycle ( TestEvent . BeforeAllStepFinished , 'beforeAll' ) ; } async onAfterAllStepFinished ( test ) { await this . next . onAfterAllStepFinished ( test ) ; test . reporter . testLifecycle ( TestEvent . AfterAllStepFinished , 'afterAll' ) ; } async onBeforeEachStepFinished ( test ) { await this . next . onBeforeEachStepFinished ( test ) ; test . reporter . testLifecycle ( TestEvent . BeforeEachStepFinished , 'beforeEach' ) ; } async onAfterEachStepFinished ( test ) { await this . next . onAfterEachStepFinished ( test ) ; test . reporter . testLifecycle ( TestEvent . AfterEachStepFinished , 'afterEach' ) ; } async beforeHookAction ( test , command , args ? ) { await this . next . beforeHookAction ( test , command , args ) ; test . reporter . testLifecycle ( TestEvent . BeforeHookAction , command , '' , 0 , '' , args ) ; } async afterHookAction ( test , command , args ? ) { await this . next . afterHookAction ( test , command , args ) ; test . reporter . testLifecycle ( TestEvent . AfterHookAction , command , '' , 0 , '' , args ) ; } }