Skip to content

Commit

Permalink
Revert "fix: pass a URL instance (#158)"
Browse files Browse the repository at this point in the history
This reverts commit 0c51c64.
  • Loading branch information
Kikobeats committed Mar 28, 2023
1 parent de1650c commit 8e70d3f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ const isFetchMode = url =>
autoDomains.includes(parseUrl(url).domainWithoutSuffix)

const determinateMode = (url, { prerender }) => {
if (prerender === false || isMediaUrl(url.toString())) return 'fetch'
if (prerender === false || isMediaUrl(url)) return 'fetch'
if (prerender === true) return 'prerender'
return isFetchMode(url) ? 'fetch' : 'prerender'
}
Expand Down
74 changes: 35 additions & 39 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,50 +11,46 @@ const wait = async (promise, prop) => {
return prop ? res[prop] : res
}

;[
{ title: 'from URL', url: 'https://example.com' },
{ title: 'from URL instance', url: new URL('https://example.com') }
].forEach(({ title, url }) => {
test(title, async t => {
const [prerenderDisabled, prerenderEnabled] = await Promise.all([
test('reachable URL', async t => {
const url = 'https://example.com'
const [prerenderDisabled, prerenderEnabled] = await Promise.all([
getHTML(url, { prerender: false, getBrowserless }),
getHTML(url, {
prerender: true,
getBrowserless,
puppeteerOpts: { adblock: false }
})
])

t.is(
await wait(
getHTML(url, { prerender: false, getBrowserless }),
'statusCode'
),
200
)
t.is(
await wait(
getHTML(url, {
prerender: true,
getBrowserless,
puppeteerOpts: { adblock: false }
})
])

t.is(
await wait(
getHTML(url, { prerender: false, getBrowserless }),
'statusCode'
),
200
)
t.is(
await wait(
getHTML(url, {
prerender: true,
getBrowserless,
puppeteerOpts: { adblock: false }
}),
'statusCode'
),
200
)

t.is(prerenderDisabled.statusCode, prerenderEnabled.statusCode)
t.is(prerenderDisabled.statusCode, 200)

t.true(Object.keys(prerenderDisabled.headers).length > 0)
t.true(Object.keys(prerenderEnabled.headers).length > 0)
t.is(typeof prerenderDisabled.headers, typeof prerenderEnabled.headers)

t.true(prerenderDisabled.html.length > 0)
t.true(prerenderEnabled.html.length > 0)
t.is(typeof prerenderDisabled.html, typeof prerenderEnabled.html)
})
}),
'statusCode'
),
200
)

t.is(prerenderDisabled.statusCode, prerenderEnabled.statusCode)
t.is(prerenderDisabled.statusCode, 200)

t.true(Object.keys(prerenderDisabled.headers).length > 0)
t.true(Object.keys(prerenderEnabled.headers).length > 0)
t.is(typeof prerenderDisabled.headers, typeof prerenderEnabled.headers)

t.true(prerenderDisabled.html.length > 0)
t.true(prerenderEnabled.html.length > 0)
t.is(typeof prerenderDisabled.html, typeof prerenderEnabled.html)
})

test('timeout URL', async t => {
Expand Down

0 comments on commit 8e70d3f

Please sign in to comment.