aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/helpers/image.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-02-16 10:19:09 +0100
committerChocobozzz <chocobozzz@cpy.re>2021-02-16 10:36:44 +0100
commit1664bc60eb7aa3fa3792b6acff50f9bbabd3d877 (patch)
tree2434f642c2a7e895317bf791500dd181cd8f18c7 /server/tests/helpers/image.ts
parent374b725df52d941af1cf37cf211593340c05206c (diff)
downloadPeerTube-1664bc60eb7aa3fa3792b6acff50f9bbabd3d877.tar.gz
PeerTube-1664bc60eb7aa3fa3792b6acff50f9bbabd3d877.tar.zst
PeerTube-1664bc60eb7aa3fa3792b6acff50f9bbabd3d877.zip
Optimize remote image processing
Diffstat (limited to 'server/tests/helpers/image.ts')
-rw-r--r--server/tests/helpers/image.ts59
1 files changed, 59 insertions, 0 deletions
diff --git a/server/tests/helpers/image.ts b/server/tests/helpers/image.ts
new file mode 100644
index 000000000..54911697f
--- /dev/null
+++ b/server/tests/helpers/image.ts
@@ -0,0 +1,59 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import { readFile, remove } from 'fs-extra'
5import { join } from 'path'
6import { processImage } from '../../../server/helpers/image-utils'
7import { buildAbsoluteFixturePath, root } from '../../../shared/extra-utils'
8import { expect } from 'chai'
9
10async 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
23describe('Image helpers', function () {
24 const imageDestDir = join(root(), 'test-images')
25 const imageDest = join(imageDestDir, 'test.jpg')
26 const thumbnailSize = { width: 223, height: 122 }
27
28 it('Should skip processing if the source image is okay', async function () {
29 const input = buildAbsoluteFixturePath('thumbnail.jpg')
30 await processImage(input, imageDest, thumbnailSize, true)
31
32 await checkBuffers(input, imageDest, true)
33 })
34
35 it('Should not skip processing if the source image does not have the appropriate extension', async function () {
36 const input = buildAbsoluteFixturePath('thumbnail.png')
37 await processImage(input, imageDest, thumbnailSize, true)
38
39 await checkBuffers(input, imageDest, false)
40 })
41
42 it('Should not skip processing if the source image does not have the appropriate size', async function () {
43 const input = buildAbsoluteFixturePath('preview.jpg')
44 await processImage(input, imageDest, thumbnailSize, true)
45
46 await checkBuffers(input, imageDest, false)
47 })
48
49 it('Should not skip processing if the source image does not have the appropriate size', async function () {
50 const input = buildAbsoluteFixturePath('thumbnail-big.jpg')
51 await processImage(input, imageDest, thumbnailSize, true)
52
53 await checkBuffers(input, imageDest, false)
54 })
55
56 after(async function () {
57 await remove(imageDest)
58 })
59})