]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/shared/directories.ts
Add TMP persistent directory
[github/Chocobozzz/PeerTube.git] / server / tests / shared / directories.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import { expect } from 'chai'
4 import { pathExists, readdir } from 'fs-extra'
5 import { PeerTubeServer } from '@shared/server-commands'
6
7 async function checkTmpIsEmpty (server: PeerTubeServer) {
8 await checkDirectoryIsEmpty(server, 'tmp', [ 'plugins-global.css', 'hls', 'resumable-uploads' ])
9
10 if (await pathExists(server.getDirectoryPath('tmp/hls'))) {
11 await checkDirectoryIsEmpty(server, 'tmp/hls')
12 }
13 }
14
15 async function checkPersistentTmpIsEmpty (server: PeerTubeServer) {
16 await checkDirectoryIsEmpty(server, 'tmp-persistent')
17 }
18
19 async function checkDirectoryIsEmpty (server: PeerTubeServer, directory: string, exceptions: string[] = []) {
20 const directoryPath = server.getDirectoryPath(directory)
21
22 const directoryExists = await pathExists(directoryPath)
23 expect(directoryExists).to.be.true
24
25 const files = await readdir(directoryPath)
26 const filtered = files.filter(f => exceptions.includes(f) === false)
27
28 expect(filtered).to.have.lengthOf(0)
29 }
30
31 export {
32 checkTmpIsEmpty,
33 checkPersistentTmpIsEmpty,
34 checkDirectoryIsEmpty
35 }