@@ -104,13 +104,35 @@ describe('parseHookNames', () => {
104
104
expectHookNamesToEqual ( hookNames , [ 'foo' , 'bar' , 'baz' ] ) ;
105
105
} ) ;
106
106
107
- it ( 'should return null for hooks without names like useEffect' , async ( ) => {
107
+ it ( 'should skip loading source files for unnamed hooks like useEffect' , async ( ) => {
108
108
const Component = require ( './__source__/__untransformed__/ComponentWithUseEffect' )
109
109
. Component ;
110
+
111
+ // Since this component contains only unnamed hooks, the source code should not even be loaded.
112
+ fetchMock . mockIf ( / .+ $ / , request => {
113
+ throw Error ( `Unexpected file request for "${ request . url } "` ) ;
114
+ } ) ;
115
+
110
116
const hookNames = await getHookNamesForComponent ( Component ) ;
111
117
expectHookNamesToEqual ( hookNames , [ ] ) ; // No hooks with names
112
118
} ) ;
113
119
120
+ it ( 'should skip loading source files for unnamed hooks like useEffect (alternate)' , async ( ) => {
121
+ const Component = require ( './__source__/__untransformed__/ComponentWithExternalUseEffect' )
122
+ . Component ;
123
+
124
+ fetchMock . mockIf ( / .+ $ / , request => {
125
+ // Since th custom hook contains only unnamed hooks, the source code should not be loaded.
126
+ if ( request . url . endsWith ( 'useCustom.js' ) ) {
127
+ throw Error ( `Unexpected file request for "${ request . url } "` ) ;
128
+ }
129
+ return Promise . resolve ( requireText ( request . url , 'utf8' ) ) ;
130
+ } ) ;
131
+
132
+ const hookNames = await getHookNamesForComponent ( Component ) ;
133
+ expectHookNamesToEqual ( hookNames , [ 'count' , null ] ) ; // No hooks with names
134
+ } ) ;
135
+
114
136
it ( 'should parse names for custom hooks' , async ( ) => {
115
137
const Component = require ( './__source__/__untransformed__/ComponentWithNamedCustomHooks' )
116
138
. Component ;
@@ -239,10 +261,10 @@ describe('parseHookNames', () => {
239
261
await test (
240
262
'./__source__/__compiled__/external/ComponentWithMultipleHooksPerLine' ,
241
263
) ; // external source map
242
- await test (
243
- './__source__/__compiled__/bundle' ,
244
- 'ComponentWithMultipleHooksPerLine' ,
245
- ) ; // bundle source map
264
+ // await test(
265
+ // './__source__/__compiled__/bundle',
266
+ // 'ComponentWithMultipleHooksPerLine',
267
+ // ); // bundle source map
246
268
} ) ;
247
269
248
270
// TODO Inline require (e.g. require("react").useState()) isn't supported yet.
0 commit comments