mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-18 06:44:46 -07:00
Test for non-alpanumeric characters in readme
This commit is contained in:
parent
b7471132c1
commit
4cbde7c8f5
3 changed files with 257 additions and 157 deletions
79
test/prebuild.js
Normal file
79
test/prebuild.js
Normal 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()
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue