import { Reporter } from "./Reporter" ; import { LogEntry } from "../LogEntry" ; import { LogLevel } from "../LogLevel" ; import { RunContext } from "../../types/RunContext" ; import { hrToSeconds } from "./formatDuration" ; export class JsonReporter implements Reporter { constructor ( private options ) { } log ( entry ) { if ( this . options . logLevel >= entry . level ) { console . log ( JSON . stringify ( entry ) ) ; } } summarize ( context ) { const { measures , targets } = context ; const summary = { } ; const taskStats = [ ] ; for ( const wrappedTarget of targets . values ( ) ) { taskStats . push ( { package : wrappedTarget . target . packageName , task : wrappedTarget . target . task , duration : hrToSeconds ( wrappedTarget . duration ) , status : wrappedTarget . status } ) ; } if ( measures . failedTargets && measures . failedTargets . length > 0 ) { summary . failedTargets = measures . failedTargets ; } summary . duration = hrToSeconds ( measures . duration ) ; summary . taskStats = taskStats ; console . log ( JSON . stringify ( { summary } ) ) ; } }