-
-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #719 from microlinkhq/next
fix(logo-favicon): expose resolveFaviconUrl
- Loading branch information
Showing
4 changed files
with
104 additions
and
52 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
37 changes: 37 additions & 0 deletions
37
packages/metascraper-logo-favicon/test/resolve-favicon-url.js
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,37 @@ | ||
'use strict' | ||
|
||
const test = require('ava') | ||
|
||
const { resolveFaviconUrl } = require('..') | ||
const { runServer } = require('./helpers') | ||
|
||
const toUrl = (basename, pathname) => new URL(pathname, basename).toString() | ||
|
||
test('undefined if favicon url is not reachable', async t => { | ||
const url = await runServer(t, async ({ res }) => { | ||
res.statusCode = 404 | ||
res.end('Not Found') | ||
}) | ||
t.is(await resolveFaviconUrl(toUrl(url, 'favico.ico')), undefined) | ||
}) | ||
|
||
test('undefined if content type is not expected', async t => { | ||
const url = await runServer(t, async ({ res }) => { | ||
res.statusCode = 200 | ||
res.setHeader('Content-Type', 'image/svg+xml') | ||
res.end() | ||
}) | ||
t.is(await resolveFaviconUrl(toUrl(url, 'favicon.ico'), []), undefined) | ||
}) | ||
|
||
test('undefined if body is not the expected according to content type', async t => { | ||
const url = await runServer(t, async ({ res }) => { | ||
res.setHeader('content-type', 'image/x-icon') | ||
res.end('<svg></svg>') | ||
}) | ||
|
||
t.is( | ||
await resolveFaviconUrl(`${url}favicon.png`, ['image/x-icon']), | ||
undefined | ||
) | ||
}) |