@@ -11,10 +11,6 @@ const IGNORED_MODULES = [
11
11
'mersenne' ,
12
12
] ;
13
13
14
- const IGNORED_METHODS = {
15
- system : [ 'directoryPath' , 'filePath' ] , // these are TODOs
16
- } ;
17
-
18
14
function isTestableModule ( mod : string ) {
19
15
return IGNORED_MODULES . indexOf ( mod ) === - 1 ;
20
16
}
@@ -23,27 +19,45 @@ function isMethodOf(mod: string) {
23
19
return ( meth : string ) => typeof faker [ mod ] [ meth ] === 'function' ;
24
20
}
25
21
26
- function isTestableMethod ( mod : string ) {
27
- return ( meth : string ) =>
28
- ! ( mod in IGNORED_METHODS && IGNORED_METHODS [ mod ] . indexOf ( meth ) >= 0 ) ;
29
- }
22
+ const BROKEN_LOCALE_METHODS = {
23
+ // TODO ST-DDT 2022-03-28: these are TODOs (usually broken locale files)
24
+ address : {
25
+ cityPrefix : [ 'pt_BR' , 'pt_PT' ] ,
26
+ citySuffix : [ 'pt_PT' ] ,
27
+ countryCode : [ 'he' ] ,
28
+ state : [ 'az' , 'cz' , 'nb_NO' , 'sk' ] ,
29
+ stateAbbr : [ 'cz' , 'sk' ] ,
30
+ } ,
31
+ company : {
32
+ companySuffix : [ 'az' ] ,
33
+ } ,
34
+ name : {
35
+ prefix : [ 'az' , 'id_ID' , 'ru' ] ,
36
+ suffix : [ 'az' , 'it' , 'mk' , 'pt_PT' , 'ru' ] ,
37
+ } ,
38
+ } ;
30
39
31
- function both (
32
- pred1 : ( meth : string ) => boolean ,
33
- pred2 : ( meth : string ) => boolean
34
- ) : ( meth : string ) => boolean {
35
- return ( value ) => pred1 ( value ) && pred2 ( value ) ;
40
+ function isWorkingLocaleForMethod (
41
+ mod : string ,
42
+ meth : string ,
43
+ locale : string
44
+ ) : boolean {
45
+ return ( BROKEN_LOCALE_METHODS [ mod ] ?. [ meth ] ?? [ ] ) . indexOf ( locale ) === - 1 ;
36
46
}
37
47
38
48
// Basic smoke tests to make sure each method is at least implemented and returns a value.
39
49
40
50
function modulesList ( ) : { [ module : string ] : string [ ] } {
41
51
const modules = Object . keys ( faker )
52
+ . sort ( )
42
53
. filter ( isTestableModule )
43
54
. reduce ( ( result , mod ) => {
44
- result [ mod ] = Object . keys ( faker [ mod ] ) . filter (
45
- both ( isMethodOf ( mod ) , isTestableMethod ( mod ) )
46
- ) ;
55
+ const methods = Object . keys ( faker [ mod ] ) . filter ( isMethodOf ( mod ) ) ;
56
+ if ( methods . length ) {
57
+ result [ mod ] = methods ;
58
+ } else {
59
+ console . log ( `Skipping ${ mod } - No testable methods` ) ;
60
+ }
47
61
return result ;
48
62
} , { } ) ;
49
63
@@ -55,23 +69,29 @@ const modules = modulesList();
55
69
describe ( 'functional tests' , ( ) => {
56
70
for ( const locale in faker . locales ) {
57
71
describe ( locale , ( ) => {
58
- faker . locale = locale ;
59
72
Object . keys ( modules ) . forEach ( ( module ) => {
60
73
describe ( module , ( ) => {
61
- // if there is nothing to test, create a dummy test so the test runner doesn't complain
62
- if ( Object . keys ( modules [ module ] ) . length === 0 ) {
63
- it . todo ( `${ module } was empty` ) ;
64
- }
65
-
66
74
modules [ module ] . forEach ( ( meth ) => {
67
- it ( meth + '()' , ( ) => {
75
+ const testAssertion = ( ) => {
76
+ faker . locale = locale ;
77
+ // TODO ST-DDT 2022-03-28: Use random seed once there are no more failures
78
+ faker . seed ( 1 ) ;
68
79
const result = faker [ module ] [ meth ] ( ) ;
80
+
69
81
if ( meth === 'boolean' ) {
70
82
expect ( result ) . toBeTypeOf ( 'boolean' ) ;
71
83
} else {
72
84
expect ( result ) . toBeTruthy ( ) ;
73
85
}
74
- } ) ;
86
+ } ;
87
+
88
+ if ( isWorkingLocaleForMethod ( module , meth , locale ) ) {
89
+ it ( meth + '()' , testAssertion ) ;
90
+ } else {
91
+ // TODO ST-DDT 2022-03-28: Remove once there are no more failures
92
+ // We expect a failure here to ensure we remove the exclusions when fixed
93
+ it . fails ( meth + '()' , testAssertion ) ;
94
+ }
75
95
} ) ;
76
96
} ) ;
77
97
} ) ;
@@ -82,26 +102,16 @@ describe('functional tests', () => {
82
102
describe ( 'faker.fake functional tests' , ( ) => {
83
103
for ( const locale in faker . locales ) {
84
104
describe ( locale , ( ) => {
85
- faker . locale = locale ;
86
- faker . seed ( 1 ) ;
87
105
Object . keys ( modules ) . forEach ( ( module ) => {
88
106
describe ( module , ( ) => {
89
- // if there is nothing to test, create a dummy test so the test runner doesn't complain
90
- if ( Object . keys ( modules [ module ] ) . length === 0 ) {
91
- it . todo ( `${ module } was empty` ) ;
92
- }
93
-
94
107
modules [ module ] . forEach ( ( meth ) => {
95
108
it ( meth + '()' , ( ) => {
109
+ faker . locale = locale ;
110
+ // TODO ST-DDT 2022-03-28: Use random seed once there are no more failures
111
+ faker . seed ( 1 ) ;
96
112
const result = faker . fake ( '{{' + module + '.' + meth + '}}' ) ;
97
- // just make sure any result is returned
98
- // an undefined result usually means an error
99
- expect ( result ) . toBeDefined ( ) ;
100
- // if (meth === 'boolean') {
101
- // expect(result).toBeTypeOf('boolean');
102
- // } else {
103
- // expect(result).toBeTruthy();
104
- // }
113
+
114
+ expect ( result ) . toBeTypeOf ( 'string' ) ;
105
115
} ) ;
106
116
} ) ;
107
117
} ) ;
0 commit comments