import { Stage , StageCrewMember } from '@serenity-js/core' ; import * as events from '@serenity-js/core/lib/events' ; import { Writable } from 'stream' ; export class StdOutReporter implements StageCrewMember { public static linePrefix = '[Serenity/JS]' ; static parse ( stdout ) { return stdout . split ( '\n' ) . filter ( line => ! ! ~ line . indexOf ( StdOutReporter . linePrefix ) ) . map ( line => { const matched = line . match ( /.*?\[Serenity\/JS](.*)$/ ) ; const serialised = JSON . parse ( matched [ 1 ] ) ; return events [ serialised . type ] . fromJSON ( serialised . event ) ; } ) ; } constructor ( private readonly output = process . stdout , private readonly stage = null ) { } assignedTo ( stage ) { return new StdOutReporter ( this . output , stage ) ; } notifyOf ( event ) { this . output . write ( `${ StdOutReporter . linePrefix }${ JSON . stringify ( { type : event . constructor . name , event : event . toJSON ( ) } ) }\n` ) ; } }