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/lib | |
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/lib')
-rw-r--r-- | server/tests/lib/index.ts | 1 | ||||
-rw-r--r-- | server/tests/lib/video-constant-registry-factory.ts | 154 |
2 files changed, 0 insertions, 155 deletions
diff --git a/server/tests/lib/index.ts b/server/tests/lib/index.ts deleted file mode 100644 index a40df35fd..000000000 --- a/server/tests/lib/index.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export * from './video-constant-registry-factory' | ||
diff --git a/server/tests/lib/video-constant-registry-factory.ts b/server/tests/lib/video-constant-registry-factory.ts deleted file mode 100644 index c3480dc12..000000000 --- a/server/tests/lib/video-constant-registry-factory.ts +++ /dev/null | |||
@@ -1,154 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions */ | ||
2 | import { expect } from 'chai' | ||
3 | import { VideoConstantManagerFactory } from '@server/lib/plugins/video-constant-manager-factory' | ||
4 | import { | ||
5 | VIDEO_CATEGORIES, | ||
6 | VIDEO_LANGUAGES, | ||
7 | VIDEO_LICENCES, | ||
8 | VIDEO_PLAYLIST_PRIVACIES, | ||
9 | VIDEO_PRIVACIES | ||
10 | } from '@server/initializers/constants' | ||
11 | import { | ||
12 | VideoPlaylistPrivacy, | ||
13 | VideoPrivacy | ||
14 | } from '@shared/models' | ||
15 | |||
16 | describe('VideoConstantManagerFactory', function () { | ||
17 | const factory = new VideoConstantManagerFactory('peertube-plugin-constants') | ||
18 | |||
19 | afterEach(() => { | ||
20 | factory.resetVideoConstants('peertube-plugin-constants') | ||
21 | }) | ||
22 | |||
23 | describe('VideoCategoryManager', () => { | ||
24 | const videoCategoryManager = factory.createVideoConstantManager<number>('category') | ||
25 | |||
26 | it('Should be able to list all video category constants', () => { | ||
27 | const constants = videoCategoryManager.getConstants() | ||
28 | expect(constants).to.deep.equal(VIDEO_CATEGORIES) | ||
29 | }) | ||
30 | |||
31 | it('Should be able to delete a video category constant', () => { | ||
32 | const successfullyDeleted = videoCategoryManager.deleteConstant(1) | ||
33 | expect(successfullyDeleted).to.be.true | ||
34 | expect(videoCategoryManager.getConstantValue(1)).to.be.undefined | ||
35 | }) | ||
36 | |||
37 | it('Should be able to add a video category constant', () => { | ||
38 | const successfullyAdded = videoCategoryManager.addConstant(42, 'The meaning of life') | ||
39 | expect(successfullyAdded).to.be.true | ||
40 | expect(videoCategoryManager.getConstantValue(42)).to.equal('The meaning of life') | ||
41 | }) | ||
42 | |||
43 | it('Should be able to reset video category constants', () => { | ||
44 | videoCategoryManager.deleteConstant(1) | ||
45 | videoCategoryManager.resetConstants() | ||
46 | expect(videoCategoryManager.getConstantValue(1)).not.be.undefined | ||
47 | }) | ||
48 | }) | ||
49 | |||
50 | describe('VideoLicenceManager', () => { | ||
51 | const videoLicenceManager = factory.createVideoConstantManager<number>('licence') | ||
52 | it('Should be able to list all video licence constants', () => { | ||
53 | const constants = videoLicenceManager.getConstants() | ||
54 | expect(constants).to.deep.equal(VIDEO_LICENCES) | ||
55 | }) | ||
56 | |||
57 | it('Should be able to delete a video licence constant', () => { | ||
58 | const successfullyDeleted = videoLicenceManager.deleteConstant(1) | ||
59 | expect(successfullyDeleted).to.be.true | ||
60 | expect(videoLicenceManager.getConstantValue(1)).to.be.undefined | ||
61 | }) | ||
62 | |||
63 | it('Should be able to add a video licence constant', () => { | ||
64 | const successfullyAdded = videoLicenceManager.addConstant(42, 'European Union Public Licence') | ||
65 | expect(successfullyAdded).to.be.true | ||
66 | expect(videoLicenceManager.getConstantValue(42 as any)).to.equal('European Union Public Licence') | ||
67 | }) | ||
68 | |||
69 | it('Should be able to reset video licence constants', () => { | ||
70 | videoLicenceManager.deleteConstant(1) | ||
71 | videoLicenceManager.resetConstants() | ||
72 | expect(videoLicenceManager.getConstantValue(1)).not.be.undefined | ||
73 | }) | ||
74 | }) | ||
75 | |||
76 | describe('PlaylistPrivacyManager', () => { | ||
77 | const playlistPrivacyManager = factory.createVideoConstantManager<VideoPlaylistPrivacy>('playlistPrivacy') | ||
78 | it('Should be able to list all video playlist privacy constants', () => { | ||
79 | const constants = playlistPrivacyManager.getConstants() | ||
80 | expect(constants).to.deep.equal(VIDEO_PLAYLIST_PRIVACIES) | ||
81 | }) | ||
82 | |||
83 | it('Should be able to delete a video playlist privacy constant', () => { | ||
84 | const successfullyDeleted = playlistPrivacyManager.deleteConstant(1) | ||
85 | expect(successfullyDeleted).to.be.true | ||
86 | expect(playlistPrivacyManager.getConstantValue(1)).to.be.undefined | ||
87 | }) | ||
88 | |||
89 | it('Should be able to add a video playlist privacy constant', () => { | ||
90 | const successfullyAdded = playlistPrivacyManager.addConstant(42 as any, 'Friends only') | ||
91 | expect(successfullyAdded).to.be.true | ||
92 | expect(playlistPrivacyManager.getConstantValue(42 as any)).to.equal('Friends only') | ||
93 | }) | ||
94 | |||
95 | it('Should be able to reset video playlist privacy constants', () => { | ||
96 | playlistPrivacyManager.deleteConstant(1) | ||
97 | playlistPrivacyManager.resetConstants() | ||
98 | expect(playlistPrivacyManager.getConstantValue(1)).not.be.undefined | ||
99 | }) | ||
100 | }) | ||
101 | |||
102 | describe('VideoPrivacyManager', () => { | ||
103 | const videoPrivacyManager = factory.createVideoConstantManager<VideoPrivacy>('privacy') | ||
104 | it('Should be able to list all video privacy constants', () => { | ||
105 | const constants = videoPrivacyManager.getConstants() | ||
106 | expect(constants).to.deep.equal(VIDEO_PRIVACIES) | ||
107 | }) | ||
108 | |||
109 | it('Should be able to delete a video privacy constant', () => { | ||
110 | const successfullyDeleted = videoPrivacyManager.deleteConstant(1) | ||
111 | expect(successfullyDeleted).to.be.true | ||
112 | expect(videoPrivacyManager.getConstantValue(1)).to.be.undefined | ||
113 | }) | ||
114 | |||
115 | it('Should be able to add a video privacy constant', () => { | ||
116 | const successfullyAdded = videoPrivacyManager.addConstant(42 as any, 'Friends only') | ||
117 | expect(successfullyAdded).to.be.true | ||
118 | expect(videoPrivacyManager.getConstantValue(42 as any)).to.equal('Friends only') | ||
119 | }) | ||
120 | |||
121 | it('Should be able to reset video privacy constants', () => { | ||
122 | videoPrivacyManager.deleteConstant(1) | ||
123 | videoPrivacyManager.resetConstants() | ||
124 | expect(videoPrivacyManager.getConstantValue(1)).not.be.undefined | ||
125 | }) | ||
126 | }) | ||
127 | |||
128 | describe('VideoLanguageManager', () => { | ||
129 | const videoLanguageManager = factory.createVideoConstantManager<string>('language') | ||
130 | it('Should be able to list all video language constants', () => { | ||
131 | const constants = videoLanguageManager.getConstants() | ||
132 | expect(constants).to.deep.equal(VIDEO_LANGUAGES) | ||
133 | }) | ||
134 | |||
135 | it('Should be able to add a video language constant', () => { | ||
136 | const successfullyAdded = videoLanguageManager.addConstant('fr', 'Fr occitan') | ||
137 | expect(successfullyAdded).to.be.true | ||
138 | expect(videoLanguageManager.getConstantValue('fr')).to.equal('Fr occitan') | ||
139 | }) | ||
140 | |||
141 | it('Should be able to delete a video language constant', () => { | ||
142 | videoLanguageManager.addConstant('fr', 'Fr occitan') | ||
143 | const successfullyDeleted = videoLanguageManager.deleteConstant('fr') | ||
144 | expect(successfullyDeleted).to.be.true | ||
145 | expect(videoLanguageManager.getConstantValue('fr')).to.be.undefined | ||
146 | }) | ||
147 | |||
148 | it('Should be able to reset video language constants', () => { | ||
149 | videoLanguageManager.addConstant('fr', 'Fr occitan') | ||
150 | videoLanguageManager.resetConstants() | ||
151 | expect(videoLanguageManager.getConstantValue('fr')).to.be.undefined | ||
152 | }) | ||
153 | }) | ||
154 | }) | ||