import { copyFileSync , existsSync , PathLike , writeFileSync } from "fs" ; import { join } from "path" ; import { sync as mkdirSync } from "mkdirp" ; import { stringify } from "properties" ; import { AllureConfig } from "../AllureConfig" ; import { Category , TestResult , TestResultContainer } from "../model" ; import { AllureWriter } from "./AllureWriter" ; const writeJson = ( path , data ) : void => { writeFileSync ( path , JSON . stringify ( data ) , { encoding : "utf-8" } ) ; } ; export class FileSystemAllureWriter implements AllureWriter { constructor ( private config ) { if ( ! existsSync ( this . config . resultsDir ) ) { mkdirSync ( this . config . resultsDir ) ; } } writeAttachment ( name , content ) { const path = this . buildPath ( name ) ; writeFileSync ( path , content ) ; } writeAttachmentFromPath ( from , distFileName ) { const to = this . buildPath ( distFileName ) ; copyFileSync ( from , to ) ; } writeEnvironmentInfo ( info ? ) { const text = stringify ( info , { unicode : true } ) . toString ( ) ; const path = this . buildPath ( "environment.properties" ) ; writeFileSync ( path , text ) ; } writeCategoriesDefinitions ( categories ) { const path = this . buildPath ( "categories.json" ) ; writeJson ( path , categories ) ; } writeGroup ( result ) { const path = this . buildPath ( `${ result . uuid }-container.json` ) ; writeJson ( path , result ) ; } writeResult ( result ) { const path = this . buildPath ( `${ result . uuid }-result.json` ) ; writeJson ( path , result ) ; } private buildPath ( name ) { return join ( this . config . resultsDir , name ) ; } }