1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { join } from 'path'
4 import { checkDirectoryIsEmpty, checkTmpIsEmpty, completeCheckHlsPlaylist } from '@server/tests/shared'
5 import { areMockObjectStorageTestsDisabled } from '@shared/core-utils'
6 import { HttpStatusCode } from '@shared/models'
13 setAccessTokensToServers,
15 } from '@shared/server-commands'
16 import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants'
18 describe('Test HLS videos', function () {
19 let servers: PeerTubeServer[] = []
21 function runTestSuite (hlsOnly: boolean, objectStorageBaseUrl?: string) {
22 const videoUUIDs: string[] = []
24 it('Should upload a video and transcode it to HLS', async function () {
27 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video 1', fixture: 'video_short.webm' } })
30 await waitJobs(servers)
32 await completeCheckHlsPlaylist({ servers, videoUUID: uuid, hlsOnly, objectStorageBaseUrl })
35 it('Should upload an audio file and transcode it to HLS', async function () {
38 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video audio', fixture: 'sample.ogg' } })
41 await waitJobs(servers)
43 await completeCheckHlsPlaylist({
47 resolutions: [ DEFAULT_AUDIO_RESOLUTION, 360, 240 ],
52 it('Should update the video', async function () {
55 await servers[0].videos.update({ id: videoUUIDs[0], attributes: { name: 'video 1 updated' } })
57 await waitJobs(servers)
59 await completeCheckHlsPlaylist({ servers, videoUUID: videoUUIDs[0], hlsOnly, objectStorageBaseUrl })
62 it('Should delete videos', async function () {
63 for (const uuid of videoUUIDs) {
64 await servers[0].videos.remove({ id: uuid })
67 await waitJobs(servers)
69 for (const server of servers) {
70 for (const uuid of videoUUIDs) {
71 await server.videos.get({ id: uuid, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
76 it('Should have the playlists/segment deleted from the disk', async function () {
77 for (const server of servers) {
78 await checkDirectoryIsEmpty(server, 'videos', [ 'private' ])
79 await checkDirectoryIsEmpty(server, join('videos', 'private'))
81 await checkDirectoryIsEmpty(server, join('streaming-playlists', 'hls'), [ 'private' ])
82 await checkDirectoryIsEmpty(server, join('streaming-playlists', 'hls', 'private'))
86 it('Should have an empty tmp directory', async function () {
87 for (const server of servers) {
88 await checkTmpIsEmpty(server)
93 before(async function () {
96 const configOverride = {
99 allow_audio_files: true,
105 servers = await createMultipleServers(2, configOverride)
107 // Get the access tokens
108 await setAccessTokensToServers(servers)
110 // Server 1 and server 2 follow each other
111 await doubleFollow(servers[0], servers[1])
114 describe('With WebTorrent & HLS enabled', function () {
118 describe('With only HLS enabled', function () {
120 before(async function () {
121 await servers[0].config.updateCustomSubConfig({
125 allowAudioFiles: true,
150 describe('With object storage enabled', function () {
151 if (areMockObjectStorageTestsDisabled()) return
153 before(async function () {
156 const configOverride = ObjectStorageCommand.getDefaultMockConfig()
157 await ObjectStorageCommand.prepareDefaultMockBuckets()
159 await servers[0].kill()
160 await servers[0].run(configOverride)
163 runTestSuite(true, ObjectStorageCommand.getMockPlaylistBaseUrl())
166 after(async function () {
167 await cleanupTests(servers)