From 3a4992633ee62d5edfbb484d9c6bcb3cf158489d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 31 Jul 2023 14:34:36 +0200 Subject: 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) --- server/tests/plugins/plugin-storage.ts | 94 ---------------------------------- 1 file changed, 94 deletions(-) delete mode 100644 server/tests/plugins/plugin-storage.ts (limited to 'server/tests/plugins/plugin-storage.ts') 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 @@ -/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ - -import { expect } from 'chai' -import { pathExists, readdir, readFile } from 'fs-extra' -import { join } from 'path' -import { - cleanupTests, - createSingleServer, - makeGetRequest, - PeerTubeServer, - PluginsCommand, - setAccessTokensToServers -} from '@shared/server-commands' -import { HttpStatusCode } from '@shared/models' - -describe('Test plugin storage', function () { - let server: PeerTubeServer - - before(async function () { - this.timeout(30000) - - server = await createSingleServer(1) - await setAccessTokensToServers([ server ]) - - await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-six') }) - }) - - describe('DB storage', function () { - it('Should correctly store a subkey', async function () { - await server.servers.waitUntilLog('superkey stored value is toto') - }) - - it('Should correctly retrieve an array as array from the storage.', async function () { - await server.servers.waitUntilLog('storedArrayKey isArray is true') - await server.servers.waitUntilLog('storedArrayKey stored value is toto, toto2') - }) - }) - - describe('Disk storage', function () { - let dataPath: string - let pluginDataPath: string - - async function getFileContent () { - const files = await readdir(pluginDataPath) - expect(files).to.have.lengthOf(1) - - return readFile(join(pluginDataPath, files[0]), 'utf8') - } - - before(function () { - dataPath = server.servers.buildDirectory('plugins/data') - pluginDataPath = join(dataPath, 'peertube-plugin-test-six') - }) - - it('Should have created the directory on install', async function () { - const dataPath = server.servers.buildDirectory('plugins/data') - const pluginDataPath = join(dataPath, 'peertube-plugin-test-six') - - expect(await pathExists(dataPath)).to.be.true - expect(await pathExists(pluginDataPath)).to.be.true - expect(await readdir(pluginDataPath)).to.have.lengthOf(0) - }) - - it('Should have created a file', async function () { - await makeGetRequest({ - url: server.url, - token: server.accessToken, - path: '/plugins/test-six/router/create-file', - expectedStatus: HttpStatusCode.OK_200 - }) - - const content = await getFileContent() - expect(content).to.equal('Prince Ali') - }) - - it('Should still have the file after an uninstallation', async function () { - await server.plugins.uninstall({ npmName: 'peertube-plugin-test-six' }) - - const content = await getFileContent() - expect(content).to.equal('Prince Ali') - }) - - it('Should still have the file after the reinstallation', async function () { - await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-six') }) - - const content = await getFileContent() - expect(content).to.equal('Prince Ali') - }) - }) - - after(async function () { - await cleanupTests([ server ]) - }) -}) -- cgit v1.2.3