Skip to content

Commit

Permalink
Merge pull request #2 from Kikobeats/next
Browse files Browse the repository at this point in the history
Update dependencies
  • Loading branch information
Kikobeats committed Dec 11, 2018
2 parents b37539d + 52aaa05 commit e8215fd
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ const fromHEAD = createRequest('head')
const fromGET = createRequest('get')

module.exports = (url, opts = {}) => {
const { href } = new URL(url)
return pAny([fromHEAD(href, opts), fromGET(href, opts)])
const { href: encodedUrl } = new URL(url)
return pAny([fromHEAD(encodedUrl, opts), fromGET(encodedUrl, opts)])
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"url"
],
"dependencies": {
"got": "~9.2.1",
"got": "~9.4.0",
"p-any": "~1.1.0"
},
"devDependencies": {
Expand Down
38 changes: 36 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,43 @@ test('passing options', async t => {
})

test('resolve non encoding urls', async t => {
const url =
const urlOne =
'https://www.metro.se/artikel/pr-experterna-s-försöker-ta-kommando-över-svenskhet-i-valfilm'
const resOne = await reachableUrl(urlOne)
t.is(resOne.url, new URL(resOne.url).href)
t.is(
resOne.url,
'https://www.metro.se/artikel/pr-experterna-s-f%C3%B6rs%C3%B6ker-ta-kommando-%C3%B6ver-svenskhet-i-valfilm'
)
t.is(200, resOne.statusCode)

const urlTwo =
'https://medium.com/@Acegikmo/the-ever-so-lovely-bézier-curve-eb27514da3bf'
const resTwo = await reachableUrl(urlTwo)
t.is(resTwo.url, new URL(resTwo.url).href)
t.is(
resTwo.url,
'https://medium.com/@Acegikmo/the-ever-so-lovely-b%C3%A9zier-curve-eb27514da3bf'
)
t.is(200, resTwo.statusCode)
})

test('resolve already encoded urls', async t => {
const urlThree =
'https://medium.com/@Acegikmo/the-ever-so-lovely-b%C3%A9zier-curve-eb27514da3bf'
const resThree = await reachableUrl(urlThree)
t.is(resThree.url, new URL(resThree.url).href)
t.is(
resThree.url,
'https://medium.com/@Acegikmo/the-ever-so-lovely-b%C3%A9zier-curve-eb27514da3bf'
)
t.is(200, resThree.statusCode)
})

test('keep original query search', async t => {
const url =
'https://www.b92.net/biz/vesti/srbija.php?yyyy=2018&mm=11&dd=05&nav_id=1465369'
const res = await reachableUrl(url)
t.is(res.url, new URL(res.url).href)
t.is(res.url, url)
t.is(200, res.statusCode)
})

0 comments on commit e8215fd

Please sign in to comment.