mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-18 06:44:46 -07:00
Test that tv pages have valid structured data
This commit is contained in:
parent
6477f7cae7
commit
4575c56a4d
1 changed files with 58 additions and 0 deletions
58
test/main.js
Normal file
58
test/main.js
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
import { promises as fs } from 'fs'
|
||||
|
||||
import test from 'ava'
|
||||
import parser from 'fast-xml-parser'
|
||||
import { structuredDataTest } from 'structured-data-testing-tool'
|
||||
import { Google } from 'structured-data-testing-tool/presets'
|
||||
|
||||
// require('dotenv').config()
|
||||
|
||||
test.before(async t => {
|
||||
const sitemapXml = await fs.readFile('./dist/sitemap.xml', 'utf-8')
|
||||
const sitemap = parser.parse( sitemapXml )
|
||||
|
||||
// Store sitemap urls to context
|
||||
t.context.sitemapUrls = sitemap.urlset.url.map( tag => new URL( tag.loc ) )
|
||||
})
|
||||
|
||||
|
||||
test('All TV pages have valid structured data', async (t, page) => {
|
||||
|
||||
const tvUrls = t.context.sitemapUrls.filter( url => url.pathname.startsWith('/tv/') )
|
||||
|
||||
// console.log('tvUrls', tvUrls )
|
||||
|
||||
for ( const tvUrl of tvUrls ) {
|
||||
|
||||
const pagePath = `./dist${ tvUrl.pathname }/index.html`
|
||||
const pageHtml = await fs.readFile( pagePath , 'utf-8' )
|
||||
|
||||
const result = await structuredDataTest( pageHtml , {
|
||||
// Check for compliance with Google, Twitter and Facebook recommendations
|
||||
presets: [
|
||||
Google
|
||||
],
|
||||
// Check the page includes a specific Schema (see https://schema.org/docs/full.html for a list)
|
||||
schemas: [ 'VideoObject' ]
|
||||
}).then(res => {
|
||||
return res
|
||||
}).catch(err => {
|
||||
console.log( 'err.res.failed', err.res.failed )
|
||||
|
||||
if (err.type === 'VALIDATION_FAILED') {
|
||||
|
||||
t.fail( 'Some structured data tests failed.' )
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
throw new Error( err )
|
||||
})
|
||||
|
||||
// console.log('result', tvUrl.pathname, Object.keys( result ))
|
||||
}
|
||||
|
||||
|
||||
t.pass()
|
||||
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue