import glob = require ( "glob" ) ; import path = require ( "path" ) ; import jsonMerger = require ( "json-merger" ) ; import { IIncludeData , IServerData , IUserData , } from "./page-objects/interface-po" ; const TEST_RESOURCE = path . join ( __dirname , ".." , ".." , "test" , "resources" ) ; const scenarioDefault = path . join ( TEST_RESOURCE , "scenario" , "default.scenario.json" ) ; let values ; let valuesFile ; let scenarioFile = scenarioDefault ; if ( process . env . SCENARIO ) { scenarioFile = path . join ( TEST_RESOURCE , "scenario" , process . env . SCENARIO . trim ( ) + ".scenario.json" ) ; const valuesDefault = jsonMerger . mergeFiles ( [ scenarioDefault ] ) ; valuesFile = jsonMerger . mergeFiles ( [ scenarioFile ] ) ; values = jsonMerger . mergeObjects ( [ valuesDefault , valuesFile ] ) ; values . description = valuesFile . description ; } else { values = jsonMerger . mergeFiles ( [ scenarioFile ] ) ; } console . log ( "--------------------------------------" ) ; console . log ( `Scenario: ${ values . name } (${ path . basename ( scenarioFile ) })` ) ; console . log ( `\t${ values . description . join ( "\n\t" ) }` ) ; if ( valuesFile ) { console . log ( JSON . stringify ( valuesFile , null , "  " ) ) ; } console . log ( "--------------------------------------" ) ; export const APPSERVER_DATA = values . server ; export const DELETE_DATA = { ... APPSERVER_DATA , serverName : "forDelete" , } ; export const ADMIN_USER_DATA = values . users . admin ; export const NO_ADMIN_USER_DATA = values . users . user ; export const INVALID_USER_DATA = values . users . invalid ; export const INCLUDE_PATH_DATA = values . includePath ; export const COMPILE_KEY_FILE = { } ; const patchFolder = path . join ( TEST_RESOURCE , "patchs" , values . patchFolder ) ; const templateFolder = path . join ( TEST_RESOURCE , "templates" , values . templatesFolder ) ; const patchFiles = getFileParams ( patchFolder , true ) ; export const PATCHS_FILES = { single : patchFiles [ "single" ] ? patchFiles [ "single" ] [ 0 ] : undefined , many : patchFiles [ "many" ] , zip : patchFiles [ "zip" ] , invalid : patchFiles [ "invalid" ] , } ; const templateFiles = getFileParams ( templateFolder , true ) ; export const TEMPLATE_FILES = templateFiles ? { ... templateFiles } : undefined ; export const PROJECT_FOLDER = path . join ( TEST_RESOURCE , "projects" , values . projectFolder ) ; const sourceFiles = getFileParams ( PROJECT_FOLDER , false ) ; export const COMPILE_FILES = { singleFile : sourceFiles [ "singleFile" ] . length ? sourceFiles [ "singleFile" ] [ 0 ] : null , userFunctions : sourceFiles [ "userFunction" ] , functions : sourceFiles [ "function" ] , resources : sourceFiles [ "resource" ] , sourcesWithError : sourceFiles [ "withError" ] , } ; const replayFolder = path . join ( TEST_RESOURCE , values . replayFolder ) ; const replayFiles = getFileParams ( replayFolder , true ) ; export const REPLAY_FILES = Object . keys ( replayFiles ) . length ? replayFiles : null ; Object . keys ( values . compileKey ) . forEach ( ( key ) => { COMPILE_KEY_FILE [ key ] = path . join ( TEST_RESOURCE , "compile-key" , values . compileKey [ key ] ) ; } ) ; function getFileParams ( patchFolder , absolute ) { const result = [ ] ; const files = glob . sync ( "**/**.*" , { cwd : patchFolder , absolute : absolute , } ) ; for ( const file of files ) { const parentFolder = path . dirname ( file ) ; const folder = path . basename ( parentFolder ) ; result [ folder ] ? result [ folder ] . push ( file ) : ( result [ folder ] = [ file ] ) ; } Object . keys ( result ) . forEach ( ( key ) => { if ( result [ key ] . length == 0 ) { console . warn ( `'${ key }' folder does not contain files. Test will be skipped.` ) ; result [ key ] = null ; } } ) ; return result ; }