]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/helpers/image.ts
Install git in docker image
[github/Chocobozzz/PeerTube.git] / server / tests / helpers / image.ts
CommitLineData
1664bc60
C
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4c7e60bc 4import { expect } from 'chai'
1664bc60
C
5import { readFile, remove } from 'fs-extra'
6import { join } from 'path'
c55e3d72 7import { buildAbsoluteFixturePath, root } from '@shared/core-utils'
1664bc60 8import { processImage } from '../../../server/helpers/image-utils'
1664bc60
C
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})