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/plugins/plugin-router.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/plugins/plugin-router.ts')
-rw-r--r-- | server/tests/plugins/plugin-router.ts | 105 |
1 files changed, 0 insertions, 105 deletions
diff --git a/server/tests/plugins/plugin-router.ts b/server/tests/plugins/plugin-router.ts deleted file mode 100644 index 40b15eb79..000000000 --- a/server/tests/plugins/plugin-router.ts +++ /dev/null | |||
@@ -1,105 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { | ||
5 | cleanupTests, | ||
6 | createSingleServer, | ||
7 | makeGetRequest, | ||
8 | makePostBodyRequest, | ||
9 | PeerTubeServer, | ||
10 | PluginsCommand, | ||
11 | setAccessTokensToServers | ||
12 | } from '@shared/server-commands' | ||
13 | import { HttpStatusCode } from '@shared/models' | ||
14 | |||
15 | describe('Test plugin helpers', function () { | ||
16 | let server: PeerTubeServer | ||
17 | const basePaths = [ | ||
18 | '/plugins/test-five/router/', | ||
19 | '/plugins/test-five/0.0.1/router/' | ||
20 | ] | ||
21 | |||
22 | before(async function () { | ||
23 | this.timeout(30000) | ||
24 | |||
25 | server = await createSingleServer(1) | ||
26 | await setAccessTokensToServers([ server ]) | ||
27 | |||
28 | await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-five') }) | ||
29 | }) | ||
30 | |||
31 | it('Should answer "pong"', async function () { | ||
32 | for (const path of basePaths) { | ||
33 | const res = await makeGetRequest({ | ||
34 | url: server.url, | ||
35 | path: path + 'ping', | ||
36 | expectedStatus: HttpStatusCode.OK_200 | ||
37 | }) | ||
38 | |||
39 | expect(res.body.message).to.equal('pong') | ||
40 | } | ||
41 | }) | ||
42 | |||
43 | it('Should check if authenticated', async function () { | ||
44 | for (const path of basePaths) { | ||
45 | const res = await makeGetRequest({ | ||
46 | url: server.url, | ||
47 | path: path + 'is-authenticated', | ||
48 | token: server.accessToken, | ||
49 | expectedStatus: 200 | ||
50 | }) | ||
51 | |||
52 | expect(res.body.isAuthenticated).to.equal(true) | ||
53 | |||
54 | const secRes = await makeGetRequest({ | ||
55 | url: server.url, | ||
56 | path: path + 'is-authenticated', | ||
57 | expectedStatus: 200 | ||
58 | }) | ||
59 | |||
60 | expect(secRes.body.isAuthenticated).to.equal(false) | ||
61 | } | ||
62 | }) | ||
63 | |||
64 | it('Should mirror post body', async function () { | ||
65 | const body = { | ||
66 | hello: 'world', | ||
67 | riri: 'fifi', | ||
68 | loulou: 'picsou' | ||
69 | } | ||
70 | |||
71 | for (const path of basePaths) { | ||
72 | const res = await makePostBodyRequest({ | ||
73 | url: server.url, | ||
74 | path: path + 'form/post/mirror', | ||
75 | fields: body, | ||
76 | expectedStatus: HttpStatusCode.OK_200 | ||
77 | }) | ||
78 | |||
79 | expect(res.body).to.deep.equal(body) | ||
80 | } | ||
81 | }) | ||
82 | |||
83 | it('Should remove the plugin and remove the routes', async function () { | ||
84 | await server.plugins.uninstall({ npmName: 'peertube-plugin-test-five' }) | ||
85 | |||
86 | for (const path of basePaths) { | ||
87 | await makeGetRequest({ | ||
88 | url: server.url, | ||
89 | path: path + 'ping', | ||
90 | expectedStatus: HttpStatusCode.NOT_FOUND_404 | ||
91 | }) | ||
92 | |||
93 | await makePostBodyRequest({ | ||
94 | url: server.url, | ||
95 | path: path + 'ping', | ||
96 | fields: {}, | ||
97 | expectedStatus: HttpStatusCode.NOT_FOUND_404 | ||
98 | }) | ||
99 | } | ||
100 | }) | ||
101 | |||
102 | after(async function () { | ||
103 | await cleanupTests([ server ]) | ||
104 | }) | ||
105 | }) | ||