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-storage.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-storage.ts')
-rw-r--r-- | server/tests/plugins/plugin-storage.ts | 94 |
1 files changed, 0 insertions, 94 deletions
diff --git a/server/tests/plugins/plugin-storage.ts b/server/tests/plugins/plugin-storage.ts deleted file mode 100644 index 112652a1f..000000000 --- a/server/tests/plugins/plugin-storage.ts +++ /dev/null | |||
@@ -1,94 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { pathExists, readdir, readFile } from 'fs-extra' | ||
5 | import { join } from 'path' | ||
6 | import { | ||
7 | cleanupTests, | ||
8 | createSingleServer, | ||
9 | makeGetRequest, | ||
10 | PeerTubeServer, | ||
11 | PluginsCommand, | ||
12 | setAccessTokensToServers | ||
13 | } from '@shared/server-commands' | ||
14 | import { HttpStatusCode } from '@shared/models' | ||
15 | |||
16 | describe('Test plugin storage', function () { | ||
17 | let server: PeerTubeServer | ||
18 | |||
19 | before(async function () { | ||
20 | this.timeout(30000) | ||
21 | |||
22 | server = await createSingleServer(1) | ||
23 | await setAccessTokensToServers([ server ]) | ||
24 | |||
25 | await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-six') }) | ||
26 | }) | ||
27 | |||
28 | describe('DB storage', function () { | ||
29 | it('Should correctly store a subkey', async function () { | ||
30 | await server.servers.waitUntilLog('superkey stored value is toto') | ||
31 | }) | ||
32 | |||
33 | it('Should correctly retrieve an array as array from the storage.', async function () { | ||
34 | await server.servers.waitUntilLog('storedArrayKey isArray is true') | ||
35 | await server.servers.waitUntilLog('storedArrayKey stored value is toto, toto2') | ||
36 | }) | ||
37 | }) | ||
38 | |||
39 | describe('Disk storage', function () { | ||
40 | let dataPath: string | ||
41 | let pluginDataPath: string | ||
42 | |||
43 | async function getFileContent () { | ||
44 | const files = await readdir(pluginDataPath) | ||
45 | expect(files).to.have.lengthOf(1) | ||
46 | |||
47 | return readFile(join(pluginDataPath, files[0]), 'utf8') | ||
48 | } | ||
49 | |||
50 | before(function () { | ||
51 | dataPath = server.servers.buildDirectory('plugins/data') | ||
52 | pluginDataPath = join(dataPath, 'peertube-plugin-test-six') | ||
53 | }) | ||
54 | |||
55 | it('Should have created the directory on install', async function () { | ||
56 | const dataPath = server.servers.buildDirectory('plugins/data') | ||
57 | const pluginDataPath = join(dataPath, 'peertube-plugin-test-six') | ||
58 | |||
59 | expect(await pathExists(dataPath)).to.be.true | ||
60 | expect(await pathExists(pluginDataPath)).to.be.true | ||
61 | expect(await readdir(pluginDataPath)).to.have.lengthOf(0) | ||
62 | }) | ||
63 | |||
64 | it('Should have created a file', async function () { | ||
65 | await makeGetRequest({ | ||
66 | url: server.url, | ||
67 | token: server.accessToken, | ||
68 | path: '/plugins/test-six/router/create-file', | ||
69 | expectedStatus: HttpStatusCode.OK_200 | ||
70 | }) | ||
71 | |||
72 | const content = await getFileContent() | ||
73 | expect(content).to.equal('Prince Ali') | ||
74 | }) | ||
75 | |||
76 | it('Should still have the file after an uninstallation', async function () { | ||
77 | await server.plugins.uninstall({ npmName: 'peertube-plugin-test-six' }) | ||
78 | |||
79 | const content = await getFileContent() | ||
80 | expect(content).to.equal('Prince Ali') | ||
81 | }) | ||
82 | |||
83 | it('Should still have the file after the reinstallation', async function () { | ||
84 | await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-six') }) | ||
85 | |||
86 | const content = await getFileContent() | ||
87 | expect(content).to.equal('Prince Ali') | ||
88 | }) | ||
89 | }) | ||
90 | |||
91 | after(async function () { | ||
92 | await cleanupTests([ server ]) | ||
93 | }) | ||
94 | }) | ||