Skip to content

Commit

Permalink
Add clearbit-logo tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Dec 17, 2017
1 parent eae7d9a commit 3e87ec4
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
exports['if logo is not present, fallback to clearbit logo API 1'] = {
"author": null,
"date": null,
"description": null,
"image": null,
"logo": "https://logo.clearbit.com/facebook.com?size=128&format=png",
"publisher": null,
"title": null,
"url": "https://facebook.com"
}

3 changes: 1 addition & 2 deletions packages/metascraper-clearbit-logo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ module.exports = opts => {

return {
logo: ({ htmlDom, meta, url: baseUrl }) => {
const { origin, hostname } = new URL(baseUrl)
if (meta.logo !== `${origin}/favicon.ico`) return
const { hostname } = new URL(baseUrl)
return `${ENDPOINT}/${hostname}?size=${size}&format=${format}`
}
}
Expand Down
6 changes: 5 additions & 1 deletion packages/metascraper-clearbit-logo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
"mocha": "latest",
"nyc": "latest",
"should": "latest",
"standard": "latest"
"snap-shot": "latest",
"standard": "latest",
"standard": "latest",
"metascraper": "latest",
"clear-module": "latest"
},
"engines": {
"node": ">= 8"
Expand Down
13 changes: 13 additions & 0 deletions packages/metascraper-clearbit-logo/test/.metascraperrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"rules": [
"metascraper-author",
"metascraper-date",
"metascraper-description",
"metascraper-image",
"metascraper-logo",
"metascraper-clearbit-logo",
"metascraper-publisher",
"metascraper-title",
"metascraper-url"
]
}
29 changes: 15 additions & 14 deletions packages/metascraper-clearbit-logo/test/index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
'use strict'

const should = require('should')

const clearbit = require('..')()
const clearModule = require('clear-module')
const snapshot = require('snap-shot')

describe('metascraper clearbit logo', () => {
it('if logo is present, not do nothing', () => {
const url = 'https://facebook.com'
const meta = { logo: 'https://facebook.com/logo.png' }
const data = clearbit.logo({ url, meta })
should(data).be.undefined()
before(() => {
clearModule.all()
process.env.METASCRAPER_CONFIG_CWD = __dirname
})

after(() => {
clearModule.all()
delete process.env.METASCRAPER_CONFIG_CWD
})

it('if logo is not present, fallback to clearbit logo API', () => {
it('if logo is not present, fallback to clearbit logo API', async () => {
const metascraper = require('metascraper')
const url = 'https://facebook.com'
const meta = { logo: 'https://facebook.com/favicon.ico' }
const data = clearbit.logo({ url, meta })
should(data).be.equal(
'https://logo.clearbit.com/facebook.com?size=128&format=png'
)
const html = '<div></div>'
const meta = await metascraper({ html, url })
snapshot(meta)
})
})

0 comments on commit 3e87ec4

Please sign in to comment.