mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-18 06:44:46 -07:00
Test that local sitemap matches production
This commit is contained in:
parent
3a92fd3613
commit
b004c8ed1a
1 changed files with 40 additions and 0 deletions
40
test/main.js
40
test/main.js
|
|
@ -2,6 +2,7 @@ import { promises as fs } from 'fs'
|
|||
|
||||
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'
|
||||
|
||||
|
|
@ -77,6 +78,45 @@ test('Sitemap contains no double slashes in paths', (t) => {
|
|||
t.pass()
|
||||
})
|
||||
|
||||
|
||||
test('Sitemap mostly matches production', async (t) => {
|
||||
// console.log('t.context.sitemapUrls', t.context.sitemapUrls)
|
||||
|
||||
const theshold = 1
|
||||
|
||||
const urlsNotOnLive = new Set()
|
||||
// const newLocalUrls = new Set()
|
||||
|
||||
const liveSitemapXml = await axios( 'https://doesitarm.com/sitemap.xml' ).then( response => response.data )
|
||||
const liveSitemap = parser.parse( liveSitemapXml )
|
||||
|
||||
// Store sitemap urls to context
|
||||
const liveSitemapUrls = new Map( liveSitemap.urlset.url.map( tag => [ tag.loc, new URL( tag.loc )] ) )
|
||||
|
||||
|
||||
for ( const localUrl of t.context.sitemapUrls ) {
|
||||
const theoreticalLiveUrl = `https://doesitarm.com${ localUrl.pathname }`
|
||||
|
||||
if ( liveSitemapUrls.has( theoreticalLiveUrl ) ) {
|
||||
liveSitemapUrls.delete( theoreticalLiveUrl )
|
||||
continue
|
||||
}
|
||||
|
||||
// localUrl is either: Missing or New
|
||||
urlsNotOnLive.add( theoreticalLiveUrl )
|
||||
|
||||
}
|
||||
|
||||
const message = `${ urlsNotOnLive.size } new or missing from live and ${ liveSitemapUrls.size } not found locally`
|
||||
|
||||
if ( (urlsNotOnLive.size + liveSitemapUrls.size) >= theshold ) {
|
||||
t.fail( message )
|
||||
}
|
||||
|
||||
t.log( message )
|
||||
t.pass()
|
||||
})
|
||||
|
||||
test('All Category pages have valid FAQPage structured data', async (t) => {
|
||||
|
||||
const categoryUrls = t.context.sitemapUrls.filter( url => url.pathname.startsWith('/kind/') )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue