Skip to content

Commit

Permalink
build: add JSON+LD recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Nov 30, 2020
1 parent c0caa34 commit 43c21ae
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
3 changes: 2 additions & 1 deletion by-feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ module.exports = {
getHtml: require('./recipes/by-feature/get-html'),
lighthouseReport: require('./recipes/by-feature/lighthouse-report'),
technologyStack: require('./recipes/by-feature/technology-stack'),
universalEmbed: require('./recipes/by-feature/universal-embed')
universalEmbed: require('./recipes/by-feature/universal-embed'),
jsonLd: require('./recipes/by-feature/json-ld')
}
23 changes: 23 additions & 0 deletions recipes/by-feature/json-ld.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict'

const mql = require('@microlink/mql')

module.exports = async (url, opts) => {
const { data } = await mql(url, {
meta: false,
data: {
jsonLd: {
selectorAll: 'script[type="application/ld+json"]'
}
},
...opts
})

return data.jsonLd
}

module.exports.meta = {
name: 'Get JSON+LD',
description: 'Retrieve all JSON+LD elements present on the website',
examples: ['https://teslahunt.io/5YJSA7E49JF269238']
}
24 changes: 18 additions & 6 deletions test/by-feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const {
getHtml,
lighthouseReport,
technologyStack,
universalEmbed
universalEmbed,
jsonLd
} = require('../by-feature')

const apiKey = process.env.MICROLINK_API_KEY
Expand All @@ -24,26 +25,37 @@ test('universal embed', async t => {
})

test('technology stack', async t => {
const technologies = await technologyStack(technologyStack.meta.examples[0])
const technologies = await technologyStack(technologyStack.meta.examples[0], {
apiKey
})
t.true(ow.isValid(technologies, ow.object.not.empty))
})

test('lighthouse report', async t => {
const report = await lighthouseReport(lighthouseReport.meta.examples[0])
const report = await lighthouseReport(lighthouseReport.meta.examples[0], {
apiKey
})
t.true(ow.isValid(report, ow.object.not.empty))
})

test('get html', async t => {
const html = await getHtml(getHtml.meta.examples[0])
const html = await getHtml(getHtml.meta.examples[0], { apiKey })
t.true(html.startsWith('<!DOCTYPE'))
})

test('fully screenshot', async t => {
const screenshot = await fullyScreenshot(fullyScreenshot.meta.examples[0])
const screenshot = await fullyScreenshot(fullyScreenshot.meta.examples[0], {
apiKey
})
t.true(ow.isValid(screenshot, ow.object.not.empty))
})

test('debug css', async t => {
const screenshot = await debugCss(debugCss.meta.examples[0])
const screenshot = await debugCss(debugCss.meta.examples[0], { apiKey })
t.true(ow.isValid(screenshot, ow.object.not.empty))
})

test('retrieve JSON+lD', async t => {
const data = await jsonLd(jsonLd.meta.examples[0], { apiKey })
t.true(ow.isValid(data, ow.array.not.empty))
})

0 comments on commit 43c21ae

Please sign in to comment.