2021-02-16 04:19:09 -05:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
|
|
|
|
|
|
|
import 'mocha'
|
2021-07-16 08:27:30 -04:00
|
|
|
import { expect } from 'chai'
|
2021-02-16 04:19:09 -05:00
|
|
|
import { readFile, remove } from 'fs-extra'
|
|
|
|
import { join } from 'path'
|
|
|
|
import { processImage } from '../../../server/helpers/image-utils'
|
2021-12-17 03:29:23 -05:00
|
|
|
import { buildAbsoluteFixturePath, root } from '../../../shared/server-commands'
|
2021-02-16 04:19:09 -05:00
|
|
|
|
|
|
|
async function checkBuffers (path1: string, path2: string, equals: boolean) {
|
|
|
|
const [ buf1, buf2 ] = await Promise.all([
|
|
|
|
readFile(path1),
|
|
|
|
readFile(path2)
|
|
|
|
])
|
|
|
|
|
|
|
|
if (equals) {
|
|
|
|
expect(buf1.equals(buf2)).to.be.true
|
|
|
|
} else {
|
|
|
|
expect(buf1.equals(buf2)).to.be.false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('Image helpers', function () {
|
|
|
|
const imageDestDir = join(root(), 'test-images')
|
|
|
|
const imageDest = join(imageDestDir, 'test.jpg')
|
|
|
|
const thumbnailSize = { width: 223, height: 122 }
|
|
|
|
|
|
|
|
it('Should skip processing if the source image is okay', async function () {
|
|
|
|
const input = buildAbsoluteFixturePath('thumbnail.jpg')
|
|
|
|
await processImage(input, imageDest, thumbnailSize, true)
|
|
|
|
|
|
|
|
await checkBuffers(input, imageDest, true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not skip processing if the source image does not have the appropriate extension', async function () {
|
|
|
|
const input = buildAbsoluteFixturePath('thumbnail.png')
|
|
|
|
await processImage(input, imageDest, thumbnailSize, true)
|
|
|
|
|
|
|
|
await checkBuffers(input, imageDest, false)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not skip processing if the source image does not have the appropriate size', async function () {
|
|
|
|
const input = buildAbsoluteFixturePath('preview.jpg')
|
|
|
|
await processImage(input, imageDest, thumbnailSize, true)
|
|
|
|
|
|
|
|
await checkBuffers(input, imageDest, false)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not skip processing if the source image does not have the appropriate size', async function () {
|
|
|
|
const input = buildAbsoluteFixturePath('thumbnail-big.jpg')
|
|
|
|
await processImage(input, imageDest, thumbnailSize, true)
|
|
|
|
|
|
|
|
await checkBuffers(input, imageDest, false)
|
|
|
|
})
|
|
|
|
|
|
|
|
after(async function () {
|
|
|
|
await remove(imageDest)
|
|
|
|
})
|
|
|
|
})
|