import fs from 'fs' ; import { getOptions } from '../lib/config/options' ; declare global { namespace jest { type ContainsOption < T > = T extends ArrayLike < unknown > ? T [ number ] : unknown ; interface Matchers < R , T > { param arg toContainOption ( arg ) : void ; } } } const options = getOptions ( ) ; describe ( 'website-docs' , ( ) => { const doc = fs . readFileSync ( 'docs/usage/configuration-options.md' , 'utf8' ) ; const selfHostDoc = fs . readFileSync ( 'docs/usage/self-hosted-configuration.md' , 'utf8' ) ; const headers = doc . match ( /\n## (.*?)\n/g ) . map ( ( match ) => match . substring ( 4 , match . length - 1 ) ) ; const selfHostHeaders = selfHostDoc . match ( /\n## (.*?)\n/g ) . map ( ( match ) => match . substring ( 4 , match . length - 1 ) ) ; const expectedOptions = options . filter ( ( option ) => option . stage !== 'global' ) . filter ( ( option ) => option . releaseStatus !== 'unpublished' ) . filter ( ( option ) => ! option . globalOnly ) . filter ( ( option ) => ! option . parent ) . filter ( ( option ) => ! option . autogenerated ) . map ( ( option ) => option . name ) . sort ( ) ; const selfHostExpectedOptions = options . filter ( ( option ) => option . globalOnly || option . stage === 'global' ) . map ( ( option ) => option . name ) . sort ( ) ; it ( 'has doc headers sorted alphabetically' , ( ) => { expect ( headers ) . toEqual ( [ ... headers ] . sort ( ) ) ; } ) ; it ( 'has headers for every required option' , ( ) => { expect ( headers ) . toEqual ( expectedOptions ) ; } ) ; it ( 'has self hosted doc headers sorted alphabetically' , ( ) => { expect ( selfHostHeaders ) . toEqual ( [ ... selfHostHeaders ] . sort ( ) ) ; } ) ; it ( 'has headers (self hosted) for every required option' , ( ) => { expect ( selfHostHeaders ) . toEqual ( selfHostExpectedOptions ) ; } ) ; const headers3 = doc . match ( /\n### (.*?)\n/g ) . map ( ( match ) => match . substring ( 5 , match . length - 1 ) ) ; headers3 . sort ( ) ; const expectedOptions3 = options . filter ( ( option ) => option . stage !== 'global' ) . filter ( ( option ) => ! option . globalOnly ) . filter ( ( option ) => option . parent ) . map ( ( option ) => option . name ) . sort ( ) ; expectedOptions3 . sort ( ) ; it ( 'has headers for every required sub-option' , ( ) => { expect ( headers3 ) . toEqual ( expectedOptions3 ) ; } ) ; const relatedOptionsMatrix = options . filter ( ( option ) => option . relatedOptions ) . map ( ( option ) => option . relatedOptions ) . sort ( ) ; let relatedOptions = [ ] . concat ( ... relatedOptionsMatrix ) ; relatedOptions = [ ... new Set ( relatedOptions ) ] ; expect . extend ( { toContainOption < T extends string > ( received , argument ) { if ( received . includes ( argument ) ) { return { message : ( ) : string => `Option "${ argument }" should be within options` , pass : true , } ; } return { message : ( ) : string => `Option "${ argument }" doesn't exist within options` , pass : false , } ; } , } ) ; const allOptionNames = options . map ( ( option ) => option . name ) . sort ( ) ; it ( 'has valid relateOptions values' , ( ) => { relatedOptions . forEach ( ( relOption ) => { expect ( allOptionNames ) . toContainOption ( relOption ) ; } ) ; } ) ; } ) ;