Test that apps with bundle data have sections

This commit is contained in:
Sam Carlton 2021-07-10 22:53:27 -05:00
parent 149ede5615
commit 8e476abea6

View file

@ -1,14 +1,26 @@
import { promises as fs } from 'fs'
// import { promises as fs } from 'fs'
import fs from 'fs-extra'
import test from 'ava'
import parser from 'fast-xml-parser'
import axios from 'axios'
import { structuredDataTest } from 'structured-data-testing-tool'
import { Google, Twitter } from 'structured-data-testing-tool/presets'
// require('dotenv').config()
require('dotenv').config()
function isString( maybeString ) {
return (typeof maybeString === 'string' || maybeString instanceof String)
}
async function pageContains ( needle, pageUrlString ) {
const pageUrlInstance = new URL( pageUrlString )
const pagePath = `./dist${ pageUrlInstance.pathname }/index.html`
const pageHtml = await fs.readFile( pagePath , 'utf-8' )
return pageHtml.includes( needle )
}
async function testStructuredData ( options ) {
const {
@ -200,3 +212,33 @@ test('All TV pages have valid VideoObject structured data', async (t) => {
t.pass()
})
test('All App pages with bundle data have bundle data visuals', async (t) => {
const appUrls = t.context.sitemapUrls.filter( url => url.pathname.startsWith('/app/') )
const appsWithBundleIds = await fs.readJson('./static/app-list.json', 'utf-8').then( appList => {
return appList.filter( app => {
return app.bundleIds.length > 0
})
})
t.log(`${appsWithBundleIds.length} apps with bundle IDs`)
try {
for ( const app of appsWithBundleIds ) {
const hasAppBundlesSection = await pageContains( 'App Bundles', `${ process.env.URL }${app.endpoint}` )
if ( !hasAppBundlesSection ) throw new Error(`Couldn't find App Bundles section on ${ app.endpoint }`)
}
} catch ( error ) {
console.log('failed', error)
t.fail( error.message )
}
t.log( `${appsWithBundleIds.length} valid app pages` )
t.pass()
})