UNPKG

@travetto/test

Version:

Declarative test framework

22 lines (18 loc) 596 B
import { Writable } from 'node:stream'; import type { TestEvent } from '../../model/event'; import type { TestConsumerShape } from '../types'; import { SerializeUtil } from '../serialize'; import { TestConsumer } from '../registry'; /** * Streams all test events a JSON payload, in an nd-json format */ @TestConsumer() export class EventStreamer implements TestConsumerShape { #stream: Writable; constructor(stream: Writable = process.stdout) { this.#stream = stream; } onEvent(event: TestEvent): void { this.#stream.write(`${SerializeUtil.serializeToJSON(event)}\n`); } }