import { Allure , AllureRuntime , AllureStep , AllureTest , AttachmentOptions , ContentType , ExecutableItemWrapper , isPromise , Status , StepInterface , } from "allure-js-commons" ; import { CucumberJSAllureFormatter } from "./CucumberJSAllureReporter" ; export class CucumberAllureInterface extends Allure { constructor ( private readonly reporter , runtime ) { super ( runtime ) ; } step < T > ( name , body ) { const wrappedStep = this . startStep ( name ) ; let result ; try { result = wrappedStep . run ( body ) ; } catch ( err ) { wrappedStep . setError ( err as Error ) ; wrappedStep . endStep ( ) ; throw err ; } if ( isPromise ( result ) ) { const promise = result as any as Promise < any > ; return promise . then ( ( a ) => { wrappedStep . endStep ( ) ; return a ; } ) . catch ( ( e ) => { wrappedStep . setError ( e ) ; wrappedStep . endStep ( ) ; throw e ; } ) as any as T ; } else { wrappedStep . endStep ( ) ; return result ; } } logStep ( name , status ? ) { const step = this . startStep ( name ) ; step . setStatus ( status ) ; step . endStep ( ) ; } attachment ( name , content , options ) { const file = this . reporter . writeAttachment ( content , options ) ; this . currentExecutable . addAttachment ( name , options , file ) ; } testAttachment ( name , content , options ) { const file = this . reporter . writeAttachment ( content , options ) ; this . currentTest . addAttachment ( name , options , file ) ; } addParameter ( name , value ) { this . currentTest . addParameter ( name , value ) ; } addLabel ( name , value ) { this . currentTest . addLabel ( name , value ) ; } addIssueLink ( url , name ) { this . currentTest . addIssueLink ( url , name ) ; } addTmsLink ( url , name ) { this . currentTest . addTmsLink ( url , name ) ; } protected get currentExecutable ( ) : ExecutableItemWrapper { const result = this . reporter . currentStep || this . reporter . currentTest ; if ( result === null ) { throw new Error ( "No executable!" ) ; } return result ; } protected get currentTest ( ) : AllureTest { if ( this . reporter . currentTest === null ) { throw new Error ( "No test running!" ) ; } return this . reporter . currentTest ; } private startStep ( name ) { const allureStep = this . currentExecutable . startStep ( name ) ; this . reporter . pushStep ( allureStep ) ; return new WrappedStep ( this . reporter , allureStep ) ; } } export class WrappedStep { constructor ( private readonly reporter , private readonly step ) { } startStep ( name ) { const step = this . step . startStep ( name ) ; this . reporter . pushStep ( step ) ; return new WrappedStep ( this . reporter , step ) ; } setStatus ( status ? ) { this . step . status = status ; } setError ( error ) { this . step . status = Status . FAILED ; this . step . detailsMessage = error . message ; this . step . detailsTrace = error . stack ; } endStep ( ) { this . reporter . popStep ( ) ; this . step . endStep ( ) ; } run < T > ( body ) { return this . step . wrap ( body ) ( ) ; } }