-
-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(logo-favicon): granular control (#667)
- Loading branch information
Showing
11 changed files
with
180 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict' | ||
|
||
const test = require('ava') | ||
|
||
const { favicon } = require('..') | ||
|
||
test('with { contentType: \'image/vnd.microsoft.icon\' }', async t => { | ||
const url = 'https://microlink.io/' | ||
t.is(await favicon(url), 'https://microlink.io/favicon.ico') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict' | ||
|
||
const test = require('ava') | ||
|
||
const { createGetLogo } = require('..') | ||
|
||
test('serialize null correctly', async t => { | ||
const cache = new Map() | ||
const keyvOpts = { store: cache } | ||
const getLogo = createGetLogo({ | ||
keyvOpts, | ||
withGoogle: false, | ||
withFavicon: false | ||
}) | ||
t.is(await getLogo('https://example.com'), undefined) | ||
t.is(JSON.parse(cache.get('https://example.com')).value, null) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict' | ||
|
||
const test = require('ava') | ||
const got = require('got') | ||
|
||
const { google } = require('..') | ||
|
||
test('return undefined under no logo', async t => { | ||
const url = 'https://idontexist.lol' | ||
t.is(await google(url), undefined) | ||
}) | ||
|
||
test('return logo when URL is reachable', async t => { | ||
const url = 'https://microlink.io/' | ||
const logoUrl = await google(url) | ||
t.true(typeof logoUrl === 'string') | ||
|
||
const fallbackUrl = google.url() | ||
const [logo, fallback] = await Promise.all( | ||
[logoUrl, fallbackUrl].map(url => | ||
got(url, { | ||
responseType: 'buffer', | ||
resolveBodyOnly: true, | ||
throwHttpErrors: false | ||
}) | ||
) | ||
) | ||
t.true(logo.length !== fallback.length) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'use strict' | ||
|
||
const test = require('ava') | ||
const got = require('got') | ||
|
||
const { createGetLogo, createRootFavicon, google } = require('..') | ||
|
||
test('enable it by default', async t => { | ||
const getLogo = createGetLogo({ withGoogle: true, withFavicon: true }) | ||
const rootFavicon = createRootFavicon({ getLogo }) | ||
const url = 'https://geolocation-indol.vercel.app/' | ||
const logoUrl = await rootFavicon({ url }) | ||
const domainLogoUrl = google.url('https://vercel.app/') | ||
|
||
const [logo, domainLogo] = await Promise.all( | ||
[logoUrl, domainLogoUrl].map(url => | ||
got(url, { | ||
responseType: 'buffer', | ||
resolveBodyOnly: true, | ||
throwHttpErrors: false | ||
}) | ||
) | ||
) | ||
|
||
t.is(logo.length, domainLogo.length) | ||
}) | ||
|
||
test('exclude certain subdomains', async t => { | ||
const getLogo = createGetLogo({ withGoogle: true, withFavicon: true }) | ||
const rootFavicon = createRootFavicon({ | ||
getLogo, | ||
withRootFavicon: /^vercel\.app/ | ||
}) | ||
const url = 'https://geolocation-indol.vercel.app/' | ||
const logoUrl = await rootFavicon({ url }) | ||
t.is(logoUrl, undefined) | ||
}) | ||
|
||
test('disable it when \'{ withRootFavicon: false}\'', async t => { | ||
const rootFavicon = createRootFavicon({ withRootFavicon: false }) | ||
t.is(rootFavicon, undefined) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.