import * as messages from '@cucumber/messages' ; import CucumberHtmlStream from '../src/CucumberHtmlStream' ; import { Writable } from 'stream' ; import assert from 'assert' ; async function renderAsHtml ( ... envelopes ) { return new Promise ( ( resolve , reject ) => { let html = '' ; const sink = new Writable ( { write ( chunk , encoding , callback ) { html += chunk ; callback ( ) ; } , } ) ; sink . on ( 'finish' , ( ) => resolve ( html ) ) ; const cucumberHtmlStream = new CucumberHtmlStream ( `${ __dirname }/dummy.css` , `${ __dirname }/dummy.js` ) ; cucumberHtmlStream . on ( 'error' , reject ) ; cucumberHtmlStream . pipe ( sink ) ; for ( const envelope of envelopes ) { cucumberHtmlStream . write ( envelope ) ; } cucumberHtmlStream . end ( ) ; } ) ; } describe ( 'CucumberHtmlStream' , ( ) => { it ( 'writes zero messages to html' , async ( ) => { const html = await renderAsHtml ( ) ; assert ( html . indexOf ( 'window.CUCUMBER_MESSAGES = []' ) >= 0 ) ; } ) ; it ( 'writes one message to html' , async ( ) => { const e1 = { testRunStarted : { timestamp : { seconds : 0 , nanos : 0 } , } , } ; const html = await renderAsHtml ( e1 ) ; assert ( html . indexOf ( `window.CUCUMBER_MESSAGES = [${ JSON . stringify ( e1 ) }]` ) >= 0 ) ; } ) ; it ( 'writes two messages to html' , async ( ) => { const e1 = { testRunStarted : { timestamp : { seconds : 0 , nanos : 0 } , } , } ; const e2 = { testRunFinished : { timestamp : { seconds : 0 , nanos : 0 } , success : true , } , } ; const html = await renderAsHtml ( e1 , e2 ) ; assert ( html . indexOf ( `window.CUCUMBER_MESSAGES = [${ JSON . stringify ( e1 ) },${ JSON . stringify ( e2 ) }]` ) >= 0 ) ; } ) ; } ) ;