add testcases

This commit is contained in:
Hongbo Wu
2023-06-07 10:45:46 +08:00
parent 45609335b6
commit d194709b0e
9 changed files with 45 additions and 11 deletions

View File

@ -0,0 +1,9 @@
<DIV class="page" id="readability-page-1">
<img src="https://omnivore.app/small.png" alt="small image" />
<img src="https://omnivore.app/large_and_square.png" alt="large and square image" />
<img src="https://omnivore.app/wide.png" alt="wide image" />
<img src="https://omnivore.app/sprite.png" alt="sprite image" />
</DIV>

Binary file not shown.

After

Width:  |  Height:  |  Size: 117 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 872 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 117 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 174 KiB

View File

@ -0,0 +1,30 @@
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()
})
})

View File

@ -1,8 +0,0 @@
import 'mocha'
import { expect } from 'chai'
describe('stub test', () => {
it('should pass', () => {
expect(true).to.be.true
})
})