aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/transcoding/hls.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-07-31 14:34:36 +0200
committerChocobozzz <me@florianbigard.com>2023-08-11 15:02:33 +0200
commit3a4992633ee62d5edfbb484d9c6bcb3cf158489d (patch)
treee4510b39bdac9c318fdb4b47018d08f15368b8f0 /server/tests/api/transcoding/hls.ts
parent04d1da5621d25d59bd5fa1543b725c497bf5d9a8 (diff)
downloadPeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.gz
PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.zst
PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.zip
Migrate server to ESM
Sorry for the very big commit that may lead to git log issues and merge conflicts, but it's a major step forward: * Server can be faster at startup because imports() are async and we can easily lazy import big modules * Angular doesn't seem to support ES import (with .js extension), so we had to correctly organize peertube into a monorepo: * Use yarn workspace feature * Use typescript reference projects for dependencies * Shared projects have been moved into "packages", each one is now a node module (with a dedicated package.json/tsconfig.json) * server/tools have been moved into apps/ and is now a dedicated app bundled and published on NPM so users don't have to build peertube cli tools manually * server/tests have been moved into packages/ so we don't compile them every time we want to run the server * Use isolatedModule option: * Had to move from const enum to const (https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums) * Had to explictely specify "type" imports when used in decorators * Prefer tsx (that uses esbuild under the hood) instead of ts-node to load typescript files (tests with mocha or scripts): * To reduce test complexity as esbuild doesn't support decorator metadata, we only test server files that do not import server models * We still build tests files into js files for a faster CI * Remove unmaintained peertube CLI import script * Removed some barrels to speed up execution (less imports)
Diffstat (limited to 'server/tests/api/transcoding/hls.ts')
-rw-r--r--server/tests/api/transcoding/hls.ts175
1 files changed, 0 insertions, 175 deletions
diff --git a/server/tests/api/transcoding/hls.ts b/server/tests/api/transcoding/hls.ts
deleted file mode 100644
index d67043c2a..000000000
--- a/server/tests/api/transcoding/hls.ts
+++ /dev/null
@@ -1,175 +0,0 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { join } from 'path'
4import { checkDirectoryIsEmpty, checkTmpIsEmpty, completeCheckHlsPlaylist } from '@server/tests/shared'
5import { areMockObjectStorageTestsDisabled } from '@shared/core-utils'
6import { HttpStatusCode } from '@shared/models'
7import {
8 cleanupTests,
9 createMultipleServers,
10 doubleFollow,
11 ObjectStorageCommand,
12 PeerTubeServer,
13 setAccessTokensToServers,
14 waitJobs
15} from '@shared/server-commands'
16import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants'
17
18describe('Test HLS videos', function () {
19 let servers: PeerTubeServer[] = []
20
21 function runTestSuite (hlsOnly: boolean, objectStorageBaseUrl?: string) {
22 const videoUUIDs: string[] = []
23
24 it('Should upload a video and transcode it to HLS', async function () {
25 this.timeout(120000)
26
27 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video 1', fixture: 'video_short.webm' } })
28 videoUUIDs.push(uuid)
29
30 await waitJobs(servers)
31
32 await completeCheckHlsPlaylist({ servers, videoUUID: uuid, hlsOnly, objectStorageBaseUrl })
33 })
34
35 it('Should upload an audio file and transcode it to HLS', async function () {
36 this.timeout(120000)
37
38 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video audio', fixture: 'sample.ogg' } })
39 videoUUIDs.push(uuid)
40
41 await waitJobs(servers)
42
43 await completeCheckHlsPlaylist({
44 servers,
45 videoUUID: uuid,
46 hlsOnly,
47 resolutions: [ DEFAULT_AUDIO_RESOLUTION, 360, 240 ],
48 objectStorageBaseUrl
49 })
50 })
51
52 it('Should update the video', async function () {
53 this.timeout(30000)
54
55 await servers[0].videos.update({ id: videoUUIDs[0], attributes: { name: 'video 1 updated' } })
56
57 await waitJobs(servers)
58
59 await completeCheckHlsPlaylist({ servers, videoUUID: videoUUIDs[0], hlsOnly, objectStorageBaseUrl })
60 })
61
62 it('Should delete videos', async function () {
63 for (const uuid of videoUUIDs) {
64 await servers[0].videos.remove({ id: uuid })
65 }
66
67 await waitJobs(servers)
68
69 for (const server of servers) {
70 for (const uuid of videoUUIDs) {
71 await server.videos.get({ id: uuid, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
72 }
73 }
74 })
75
76 it('Should have the playlists/segment deleted from the disk', async function () {
77 for (const server of servers) {
78 await checkDirectoryIsEmpty(server, 'web-videos', [ 'private' ])
79 await checkDirectoryIsEmpty(server, join('web-videos', 'private'))
80
81 await checkDirectoryIsEmpty(server, join('streaming-playlists', 'hls'), [ 'private' ])
82 await checkDirectoryIsEmpty(server, join('streaming-playlists', 'hls', 'private'))
83 }
84 })
85
86 it('Should have an empty tmp directory', async function () {
87 for (const server of servers) {
88 await checkTmpIsEmpty(server)
89 }
90 })
91 }
92
93 before(async function () {
94 this.timeout(120000)
95
96 const configOverride = {
97 transcoding: {
98 enabled: true,
99 allow_audio_files: true,
100 hls: {
101 enabled: true
102 }
103 }
104 }
105 servers = await createMultipleServers(2, configOverride)
106
107 // Get the access tokens
108 await setAccessTokensToServers(servers)
109
110 // Server 1 and server 2 follow each other
111 await doubleFollow(servers[0], servers[1])
112 })
113
114 describe('With Web Video & HLS enabled', function () {
115 runTestSuite(false)
116 })
117
118 describe('With only HLS enabled', function () {
119
120 before(async function () {
121 await servers[0].config.updateCustomSubConfig({
122 newConfig: {
123 transcoding: {
124 enabled: true,
125 allowAudioFiles: true,
126 resolutions: {
127 '144p': false,
128 '240p': true,
129 '360p': true,
130 '480p': true,
131 '720p': true,
132 '1080p': true,
133 '1440p': true,
134 '2160p': true
135 },
136 hls: {
137 enabled: true
138 },
139 webVideos: {
140 enabled: false
141 }
142 }
143 }
144 })
145 })
146
147 runTestSuite(true)
148 })
149
150 describe('With object storage enabled', function () {
151 if (areMockObjectStorageTestsDisabled()) return
152
153 const objectStorage = new ObjectStorageCommand()
154
155 before(async function () {
156 this.timeout(120000)
157
158 const configOverride = objectStorage.getDefaultMockConfig()
159 await objectStorage.prepareDefaultMockBuckets()
160
161 await servers[0].kill()
162 await servers[0].run(configOverride)
163 })
164
165 runTestSuite(true, objectStorage.getMockPlaylistBaseUrl())
166
167 after(async function () {
168 await objectStorage.cleanupMock()
169 })
170 })
171
172 after(async function () {
173 await cleanupTests(servers)
174 })
175})