@@ -104,13 +104,35 @@ describe('parseHookNames', () => {
104104 expectHookNamesToEqual ( hookNames , [ 'foo' , 'bar' , 'baz' ] ) ;
105105 } ) ;
106106
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 ( ) => {
108108 const Component = require ( './__source__/__untransformed__/ComponentWithUseEffect' )
109109 . 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+
110116 const hookNames = await getHookNamesForComponent ( Component ) ;
111117 expectHookNamesToEqual ( hookNames , [ ] ) ; // No hooks with names
112118 } ) ;
113119
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+
114136 it ( 'should parse names for custom hooks' , async ( ) => {
115137 const Component = require ( './__source__/__untransformed__/ComponentWithNamedCustomHooks' )
116138 . Component ;
@@ -239,10 +261,10 @@ describe('parseHookNames', () => {
239261 await test (
240262 './__source__/__compiled__/external/ComponentWithMultipleHooksPerLine' ,
241263 ) ; // 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
246268 } ) ;
247269
248270 // TODO Inline require (e.g. require("react").useState()) isn't supported yet.
0 commit comments