X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=shared%2Futils%2Fserver%2Fservers.ts;h=1e9c83c72ad8bebd4393da73e4b950cebfe9eb4f;hb=5abb9fbbd12e7097e348d6a38622d364b1fa47ed;hp=88d2b390cf9015bf9d83cd3b232f8c79bcfc2f38;hpb=2a8c5d0af13f3ccb9a505e1fbc9d324b9d33ba1f;p=github%2FChocobozzz%2FPeerTube.git diff --git a/shared/utils/server/servers.ts b/shared/utils/server/servers.ts index 88d2b390c..1e9c83c72 100644 --- a/shared/utils/server/servers.ts +++ b/shared/utils/server/servers.ts @@ -1,7 +1,11 @@ +/* tslint:disable:no-unused-expression */ + import { ChildProcess, exec, fork } from 'child_process' import { join } from 'path' import { root, wait } from '../miscs/miscs' -import { readFile } from 'fs-extra' +import { readdir, readFile } from 'fs-extra' +import { existsSync } from 'fs' +import { expect } from 'chai' interface ServerInfo { app: ChildProcess, @@ -141,8 +145,12 @@ function runServer (serverNumber: number, configOverride?: Object, args = []) { if (dontContinue === true) return server.app.stdout.removeListener('data', onStdout) + + process.on('exit', () => process.kill(server.app.pid)) + res(server) }) + }) } @@ -153,6 +161,18 @@ async function reRunServer (server: ServerInfo, configOverride?: any) { return server } +async function checkTmpIsEmpty (server: ServerInfo) { + const testDirectory = 'test' + server.serverNumber + + const directoryPath = join(root(), testDirectory, 'tmp') + + const directoryExists = existsSync(directoryPath) + expect(directoryExists).to.be.true + + const files = await readdir(directoryPath) + expect(files).to.have.lengthOf(0) +} + function killallServers (servers: ServerInfo[]) { for (const server of servers) { process.kill(-server.app.pid) @@ -175,6 +195,7 @@ async function waitUntilLog (server: ServerInfo, str: string, count = 1) { // --------------------------------------------------------------------------- export { + checkTmpIsEmpty, ServerInfo, flushAndRunMultipleServers, flushTests,