1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { expect } from 'chai'
5 import { readFile, remove } from 'fs-extra'
6 import { join } from 'path'
7 import { processImage } from '../../../server/helpers/image-utils'
8 import { buildAbsoluteFixturePath, root } from '../../../shared/extra-utils'
10 async function checkBuffers (path1: string, path2: string, equals: boolean) {
11 const [ buf1, buf2 ] = await Promise.all([
17 expect(buf1.equals(buf2)).to.be.true
19 expect(buf1.equals(buf2)).to.be.false
23 describe('Image helpers', function () {
24 const imageDestDir = join(root(), 'test-images')
25 const imageDest = join(imageDestDir, 'test.jpg')
26 const thumbnailSize = { width: 223, height: 122 }
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)
32 await checkBuffers(input, imageDest, true)
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)
39 await checkBuffers(input, imageDest, false)
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)
46 await checkBuffers(input, imageDest, false)
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)
53 await checkBuffers(input, imageDest, false)
56 after(async function () {
57 await remove(imageDest)