diff options
author | Chocobozzz <me@florianbigard.com> | 2023-07-31 14:34:36 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-08-11 15:02:33 +0200 |
commit | 3a4992633ee62d5edfbb484d9c6bcb3cf158489d (patch) | |
tree | e4510b39bdac9c318fdb4b47018d08f15368b8f0 /server/tests/api/videos/video-playlist-thumbnails.ts | |
parent | 04d1da5621d25d59bd5fa1543b725c497bf5d9a8 (diff) | |
download | PeerTube-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/videos/video-playlist-thumbnails.ts')
-rw-r--r-- | server/tests/api/videos/video-playlist-thumbnails.ts | 234 |
1 files changed, 0 insertions, 234 deletions
diff --git a/server/tests/api/videos/video-playlist-thumbnails.ts b/server/tests/api/videos/video-playlist-thumbnails.ts deleted file mode 100644 index c274c20bf..000000000 --- a/server/tests/api/videos/video-playlist-thumbnails.ts +++ /dev/null | |||
@@ -1,234 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { testImageGeneratedByFFmpeg } from '@server/tests/shared' | ||
5 | import { VideoPlaylistPrivacy } from '@shared/models' | ||
6 | import { | ||
7 | cleanupTests, | ||
8 | createMultipleServers, | ||
9 | doubleFollow, | ||
10 | PeerTubeServer, | ||
11 | setAccessTokensToServers, | ||
12 | setDefaultVideoChannel, | ||
13 | waitJobs | ||
14 | } from '@shared/server-commands' | ||
15 | |||
16 | describe('Playlist thumbnail', function () { | ||
17 | let servers: PeerTubeServer[] = [] | ||
18 | |||
19 | let playlistWithoutThumbnailId: number | ||
20 | let playlistWithThumbnailId: number | ||
21 | |||
22 | let withThumbnailE1: number | ||
23 | let withThumbnailE2: number | ||
24 | let withoutThumbnailE1: number | ||
25 | let withoutThumbnailE2: number | ||
26 | |||
27 | let video1: number | ||
28 | let video2: number | ||
29 | |||
30 | async function getPlaylistWithoutThumbnail (server: PeerTubeServer) { | ||
31 | const body = await server.playlists.list({ start: 0, count: 10 }) | ||
32 | |||
33 | return body.data.find(p => p.displayName === 'playlist without thumbnail') | ||
34 | } | ||
35 | |||
36 | async function getPlaylistWithThumbnail (server: PeerTubeServer) { | ||
37 | const body = await server.playlists.list({ start: 0, count: 10 }) | ||
38 | |||
39 | return body.data.find(p => p.displayName === 'playlist with thumbnail') | ||
40 | } | ||
41 | |||
42 | before(async function () { | ||
43 | this.timeout(120000) | ||
44 | |||
45 | servers = await createMultipleServers(2) | ||
46 | |||
47 | // Get the access tokens | ||
48 | await setAccessTokensToServers(servers) | ||
49 | await setDefaultVideoChannel(servers) | ||
50 | |||
51 | for (const server of servers) { | ||
52 | await server.config.disableTranscoding() | ||
53 | } | ||
54 | |||
55 | // Server 1 and server 2 follow each other | ||
56 | await doubleFollow(servers[0], servers[1]) | ||
57 | |||
58 | video1 = (await servers[0].videos.quickUpload({ name: 'video 1' })).id | ||
59 | video2 = (await servers[0].videos.quickUpload({ name: 'video 2' })).id | ||
60 | |||
61 | await waitJobs(servers) | ||
62 | }) | ||
63 | |||
64 | it('Should automatically update the thumbnail when adding an element', async function () { | ||
65 | this.timeout(30000) | ||
66 | |||
67 | const created = await servers[1].playlists.create({ | ||
68 | attributes: { | ||
69 | displayName: 'playlist without thumbnail', | ||
70 | privacy: VideoPlaylistPrivacy.PUBLIC, | ||
71 | videoChannelId: servers[1].store.channel.id | ||
72 | } | ||
73 | }) | ||
74 | playlistWithoutThumbnailId = created.id | ||
75 | |||
76 | const added = await servers[1].playlists.addElement({ | ||
77 | playlistId: playlistWithoutThumbnailId, | ||
78 | attributes: { videoId: video1 } | ||
79 | }) | ||
80 | withoutThumbnailE1 = added.id | ||
81 | |||
82 | await waitJobs(servers) | ||
83 | |||
84 | for (const server of servers) { | ||
85 | const p = await getPlaylistWithoutThumbnail(server) | ||
86 | await testImageGeneratedByFFmpeg(server.url, 'thumbnail-playlist', p.thumbnailPath) | ||
87 | } | ||
88 | }) | ||
89 | |||
90 | it('Should not update the thumbnail if we explicitly uploaded a thumbnail', async function () { | ||
91 | this.timeout(30000) | ||
92 | |||
93 | const created = await servers[1].playlists.create({ | ||
94 | attributes: { | ||
95 | displayName: 'playlist with thumbnail', | ||
96 | privacy: VideoPlaylistPrivacy.PUBLIC, | ||
97 | videoChannelId: servers[1].store.channel.id, | ||
98 | thumbnailfile: 'custom-thumbnail.jpg' | ||
99 | } | ||
100 | }) | ||
101 | playlistWithThumbnailId = created.id | ||
102 | |||
103 | const added = await servers[1].playlists.addElement({ | ||
104 | playlistId: playlistWithThumbnailId, | ||
105 | attributes: { videoId: video1 } | ||
106 | }) | ||
107 | withThumbnailE1 = added.id | ||
108 | |||
109 | await waitJobs(servers) | ||
110 | |||
111 | for (const server of servers) { | ||
112 | const p = await getPlaylistWithThumbnail(server) | ||
113 | await testImageGeneratedByFFmpeg(server.url, 'custom-thumbnail', p.thumbnailPath) | ||
114 | } | ||
115 | }) | ||
116 | |||
117 | it('Should automatically update the thumbnail when moving the first element', async function () { | ||
118 | this.timeout(30000) | ||
119 | |||
120 | const added = await servers[1].playlists.addElement({ | ||
121 | playlistId: playlistWithoutThumbnailId, | ||
122 | attributes: { videoId: video2 } | ||
123 | }) | ||
124 | withoutThumbnailE2 = added.id | ||
125 | |||
126 | await servers[1].playlists.reorderElements({ | ||
127 | playlistId: playlistWithoutThumbnailId, | ||
128 | attributes: { | ||
129 | startPosition: 1, | ||
130 | insertAfterPosition: 2 | ||
131 | } | ||
132 | }) | ||
133 | |||
134 | await waitJobs(servers) | ||
135 | |||
136 | for (const server of servers) { | ||
137 | const p = await getPlaylistWithoutThumbnail(server) | ||
138 | await testImageGeneratedByFFmpeg(server.url, 'thumbnail-playlist', p.thumbnailPath) | ||
139 | } | ||
140 | }) | ||
141 | |||
142 | it('Should not update the thumbnail when moving the first element if we explicitly uploaded a thumbnail', async function () { | ||
143 | this.timeout(30000) | ||
144 | |||
145 | const added = await servers[1].playlists.addElement({ | ||
146 | playlistId: playlistWithThumbnailId, | ||
147 | attributes: { videoId: video2 } | ||
148 | }) | ||
149 | withThumbnailE2 = added.id | ||
150 | |||
151 | await servers[1].playlists.reorderElements({ | ||
152 | playlistId: playlistWithThumbnailId, | ||
153 | attributes: { | ||
154 | startPosition: 1, | ||
155 | insertAfterPosition: 2 | ||
156 | } | ||
157 | }) | ||
158 | |||
159 | await waitJobs(servers) | ||
160 | |||
161 | for (const server of servers) { | ||
162 | const p = await getPlaylistWithThumbnail(server) | ||
163 | await testImageGeneratedByFFmpeg(server.url, 'custom-thumbnail', p.thumbnailPath) | ||
164 | } | ||
165 | }) | ||
166 | |||
167 | it('Should automatically update the thumbnail when deleting the first element', async function () { | ||
168 | this.timeout(30000) | ||
169 | |||
170 | await servers[1].playlists.removeElement({ | ||
171 | playlistId: playlistWithoutThumbnailId, | ||
172 | elementId: withoutThumbnailE1 | ||
173 | }) | ||
174 | |||
175 | await waitJobs(servers) | ||
176 | |||
177 | for (const server of servers) { | ||
178 | const p = await getPlaylistWithoutThumbnail(server) | ||
179 | await testImageGeneratedByFFmpeg(server.url, 'thumbnail-playlist', p.thumbnailPath) | ||
180 | } | ||
181 | }) | ||
182 | |||
183 | it('Should not update the thumbnail when deleting the first element if we explicitly uploaded a thumbnail', async function () { | ||
184 | this.timeout(30000) | ||
185 | |||
186 | await servers[1].playlists.removeElement({ | ||
187 | playlistId: playlistWithThumbnailId, | ||
188 | elementId: withThumbnailE1 | ||
189 | }) | ||
190 | |||
191 | await waitJobs(servers) | ||
192 | |||
193 | for (const server of servers) { | ||
194 | const p = await getPlaylistWithThumbnail(server) | ||
195 | await testImageGeneratedByFFmpeg(server.url, 'custom-thumbnail', p.thumbnailPath) | ||
196 | } | ||
197 | }) | ||
198 | |||
199 | it('Should the thumbnail when we delete the last element', async function () { | ||
200 | this.timeout(30000) | ||
201 | |||
202 | await servers[1].playlists.removeElement({ | ||
203 | playlistId: playlistWithoutThumbnailId, | ||
204 | elementId: withoutThumbnailE2 | ||
205 | }) | ||
206 | |||
207 | await waitJobs(servers) | ||
208 | |||
209 | for (const server of servers) { | ||
210 | const p = await getPlaylistWithoutThumbnail(server) | ||
211 | expect(p.thumbnailPath).to.be.null | ||
212 | } | ||
213 | }) | ||
214 | |||
215 | it('Should not update the thumbnail when we delete the last element if we explicitly uploaded a thumbnail', async function () { | ||
216 | this.timeout(30000) | ||
217 | |||
218 | await servers[1].playlists.removeElement({ | ||
219 | playlistId: playlistWithThumbnailId, | ||
220 | elementId: withThumbnailE2 | ||
221 | }) | ||
222 | |||
223 | await waitJobs(servers) | ||
224 | |||
225 | for (const server of servers) { | ||
226 | const p = await getPlaylistWithThumbnail(server) | ||
227 | await testImageGeneratedByFFmpeg(server.url, 'custom-thumbnail', p.thumbnailPath) | ||
228 | } | ||
229 | }) | ||
230 | |||
231 | after(async function () { | ||
232 | await cleanupTests(servers) | ||
233 | }) | ||
234 | }) | ||