]>
Commit | Line | Data |
---|---|---|
6c5065a0 C |
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' | |
c55e3d72 | 5 | import { PeerTubeServer } from '@shared/server-commands' |
6c5065a0 | 6 | |
254d3579 | 7 | async 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 | ||
254d3579 | 15 | async function checkDirectoryIsEmpty (server: PeerTubeServer, directory: string, exceptions: string[] = []) { |
6c5f0d3a | 16 | const directoryPath = server.getDirectoryPath(directory) |
6c5065a0 C |
17 | |
18 | const directoryExists = await pathExists(directoryPath) | |
19 | expect(directoryExists).to.be.true | |
20 | ||
21 | const files = await readdir(directoryPath) | |
22 | const filtered = files.filter(f => exceptions.includes(f) === false) | |
23 | ||
24 | expect(filtered).to.have.lengthOf(0) | |
25 | } | |
26 | ||
27 | export { | |
28 | checkTmpIsEmpty, | |
29 | checkDirectoryIsEmpty | |
30 | } |