import { PathLike , readFileSync } from "fs" ; import { Category , TestResult , TestResultContainer } from "../model" ; import { AllureWriter } from "./AllureWriter" ; export interface AllureResults { tests : TestResult [ ] ; groups : TestResultContainer [ ] ; attachments : Record < string , Buffer | string > ; } export class InMemoryAllureWriter implements AllureWriter { public groups : TestResultContainer [ ] = [ ] ; public tests : TestResult [ ] = [ ] ; public attachments : Record < string , Buffer | string > = { } ; public categories ? : Category [ ] ; public envInfo ? : Record < string , string | undefined > ; public writeGroup ( result ) { this . groups . push ( result ) ; } public writeResult ( result ) { this . tests . push ( result ) ; } public writeAttachment ( name , content ) { this . attachments [ name ] = content ; } public writeAttachmentFromPath ( from , toFileName ) { this . attachments [ toFileName ] = readFileSync ( from ) ; } public writeCategoriesDefinitions ( categories ) { if ( this . categories ) { console . warn ( "overwriting existing categories" ) ; } this . categories = categories ; } public writeEnvironmentInfo ( envInfo ? ) { if ( this . envInfo ) { console . warn ( "overwriting existing environment info" ) ; } this . envInfo = envInfo ; } public reset ( ) { this . groups = [ ] ; this . tests = [ ] ; this . attachments = { } ; } public getMaybeTestByName ( name ) { return this . tests . find ( ( t ) => t . name === name ) ; } public getTestByName ( name ) { const res = this . getMaybeTestByName ( name ) ; if ( ! res ) { throw new Error ( `Test not found: ${ name }` ) ; } return res ; } public getMaybeGroupByName ( name ) { return this . groups . find ( ( g ) => g . name === name ) ; } public getGroupByName ( name ) { const res = this . getMaybeGroupByName ( name ) ; if ( ! res ) { throw new Error ( `Group not found: ${ name }` ) ; } return res ; } }