diff --git a/test/main.js b/test/main.js index 372be3d..80e7318 100644 --- a/test/main.js +++ b/test/main.js @@ -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() + +})