Test for non-alpanumeric characters in readme

This commit is contained in:
Sam Carlton 2021-11-28 20:46:17 -06:00
parent b7471132c1
commit 4cbde7c8f5
3 changed files with 257 additions and 157 deletions

79
test/prebuild.js Normal file
View file

@ -0,0 +1,79 @@
import fs from 'fs-extra'
import test from 'ava'
// import MarkdownIt from 'markdown-it'
import { buildReadmeAppList } from '../helpers/build-app-list.js'
require('dotenv').config()
// const md = new MarkdownIt()
const allowedTitleCharacters = new Set( 'ABCDEFGHIJKMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 -.'.split('') )
function isString( maybeString ) {
return (typeof maybeString === 'string' || maybeString instanceof String)
}
test.before(async t => {
const readmeFileContent = await fs.readFile('./README.md', 'utf-8')
// const readmeMarkdown = md.parse( readmeFileContent )
// t.log( 'readmeMarkdown', readmeMarkdown )
// Store sitemap urls to context
t.context.readmeFileContent = readmeFileContent
})
test('README App Titles are alphanumeric only', (t) => {
// console.log('t.context.sitemapUrls', t.context.sitemapUrls)
const readmeAppList = buildReadmeAppList({
readmeContent: t.context.readmeFileContent,
scanListMap: new Map(),
commits: []
})
// console.log('readmeAppList', readmeAppList)
t.log('readmeAppList', readmeAppList.length)
for (const readmeApp of readmeAppList) {
const cleanedAppName = readmeApp.name//.toLowerCase()
// const firstInvisbleCharacterIndex = cleanedAppName.search( invisibleCharacerRegex )
// const standardSpaceCharCode = 32
for ( const character of cleanedAppName ) {
if ( !allowedTitleCharacters.has( character ) ) {
// badCharacter = readmeApp.name[firstBadCharacterIndex]
// t.log( readmeApp )
t.fail(`README App Title ${readmeApp.name} has non-alphanumeric character ${character}(charCode ${character.charCodeAt(0)})`)
break
}
}
// if ( readmeApp.name.includes('Apple Trans') ) {
// const normalNameLength = 'Apple Transporter'.length
// t.log( 'normalNameLength', normalNameLength )
// t.log( readmeApp.name, readmeApp.name.length )
// }
}
// const urlsWithDoubleSlashes = t.context.sitemapUrls.filter( url => url.pathname.includes('//') )
// if ( urlsWithDoubleSlashes.length > 0) {
// t.fail( `${ urlsWithDoubleSlashes.length } urls with doubles slashes found including ${ urlsWithDoubleSlashes[0] }` )
// }
t.log( `${readmeAppList.length} valid alpanumeric app titles in readme` )
t.pass()
})