Files
omnivore/packages/thumbnail-handler/test/index.test.ts
Hongbo Wu a621ca24bf fix test
2023-06-14 20:07:17 +08:00

28 lines
836 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')
})
})