Skip to content

Commit

Permalink
test: use a valid mp4 video url
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Jun 12, 2019
1 parent aaa7107 commit 5b1ecfd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 100
max_line_length = 80
indent_brace_style = 1TBS
spaces_around_operators = true
quote_type = auto
Expand Down
8 changes: 6 additions & 2 deletions src/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ const addMedia = (media, { $, url, headers, body }) => {

const ogMediaType = $(`meta[property="og:${media}:type"]`)
if (!ogMediaType.length) {
tags.push(`<meta property="og:${media}:type" content="${headers['content-type']}">`)
tags.push(
`<meta property="og:${media}:type" content="${headers['content-type']}">`
)
}

const head = $('head')
Expand All @@ -87,7 +89,9 @@ const htmlTemplate = () => `
module.exports = ({ html, url, headers }) => {
const contentType = headers['content-type'] || 'text/html'
const hasHTML =
mimeTypes.extension(contentType) === 'html' && typeof html === 'string' && html.length > 0
mimeTypes.extension(contentType) === 'html' &&
typeof html === 'string' &&
html.length > 0

const content = hasHTML ? html : htmlTemplate()

Expand Down
35 changes: 27 additions & 8 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,28 @@ test('unreachable urls', async t => {
</html>
`

t.deepEqual(prettyHtml(await wait(getHTML(url, { prerender: false }), 'html')), prettyHtml(html))
t.deepEqual(prettyHtml(await wait(getHTML(url, { prerender: true }), 'html')), prettyHtml(html))
t.deepEqual(
prettyHtml(await wait(getHTML(url, { prerender: false }), 'html')),
prettyHtml(html)
)
t.deepEqual(
prettyHtml(await wait(getHTML(url, { prerender: true }), 'html')),
prettyHtml(html)
)
})

test('decode base64 entities', async t => {
const url =
'https://gist.githubusercontent.com/Kikobeats/912a6c2158de3f3c30d0d7c7697af393/raw/d47d9df77696d9a42df192b7aedbf6cfd2ad393e/index.html'

const fetch = prettyHtml(await wait(getHTML(url, { prerender: false }), 'html'))
t.true(fetch.includes('<meta property="og:site_name" content="githubusercontent.com">'))
const fetch = prettyHtml(
await wait(getHTML(url, { prerender: false }), 'html')
)
t.true(
fetch.includes(
'<meta property="og:site_name" content="githubusercontent.com">'
)
)
t.true(fetch.includes('<meta property="article:published_time"'))
t.true(fetch.includes('<meta property="article:expiration_time"'))
t.true(fetch.includes('<meta property="og:locale" content="en">'))
Expand All @@ -88,8 +100,14 @@ test('decode base64 entities', async t => {
)
)

const prerender = prettyHtml(await wait(getHTML(url, { prerender: false }), 'html'))
t.true(prerender.includes('<meta property="og:site_name" content="githubusercontent.com">'))
const prerender = prettyHtml(
await wait(getHTML(url, { prerender: false }), 'html')
)
t.true(
prerender.includes(
'<meta property="og:site_name" content="githubusercontent.com">'
)
)
t.true(prerender.includes('<meta property="article:published_time"'))
t.true(prerender.includes('<meta property="article:expiration_time"'))
t.true(prerender.includes('<meta property="og:locale" content="en">'))
Expand All @@ -106,7 +124,8 @@ test('decode base64 entities', async t => {
})

test('unencoded URL', async t => {
const url = 'https://medium.com/@Acegikmo/the-ever-so-lovely-bézier-curve-eb27514da3bf'
const url =
'https://medium.com/@Acegikmo/the-ever-so-lovely-bézier-curve-eb27514da3bf'
t.is(
await wait(getHTML(url, { prerender: false }), 'url'),
'https://medium.com/@Acegikmo/the-ever-so-lovely-b%C3%A9zier-curve-eb27514da3bf'
Expand Down Expand Up @@ -136,7 +155,7 @@ test('get html from image url', async t => {
})

test('get html from video url', async t => {
const url = 'https://cdn.microlink.io/meta/preview.mp4'
const url = 'http://techslides.com/demos/sample-videos/small.mp4'
const { url: urlDetected, stats, html } = await getHTML(url, {
prerender: false
})
Expand Down

0 comments on commit 5b1ecfd

Please sign in to comment.