]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/shared/directories.ts
Add TMP persistent directory
[github/Chocobozzz/PeerTube.git] / server / tests / shared / directories.ts
CommitLineData
6c5065a0
C
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { expect } from 'chai'
4import { pathExists, readdir } from 'fs-extra'
c55e3d72 5import { PeerTubeServer } from '@shared/server-commands'
6c5065a0 6
254d3579 7async function checkTmpIsEmpty (server: PeerTubeServer) {
6c5065a0
C
8 await checkDirectoryIsEmpty(server, 'tmp', [ 'plugins-global.css', 'hls', 'resumable-uploads' ])
9
6c5f0d3a 10 if (await pathExists(server.getDirectoryPath('tmp/hls'))) {
6c5065a0
C
11 await checkDirectoryIsEmpty(server, 'tmp/hls')
12 }
13}
14
6a490560
C
15async function checkPersistentTmpIsEmpty (server: PeerTubeServer) {
16 await checkDirectoryIsEmpty(server, 'tmp-persistent')
17}
18
254d3579 19async function checkDirectoryIsEmpty (server: PeerTubeServer, directory: string, exceptions: string[] = []) {
6c5f0d3a 20 const directoryPath = server.getDirectoryPath(directory)
6c5065a0
C
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
31export {
32 checkTmpIsEmpty,
6a490560 33 checkPersistentTmpIsEmpty,
6c5065a0
C
34 checkDirectoryIsEmpty
35}