add testcases
This commit is contained in:
9
packages/thumbnail-handler/test/fixtures/findThumbnail.html
vendored
Normal file
9
packages/thumbnail-handler/test/fixtures/findThumbnail.html
vendored
Normal 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>
|
||||
BIN
packages/thumbnail-handler/test/fixtures/large_and_square.png
vendored
Normal file
BIN
packages/thumbnail-handler/test/fixtures/large_and_square.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 117 KiB |
BIN
packages/thumbnail-handler/test/fixtures/small.png
vendored
Normal file
BIN
packages/thumbnail-handler/test/fixtures/small.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 872 B |
BIN
packages/thumbnail-handler/test/fixtures/sprite.png
vendored
Normal file
BIN
packages/thumbnail-handler/test/fixtures/sprite.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 117 KiB |
BIN
packages/thumbnail-handler/test/fixtures/wide.png
vendored
Normal file
BIN
packages/thumbnail-handler/test/fixtures/wide.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 174 KiB |
30
packages/thumbnail-handler/test/index.test.ts
Normal file
30
packages/thumbnail-handler/test/index.test.ts
Normal 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()
|
||||
})
|
||||
})
|
||||
@ -1,8 +0,0 @@
|
||||
import 'mocha'
|
||||
import { expect } from 'chai'
|
||||
|
||||
describe('stub test', () => {
|
||||
it('should pass', () => {
|
||||
expect(true).to.be.true
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user