import { PathLike } from "fs" ; import { v4 as randomUUID } from "uuid" ; import { AllureConfig } from "./AllureConfig" ; import { AllureGroup } from "./AllureGroup" ; import { AttachmentOptions , Category , ContentType , TestResult , TestResultContainer } from "./model" ; import { AllureWriter , FileSystemAllureWriter , typeToExtension } from "./writers" ; const buildAttachmentFileName = ( options ) : string => { if ( typeof options === "string" ) { options = { contentType : options } ; } const extension = typeToExtension ( options ) ; return `${ randomUUID ( ) }-attachment.${ extension }` ; } ; export class AllureRuntime { private writer : AllureWriter ; constructor ( private config ) { this . writer = config . writer || new FileSystemAllureWriter ( config ) ; } startGroup ( name ? ) { const allureContainer = new AllureGroup ( this ) ; allureContainer . name = name || "Unnamed" ; return allureContainer ; } writeResult ( result ) { const modifiedResult = this . config . testMapper !== undefined ? this . config . testMapper ( result ) : result ; if ( modifiedResult != null ) { this . writer . writeResult ( modifiedResult ) ; } } writeGroup ( result ) { this . writer . writeGroup ( result ) ; } writeAttachment ( content , options ) { const fileName = buildAttachmentFileName ( options ) ; this . writer . writeAttachment ( fileName , content ) ; return fileName ; } writeAttachmentFromPath ( fromPath , options ) { const fileName = buildAttachmentFileName ( options ) ; this . writer . writeAttachmentFromPath ( fromPath , fileName ) ; return fileName ; } writeEnvironmentInfo ( info ? ) { this . writer . writeEnvironmentInfo ( info || process . env ) ; } writeCategoriesDefinitions ( categories ) { const serializedCategories = categories . map ( ( c ) => { if ( c . messageRegex instanceof RegExp ) { c . messageRegex = c . messageRegex . source ; } if ( c . traceRegex instanceof RegExp ) { c . traceRegex = c . traceRegex . source ; } return c ; } ) ; this . writer . writeCategoriesDefinitions ( serializedCategories ) ; } }