import { ensureDir } from 'fs-extra' ; import { isGithubCI } from '@shared/core-utils' ; import { PeerTubeServer , RunServerOptions } from './server' ; async function createSingleServer ( serverNumber , configOverride ? , options = { } ) { const server = new PeerTubeServer ( { serverNumber } ) ; await server . flushAndRun ( configOverride , options ) ; return server ; } function createMultipleServers ( totalServers , configOverride ? , options = { } ) { const serverPromises = [ ] ; for ( let i = 1 ; i <= totalServers ; i ++ ) { serverPromises . push ( createSingleServer ( i , configOverride , options ) ) ; } return Promise . all ( serverPromises ) ; } async function killallServers ( servers ) { return Promise . all ( servers . map ( s => s . kill ( ) ) ) ; } async function cleanupTests ( servers ) { await killallServers ( servers ) ; if ( isGithubCI ( ) ) { await ensureDir ( 'artifacts' ) ; } let p = [ ] ; for ( const server of servers ) { p = p . concat ( server . servers . cleanupTests ( ) ) ; } return Promise . all ( p ) ; } export { createSingleServer , createMultipleServers , cleanupTests , killallServers } ;