Skip to content

Commit

Permalink
test: add additional cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Mar 24, 2022
1 parent 9c4a903 commit e08bba6
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const { URL } = require('url')
const test = require('ava')
const got = require('got')

const reachableUrl = require('..')

Expand All @@ -17,6 +18,33 @@ test('resolve GET request', async t => {
t.true(isReachable(res))
})

test('allow to cache', async t => {
const url = 'https://microlink.io/favicon.ico'
const cache = new Map()

const responseOne = await reachableUrl(url, { cache })

t.is(responseOne.isFromCache, false)
t.is(cache.size, 1)

const responseTwo = await reachableUrl(url, { cache })

t.is(responseTwo.isFromCache, true)
t.is(cache.size, 1)
})

test('resolve as fast a HEAD', async t => {
const url = 'https://microlink.io/favicon.ico'

const headResponse = await got.head(url, { throwHttpErrors: false })
const headTime = headResponse.timings.phases.total

const getResponse = await reachableUrl(url)
const getTime = getResponse.timings.phases.total

t.true(getTime <= headTime * 2)
})

test('resolve prerender GET request', async t => {
const url = 'https://www.instagram.com/teslamotors'
const res = await reachableUrl(url)
Expand Down

0 comments on commit e08bba6

Please sign in to comment.