aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/videos/video-captions.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/videos/video-captions.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/videos/video-captions.ts')
-rw-r--r--server/tests/api/videos/video-captions.ts188
1 files changed, 0 insertions, 188 deletions
diff --git a/server/tests/api/videos/video-captions.ts b/server/tests/api/videos/video-captions.ts
deleted file mode 100644
index 0630c9d3a..000000000
--- a/server/tests/api/videos/video-captions.ts
+++ /dev/null
@@ -1,188 +0,0 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { expect } from 'chai'
4import { checkVideoFilesWereRemoved, testCaptionFile } from '@server/tests/shared'
5import { wait } from '@shared/core-utils'
6import {
7 cleanupTests,
8 createMultipleServers,
9 doubleFollow,
10 PeerTubeServer,
11 setAccessTokensToServers,
12 waitJobs
13} from '@shared/server-commands'
14
15describe('Test video captions', function () {
16 const uuidRegex = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
17
18 let servers: PeerTubeServer[]
19 let videoUUID: string
20
21 before(async function () {
22 this.timeout(60000)
23
24 servers = await createMultipleServers(2)
25
26 await setAccessTokensToServers(servers)
27 await doubleFollow(servers[0], servers[1])
28
29 await waitJobs(servers)
30
31 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'my video name' } })
32 videoUUID = uuid
33
34 await waitJobs(servers)
35 })
36
37 it('Should list the captions and return an empty list', async function () {
38 for (const server of servers) {
39 const body = await server.captions.list({ videoId: videoUUID })
40 expect(body.total).to.equal(0)
41 expect(body.data).to.have.lengthOf(0)
42 }
43 })
44
45 it('Should create two new captions', async function () {
46 this.timeout(30000)
47
48 await servers[0].captions.add({
49 language: 'ar',
50 videoId: videoUUID,
51 fixture: 'subtitle-good1.vtt'
52 })
53
54 await servers[0].captions.add({
55 language: 'zh',
56 videoId: videoUUID,
57 fixture: 'subtitle-good2.vtt',
58 mimeType: 'application/octet-stream'
59 })
60
61 await waitJobs(servers)
62 })
63
64 it('Should list these uploaded captions', async function () {
65 for (const server of servers) {
66 const body = await server.captions.list({ videoId: videoUUID })
67 expect(body.total).to.equal(2)
68 expect(body.data).to.have.lengthOf(2)
69
70 const caption1 = body.data[0]
71 expect(caption1.language.id).to.equal('ar')
72 expect(caption1.language.label).to.equal('Arabic')
73 expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$'))
74 await testCaptionFile(server.url, caption1.captionPath, 'Subtitle good 1.')
75
76 const caption2 = body.data[1]
77 expect(caption2.language.id).to.equal('zh')
78 expect(caption2.language.label).to.equal('Chinese')
79 expect(caption2.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-zh.vtt$'))
80 await testCaptionFile(server.url, caption2.captionPath, 'Subtitle good 2.')
81 }
82 })
83
84 it('Should replace an existing caption', async function () {
85 this.timeout(30000)
86
87 await servers[0].captions.add({
88 language: 'ar',
89 videoId: videoUUID,
90 fixture: 'subtitle-good2.vtt'
91 })
92
93 await waitJobs(servers)
94 })
95
96 it('Should have this caption updated', async function () {
97 for (const server of servers) {
98 const body = await server.captions.list({ videoId: videoUUID })
99 expect(body.total).to.equal(2)
100 expect(body.data).to.have.lengthOf(2)
101
102 const caption1 = body.data[0]
103 expect(caption1.language.id).to.equal('ar')
104 expect(caption1.language.label).to.equal('Arabic')
105 expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$'))
106 await testCaptionFile(server.url, caption1.captionPath, 'Subtitle good 2.')
107 }
108 })
109
110 it('Should replace an existing caption with a srt file and convert it', async function () {
111 this.timeout(30000)
112
113 await servers[0].captions.add({
114 language: 'ar',
115 videoId: videoUUID,
116 fixture: 'subtitle-good.srt'
117 })
118
119 await waitJobs(servers)
120
121 // Cache invalidation
122 await wait(3000)
123 })
124
125 it('Should have this caption updated and converted', async function () {
126 for (const server of servers) {
127 const body = await server.captions.list({ videoId: videoUUID })
128 expect(body.total).to.equal(2)
129 expect(body.data).to.have.lengthOf(2)
130
131 const caption1 = body.data[0]
132 expect(caption1.language.id).to.equal('ar')
133 expect(caption1.language.label).to.equal('Arabic')
134 expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$'))
135
136 const expected = 'WEBVTT FILE\r\n' +
137 '\r\n' +
138 '1\r\n' +
139 '00:00:01.600 --> 00:00:04.200\r\n' +
140 'English (US)\r\n' +
141 '\r\n' +
142 '2\r\n' +
143 '00:00:05.900 --> 00:00:07.999\r\n' +
144 'This is a subtitle in American English\r\n' +
145 '\r\n' +
146 '3\r\n' +
147 '00:00:10.000 --> 00:00:14.000\r\n' +
148 'Adding subtitles is very easy to do\r\n'
149 await testCaptionFile(server.url, caption1.captionPath, expected)
150 }
151 })
152
153 it('Should remove one caption', async function () {
154 this.timeout(30000)
155
156 await servers[0].captions.delete({ videoId: videoUUID, language: 'ar' })
157
158 await waitJobs(servers)
159 })
160
161 it('Should only list the caption that was not deleted', async function () {
162 for (const server of servers) {
163 const body = await server.captions.list({ videoId: videoUUID })
164 expect(body.total).to.equal(1)
165 expect(body.data).to.have.lengthOf(1)
166
167 const caption = body.data[0]
168
169 expect(caption.language.id).to.equal('zh')
170 expect(caption.language.label).to.equal('Chinese')
171 expect(caption.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-zh.vtt$'))
172 await testCaptionFile(server.url, caption.captionPath, 'Subtitle good 2.')
173 }
174 })
175
176 it('Should remove the video, and thus all video captions', async function () {
177 const video = await servers[0].videos.get({ id: videoUUID })
178 const { data: captions } = await servers[0].captions.list({ videoId: videoUUID })
179
180 await servers[0].videos.remove({ id: videoUUID })
181
182 await checkVideoFilesWereRemoved({ server: servers[0], video, captions })
183 })
184
185 after(async function () {
186 await cleanupTests(servers)
187 })
188})