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/helpers/image.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/helpers/image.ts')
-rw-r--r-- | server/tests/helpers/image.ts | 96 |
1 files changed, 0 insertions, 96 deletions
diff --git a/server/tests/helpers/image.ts b/server/tests/helpers/image.ts deleted file mode 100644 index 6021ffc48..000000000 --- a/server/tests/helpers/image.ts +++ /dev/null | |||
@@ -1,96 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { readFile, remove } from 'fs-extra' | ||
5 | import { join } from 'path' | ||
6 | import { execPromise } from '@server/helpers/core-utils' | ||
7 | import { buildAbsoluteFixturePath, root } from '@shared/core-utils' | ||
8 | import { processImage } from '../../../server/helpers/image-utils' | ||
9 | |||
10 | async function checkBuffers (path1: string, path2: string, equals: boolean) { | ||
11 | const [ buf1, buf2 ] = await Promise.all([ | ||
12 | readFile(path1), | ||
13 | readFile(path2) | ||
14 | ]) | ||
15 | |||
16 | if (equals) { | ||
17 | expect(buf1.equals(buf2)).to.be.true | ||
18 | } else { | ||
19 | expect(buf1.equals(buf2)).to.be.false | ||
20 | } | ||
21 | } | ||
22 | |||
23 | async function hasTitleExif (path: string) { | ||
24 | const result = JSON.parse(await execPromise(`exiftool -json ${path}`)) | ||
25 | |||
26 | return result[0]?.Title === 'should be removed' | ||
27 | } | ||
28 | |||
29 | describe('Image helpers', function () { | ||
30 | const imageDestDir = join(root(), 'test-images') | ||
31 | |||
32 | const imageDestJPG = join(imageDestDir, 'test.jpg') | ||
33 | const imageDestPNG = join(imageDestDir, 'test.png') | ||
34 | |||
35 | const thumbnailSize = { width: 280, height: 157 } | ||
36 | |||
37 | it('Should skip processing if the source image is okay', async function () { | ||
38 | const input = buildAbsoluteFixturePath('custom-thumbnail.jpg') | ||
39 | await processImage({ path: input, destination: imageDestJPG, newSize: thumbnailSize, keepOriginal: true }) | ||
40 | |||
41 | await checkBuffers(input, imageDestJPG, true) | ||
42 | }) | ||
43 | |||
44 | it('Should not skip processing if the source image does not have the appropriate extension', async function () { | ||
45 | const input = buildAbsoluteFixturePath('custom-thumbnail.png') | ||
46 | await processImage({ path: input, destination: imageDestJPG, newSize: thumbnailSize, keepOriginal: true }) | ||
47 | |||
48 | await checkBuffers(input, imageDestJPG, false) | ||
49 | }) | ||
50 | |||
51 | it('Should not skip processing if the source image does not have the appropriate size', async function () { | ||
52 | const input = buildAbsoluteFixturePath('custom-preview.jpg') | ||
53 | await processImage({ path: input, destination: imageDestJPG, newSize: thumbnailSize, keepOriginal: true }) | ||
54 | |||
55 | await checkBuffers(input, imageDestJPG, false) | ||
56 | }) | ||
57 | |||
58 | it('Should not skip processing if the source image does not have the appropriate size', async function () { | ||
59 | const input = buildAbsoluteFixturePath('custom-thumbnail-big.jpg') | ||
60 | await processImage({ path: input, destination: imageDestJPG, newSize: thumbnailSize, keepOriginal: true }) | ||
61 | |||
62 | await checkBuffers(input, imageDestJPG, false) | ||
63 | }) | ||
64 | |||
65 | it('Should strip exif for a jpg file that can not be copied', async function () { | ||
66 | const input = buildAbsoluteFixturePath('exif.jpg') | ||
67 | expect(await hasTitleExif(input)).to.be.true | ||
68 | |||
69 | await processImage({ path: input, destination: imageDestJPG, newSize: { width: 100, height: 100 }, keepOriginal: true }) | ||
70 | await checkBuffers(input, imageDestJPG, false) | ||
71 | |||
72 | expect(await hasTitleExif(imageDestJPG)).to.be.false | ||
73 | }) | ||
74 | |||
75 | it('Should strip exif for a jpg file that could be copied', async function () { | ||
76 | const input = buildAbsoluteFixturePath('exif.jpg') | ||
77 | expect(await hasTitleExif(input)).to.be.true | ||
78 | |||
79 | await processImage({ path: input, destination: imageDestJPG, newSize: thumbnailSize, keepOriginal: true }) | ||
80 | await checkBuffers(input, imageDestJPG, false) | ||
81 | |||
82 | expect(await hasTitleExif(imageDestJPG)).to.be.false | ||
83 | }) | ||
84 | |||
85 | it('Should strip exif for png', async function () { | ||
86 | const input = buildAbsoluteFixturePath('exif.png') | ||
87 | expect(await hasTitleExif(input)).to.be.true | ||
88 | |||
89 | await processImage({ path: input, destination: imageDestPNG, newSize: thumbnailSize, keepOriginal: true }) | ||
90 | expect(await hasTitleExif(imageDestPNG)).to.be.false | ||
91 | }) | ||
92 | |||
93 | after(async function () { | ||
94 | await remove(imageDestDir) | ||
95 | }) | ||
96 | }) | ||