aboutsummaryrefslogtreecommitdiffhomepage
path: root/packages/tests/src/cli/update-host.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 /packages/tests/src/cli/update-host.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 'packages/tests/src/cli/update-host.ts')
-rw-r--r--packages/tests/src/cli/update-host.ts134
1 files changed, 134 insertions, 0 deletions
diff --git a/packages/tests/src/cli/update-host.ts b/packages/tests/src/cli/update-host.ts
new file mode 100644
index 000000000..e5f165e5e
--- /dev/null
+++ b/packages/tests/src/cli/update-host.ts
@@ -0,0 +1,134 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { expect } from 'chai'
4import { getAllFiles } from '@peertube/peertube-core-utils'
5import {
6 cleanupTests,
7 createSingleServer,
8 killallServers,
9 makeActivityPubGetRequest,
10 PeerTubeServer,
11 setAccessTokensToServers,
12 waitJobs
13} from '@peertube/peertube-server-commands'
14import { parseTorrentVideo } from '@tests/shared/webtorrent.js'
15
16describe('Test update host scripts', function () {
17 let server: PeerTubeServer
18
19 before(async function () {
20 this.timeout(60000)
21
22 const overrideConfig = {
23 webserver: {
24 port: 9256
25 }
26 }
27 // Run server 2 to have transcoding enabled
28 server = await createSingleServer(2, overrideConfig)
29 await setAccessTokensToServers([ server ])
30
31 // Upload two videos for our needs
32 const { uuid: video1UUID } = await server.videos.upload()
33 await server.videos.upload()
34
35 // Create a user
36 await server.users.create({ username: 'toto', password: 'coucou' })
37
38 // Create channel
39 const videoChannel = {
40 name: 'second_channel',
41 displayName: 'second video channel',
42 description: 'super video channel description'
43 }
44 await server.channels.create({ attributes: videoChannel })
45
46 // Create comments
47 const text = 'my super first comment'
48 await server.comments.createThread({ videoId: video1UUID, text })
49
50 await waitJobs(server)
51 })
52
53 it('Should run update host', async function () {
54 this.timeout(30000)
55
56 await killallServers([ server ])
57 // Run server with standard configuration
58 await server.run()
59
60 await server.cli.execWithEnv(`npm run update-host`)
61 })
62
63 it('Should have updated videos url', async function () {
64 const { total, data } = await server.videos.list()
65 expect(total).to.equal(2)
66
67 for (const video of data) {
68 const { body } = await makeActivityPubGetRequest(server.url, '/videos/watch/' + video.uuid)
69
70 expect(body.id).to.equal('http://127.0.0.1:9002/videos/watch/' + video.uuid)
71
72 const videoDetails = await server.videos.get({ id: video.uuid })
73
74 expect(videoDetails.trackerUrls[0]).to.include(server.host)
75 expect(videoDetails.streamingPlaylists[0].playlistUrl).to.include(server.host)
76 expect(videoDetails.streamingPlaylists[0].segmentsSha256Url).to.include(server.host)
77 }
78 })
79
80 it('Should have updated video channels url', async function () {
81 const { data, total } = await server.channels.list({ sort: '-name' })
82 expect(total).to.equal(3)
83
84 for (const channel of data) {
85 const { body } = await makeActivityPubGetRequest(server.url, '/video-channels/' + channel.name)
86
87 expect(body.id).to.equal('http://127.0.0.1:9002/video-channels/' + channel.name)
88 }
89 })
90
91 it('Should have updated accounts url', async function () {
92 const body = await server.accounts.list()
93 expect(body.total).to.equal(3)
94
95 for (const account of body.data) {
96 const usernameWithDomain = account.name
97 const { body } = await makeActivityPubGetRequest(server.url, '/accounts/' + usernameWithDomain)
98
99 expect(body.id).to.equal('http://127.0.0.1:9002/accounts/' + usernameWithDomain)
100 }
101 })
102
103 it('Should have updated torrent hosts', async function () {
104 this.timeout(30000)
105
106 const { data } = await server.videos.list()
107 expect(data).to.have.lengthOf(2)
108
109 for (const video of data) {
110 const videoDetails = await server.videos.get({ id: video.id })
111 const files = getAllFiles(videoDetails)
112
113 expect(files).to.have.lengthOf(8)
114
115 for (const file of files) {
116 expect(file.magnetUri).to.contain('127.0.0.1%3A9002%2Ftracker%2Fsocket')
117 expect(file.magnetUri).to.contain('127.0.0.1%3A9002%2Fstatic%2F')
118
119 const torrent = await parseTorrentVideo(server, file)
120 const announceWS = torrent.announce.find(a => a === 'ws://127.0.0.1:9002/tracker/socket')
121 expect(announceWS).to.not.be.undefined
122
123 const announceHttp = torrent.announce.find(a => a === 'http://127.0.0.1:9002/tracker/announce')
124 expect(announceHttp).to.not.be.undefined
125
126 expect(torrent.urlList[0]).to.contain('http://127.0.0.1:9002/static/')
127 }
128 }
129 })
130
131 after(async function () {
132 await cleanupTests([ server ])
133 })
134})