@@ -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
+ // 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,29 +69,27 @@ const modules = modulesList();
55
69
describe ( 'functional tests' , ( ) => {
56
70
for ( const locale in faker . locales ) {
57
71
describe ( locale , ( ) => {
58
- // TODO: Enable after https://github.com/faker-js/faker/pull/269
59
- //it('title', () => {
60
- // faker.locale = locale;
61
- // expect(faker.definitions.title).toBe(faker.locales[locale].title);
62
- //});
63
-
64
72
Object . keys ( modules ) . forEach ( ( module ) => {
65
73
describe ( module , ( ) => {
66
- // if there is nothing to test, create a dummy test so the test runner doesn't complain
67
- if ( Object . keys ( modules [ module ] ) . length === 0 ) {
68
- it . todo ( `${ module } was empty` ) ;
69
- }
70
-
71
74
modules [ module ] . forEach ( ( meth ) => {
72
- it ( meth + '()' , ( ) => {
75
+ const testAssertion = ( ) => {
73
76
faker . locale = locale ;
77
+ faker . seed ( 1 ) ;
74
78
const result = faker [ module ] [ meth ] ( ) ;
79
+
75
80
if ( meth === 'boolean' ) {
76
81
expect ( result ) . toBeTypeOf ( 'boolean' ) ;
77
82
} else {
78
83
expect ( result ) . toBeTruthy ( ) ;
79
84
}
80
- } ) ;
85
+ } ;
86
+
87
+ if ( isWorkingLocaleForMethod ( module , meth , locale ) ) {
88
+ it ( meth + '()' , testAssertion ) ;
89
+ } else {
90
+ // TODO: Remove once there are no more failures
91
+ it . fails ( meth + '()' , testAssertion ) ;
92
+ }
81
93
} ) ;
82
94
} ) ;
83
95
} ) ;
@@ -88,26 +100,15 @@ describe('functional tests', () => {
88
100
describe ( 'faker.fake functional tests' , ( ) => {
89
101
for ( const locale in faker . locales ) {
90
102
describe ( locale , ( ) => {
91
- faker . locale = locale ;
92
- faker . seed ( 1 ) ;
93
103
Object . keys ( modules ) . forEach ( ( module ) => {
94
104
describe ( module , ( ) => {
95
- // if there is nothing to test, create a dummy test so the test runner doesn't complain
96
- if ( Object . keys ( modules [ module ] ) . length === 0 ) {
97
- it . todo ( `${ module } was empty` ) ;
98
- }
99
-
100
105
modules [ module ] . forEach ( ( meth ) => {
101
106
it ( meth + '()' , ( ) => {
107
+ faker . locale = locale ;
108
+ faker . seed ( 1 ) ; // TODO: Use random seed once there are no more failures
102
109
const result = faker . fake ( '{{' + module + '.' + meth + '}}' ) ;
103
- // just make sure any result is returned
104
- // an undefined result usually means an error
110
+
105
111
expect ( result ) . toBeTypeOf ( 'string' ) ;
106
- // if (meth === 'boolean') {
107
- // expect(result).toBeTypeOf('boolean');
108
- // } else {
109
- // expect(result).toBeTruthy();
110
- // }
111
112
} ) ;
112
113
} ) ;
113
114
} ) ;
0 commit comments