From e08bba613ee01a60081ad4789139dba5a542953f Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Thu, 24 Mar 2022 13:05:12 +0100 Subject: [PATCH] test: add additional cases --- test/index.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/index.js b/test/index.js index 7265824..3d2629a 100644 --- a/test/index.js +++ b/test/index.js @@ -2,6 +2,7 @@ const { URL } = require('url') const test = require('ava') +const got = require('got') const reachableUrl = require('..') @@ -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)