@@ -24,59 +24,98 @@ describe('CodegenActions', () => {
24
24
const reactComponents = await actions . getReactComponentsFromFile ( `${ absolutePathPrefix } /counter-class.jsx` )
25
25
26
26
expect ( reactComponents ) . to . have . length ( 1 )
27
- expect ( reactComponents [ 0 ] . displayName ) . to . equal ( 'Counter' )
27
+ expect ( reactComponents [ 0 ] . exportName ) . to . equal ( 'Counter' )
28
+ expect ( reactComponents [ 0 ] . isDefault ) . to . equal ( false )
28
29
} )
29
30
30
31
it ( 'returns React components from file with functional component' , async ( ) => {
31
32
const reactComponents = await actions . getReactComponentsFromFile ( `${ absolutePathPrefix } /counter-functional.jsx` )
32
33
33
34
expect ( reactComponents ) . to . have . length ( 1 )
34
- expect ( reactComponents [ 0 ] . displayName ) . to . equal ( 'Counter' )
35
+ expect ( reactComponents [ 0 ] . exportName ) . to . equal ( 'Counter' )
36
+ expect ( reactComponents [ 0 ] . isDefault ) . to . equal ( false )
35
37
} )
36
38
37
39
it ( 'returns only exported React components from file with functional components' , async ( ) => {
38
40
const reactComponents = await actions . getReactComponentsFromFile ( `${ absolutePathPrefix } /counter-multiple-components.jsx` )
39
41
40
42
expect ( reactComponents ) . to . have . length ( 2 )
41
- expect ( reactComponents [ 0 ] . displayName ) . to . equal ( 'CounterContainer' )
42
- expect ( reactComponents [ 1 ] . displayName ) . to . equal ( 'CounterView' )
43
- } )
44
-
45
- it ( 'returns both named and default exports' , async ( ) => {
46
- const reactComponents = await actions . getReactComponentsFromFile ( `${ absolutePathPrefix } /counter-mixed-multiple-components.tsx` )
43
+ expect ( reactComponents [ 0 ] . exportName ) . to . equal ( 'CounterContainer' )
44
+ expect ( reactComponents [ 0 ] . isDefault ) . to . equal ( false )
47
45
48
- expect ( reactComponents ) . to . have . length ( 2 )
49
- expect ( reactComponents [ 0 ] . displayName ) . to . equal ( 'CounterContainer' )
50
- expect ( reactComponents [ 1 ] . displayName ) . to . equal ( 'CounterView' )
46
+ expect ( reactComponents [ 1 ] . exportName ) . to . equal ( 'CounterView' )
47
+ expect ( reactComponents [ 1 ] . isDefault ) . to . equal ( false )
51
48
} )
52
49
53
50
it ( 'returns React components from a tsx file' , async ( ) => {
54
51
const reactComponents = await actions . getReactComponentsFromFile ( `${ absolutePathPrefix } /counter.tsx` )
55
52
56
53
expect ( reactComponents ) . to . have . length ( 1 )
57
- expect ( reactComponents [ 0 ] . displayName ) . to . equal ( 'Counter' )
54
+ expect ( reactComponents [ 0 ] . exportName ) . to . equal ( 'Counter' )
55
+ expect ( reactComponents [ 0 ] . isDefault ) . to . equal ( false )
58
56
} )
59
57
60
58
it ( 'returns React components that are exported by default' , async ( ) => {
61
- const reactComponents = await actions . getReactComponentsFromFile ( `${ absolutePathPrefix } /counter-default.tsx` )
59
+ let reactComponents = await actions . getReactComponentsFromFile ( `${ absolutePathPrefix } /counter-default.tsx` )
60
+
61
+ expect ( reactComponents ) . to . have . length ( 1 )
62
+ expect ( reactComponents [ 0 ] . exportName ) . to . equal ( 'CounterDefault' )
63
+ expect ( reactComponents [ 0 ] . isDefault ) . to . equal ( true )
62
64
65
+ reactComponents = await actions . getReactComponentsFromFile ( `${ absolutePathPrefix } /default-anonymous.jsx` )
63
66
expect ( reactComponents ) . to . have . length ( 1 )
64
- expect ( reactComponents [ 0 ] . displayName ) . to . equal ( 'CounterDefault' )
67
+ expect ( reactComponents [ 0 ] . exportName ) . to . equal ( 'Component' )
68
+ expect ( reactComponents [ 0 ] . isDefault ) . to . equal ( true )
69
+
70
+ reactComponents = await actions . getReactComponentsFromFile ( `${ absolutePathPrefix } /default-function.jsx` )
71
+ expect ( reactComponents ) . to . have . length ( 1 )
72
+ expect ( reactComponents [ 0 ] . exportName ) . to . equal ( 'HelloWorld' )
73
+ expect ( reactComponents [ 0 ] . isDefault ) . to . equal ( true )
74
+
75
+ reactComponents = await actions . getReactComponentsFromFile ( `${ absolutePathPrefix } /default-class.jsx` )
76
+ expect ( reactComponents ) . to . have . length ( 1 )
77
+ expect ( reactComponents [ 0 ] . exportName ) . to . equal ( 'HelloWorld' )
78
+ expect ( reactComponents [ 0 ] . isDefault ) . to . equal ( true )
79
+
80
+ reactComponents = await actions . getReactComponentsFromFile ( `${ absolutePathPrefix } /default-specifier.jsx` )
81
+ expect ( reactComponents ) . to . have . length ( 1 )
82
+ expect ( reactComponents [ 0 ] . exportName ) . to . equal ( 'HelloWorld' )
83
+ expect ( reactComponents [ 0 ] . isDefault ) . to . equal ( true )
65
84
} )
66
85
67
86
it ( 'returns React components defined with arrow functions' , async ( ) => {
68
87
const reactComponents = await actions . getReactComponentsFromFile ( `${ absolutePathPrefix } /counter-arrow-function.jsx` )
69
88
70
89
expect ( reactComponents ) . to . have . length ( 1 )
71
- expect ( reactComponents [ 0 ] . displayName ) . to . equal ( 'Counter' )
90
+ expect ( reactComponents [ 0 ] . exportName ) . to . equal ( 'Counter' )
91
+ expect ( reactComponents [ 0 ] . isDefault ) . to . equal ( false )
72
92
} )
73
93
74
94
it ( 'returns React components from a file with multiple separate export statements' , async ( ) => {
75
95
const reactComponents = await actions . getReactComponentsFromFile ( `${ absolutePathPrefix } /counter-separate-exports.jsx` )
76
96
77
97
expect ( reactComponents ) . to . have . length ( 2 )
78
- expect ( reactComponents [ 0 ] . displayName ) . to . equal ( 'CounterView' )
79
- expect ( reactComponents [ 1 ] . displayName ) . to . equal ( 'CounterContainer' )
98
+ expect ( reactComponents [ 0 ] . exportName ) . to . equal ( 'CounterView' )
99
+ expect ( reactComponents [ 0 ] . isDefault ) . to . equal ( false )
100
+ expect ( reactComponents [ 1 ] . exportName ) . to . equal ( 'CounterContainer' )
101
+ expect ( reactComponents [ 1 ] . isDefault ) . to . equal ( true )
102
+ } )
103
+
104
+ it ( 'returns React components that are exported and aliased' , async ( ) => {
105
+ const reactComponents = await actions . getReactComponentsFromFile ( `${ absolutePathPrefix } /export-alias.jsx` )
106
+
107
+ expect ( reactComponents ) . to . have . length ( 1 )
108
+ expect ( reactComponents [ 0 ] . exportName ) . to . equal ( 'HelloWorld' )
109
+ expect ( reactComponents [ 0 ] . isDefault ) . to . equal ( false )
110
+ } )
111
+
112
+ // TODO: "react-docgen" will resolve HOCs but our export detection does not. Can fall back to displayName here
113
+ it . skip ( 'handles higher-order-components' , async ( ) => {
114
+ const reactComponents = await actions . getReactComponentsFromFile ( `${ absolutePathPrefix } /counter-hoc.jsx` )
115
+
116
+ expect ( reactComponents ) . to . have . length ( 1 )
117
+ expect ( reactComponents [ 0 ] . exportName ) . to . equal ( 'Counter' )
118
+ expect ( reactComponents [ 0 ] . isDefault ) . to . equal ( true )
80
119
} )
81
120
82
121
it ( 'does not throw while parsing empty file' , async ( ) => {
0 commit comments