@@ -10,12 +10,36 @@ const IGNORED_MODULES = new Set([
1010 '_defaultRefDate' ,
1111] ) ;
1212
13- function isTestableModule ( mod : string ) {
14- return ! IGNORED_MODULES . has ( mod ) ;
13+ function getMethodNamesByModules ( faker : Faker ) : { [ module : string ] : string [ ] } {
14+ return Object . fromEntries (
15+ Object . keys ( faker )
16+ . filter ( isTestableModule )
17+ . sort ( )
18+ . map < [ string , string [ ] ] > ( ( moduleName ) => [
19+ moduleName ,
20+ getMethodNamesOf ( faker [ moduleName ] ) ,
21+ ] )
22+ . filter ( ( [ module , methods ] ) => {
23+ if ( methods . length === 0 ) {
24+ console . log ( `Skipping ${ module } - No testable methods` ) ;
25+ return false ;
26+ }
27+
28+ return true ;
29+ } )
30+ ) ;
31+ }
32+
33+ function isTestableModule ( moduleName : string ) : moduleName is keyof Faker {
34+ return ! IGNORED_MODULES . has ( moduleName ) ;
35+ }
36+
37+ function getMethodNamesOf ( module : object ) : string [ ] {
38+ return Object . keys ( module ) . filter ( isMethodOf ( module ) ) ;
1539}
1640
17- function isMethodOf ( mod : string ) {
18- return ( meth : string ) => typeof fakerEN [ mod ] [ meth ] === 'function' ;
41+ function isMethodOf ( module : object ) : ( method : string ) => boolean {
42+ return ( method : string ) => typeof module [ method ] === 'function' ;
1943}
2044
2145type SkipConfig < TModule > = Partial <
@@ -53,36 +77,17 @@ const BROKEN_LOCALE_METHODS = {
5377} ;
5478
5579function isWorkingLocaleForMethod (
56- mod : string ,
57- meth : string ,
80+ module : string ,
81+ method : string ,
5882 locale : string
5983) : boolean {
60- const broken = BROKEN_LOCALE_METHODS [ mod ] ?. [ meth ] ?? [ ] ;
84+ const broken = BROKEN_LOCALE_METHODS [ module ] ?. [ method ] ?? [ ] ;
6185 return broken !== '*' && ! broken . includes ( locale ) ;
6286}
6387
6488// Basic smoke tests to make sure each method is at least implemented and returns a value.
6589
66- function modulesList ( ) : { [ module : string ] : string [ ] } {
67- const modules = Object . keys ( fakerEN )
68- . sort ( )
69- . filter ( isTestableModule )
70- . reduce ( ( result , mod ) => {
71- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
72- const methods = Object . keys ( fakerEN [ mod ] ) . filter ( isMethodOf ( mod ) ) ;
73- if ( methods . length > 0 ) {
74- result [ mod ] = methods ;
75- } else {
76- console . log ( `Skipping ${ mod } - No testable methods` ) ;
77- }
78-
79- return result ;
80- } , { } ) ;
81-
82- return modules ;
83- }
84-
85- const modules = modulesList ( ) ;
90+ const modules = getMethodNamesByModules ( fakerEN ) ;
8691
8792describe ( 'BROKEN_LOCALE_METHODS test' , ( ) => {
8893 it ( 'should not contain obsolete configuration (modules)' , ( ) => {
0 commit comments