Files
omnivore/packages/thumbnail-handler/test/index.test.ts
2023-06-07 10:45:46 +08:00

31 lines
873 B
TypeScript

import { expect } from 'chai'
import fs from 'fs'
import 'mocha'
import nock from 'nock'
import path from 'path'
import { findThumbnail } from '../src'
describe('findThumbnail', () => {
it('finds the largest and squarest image', async () => {
const images = ['large_and_square', 'small', 'sprite', 'wide']
// mock getting image by url
images.forEach((image) => {
nock('https://omnivore.app')
.get(`/${image}.png`)
.replyWithFile(200, path.join(__dirname, 'fixtures', `${image}.png`))
})
// get html content from file
const content = fs.readFileSync(
path.join(__dirname, 'fixtures', 'findThumbnail.html'),
'utf8'
)
// find thumbnail
const thumbnail = await findThumbnail(content)
expect(thumbnail).to.eql('https://omnivore.app/large_and_square.png')
// clean up
nock.cleanAll()
})
})