1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
4 import { pathExists, readdir } from 'fs-extra'
5 import { homedir } from 'os'
6 import { join } from 'path'
7 import { PeerTubeServer } from '@shared/server-commands'
8 import { PeerTubeRunnerProcess } from './peertube-runner-process'
10 export async function checkTmpIsEmpty (server: PeerTubeServer) {
11 await checkDirectoryIsEmpty(server, 'tmp', [ 'plugins-global.css', 'hls', 'resumable-uploads' ])
13 if (await pathExists(server.getDirectoryPath('tmp/hls'))) {
14 await checkDirectoryIsEmpty(server, 'tmp/hls')
18 export async function checkPersistentTmpIsEmpty (server: PeerTubeServer) {
19 await checkDirectoryIsEmpty(server, 'tmp-persistent')
22 export async function checkDirectoryIsEmpty (server: PeerTubeServer, directory: string, exceptions: string[] = []) {
23 const directoryPath = server.getDirectoryPath(directory)
25 const directoryExists = await pathExists(directoryPath)
26 expect(directoryExists).to.be.true
28 const files = await readdir(directoryPath)
29 const filtered = files.filter(f => exceptions.includes(f) === false)
31 expect(filtered).to.have.lengthOf(0)
34 export async function checkPeerTubeRunnerCacheIsEmpty (runner: PeerTubeRunnerProcess) {
35 const directoryPath = join(homedir(), '.cache', 'peertube-runner-nodejs', runner.getId(), 'transcoding')
37 const directoryExists = await pathExists(directoryPath)
38 expect(directoryExists).to.be.true
40 const files = await readdir(directoryPath)
42 expect(files).to.have.lengthOf(0)