@@ -17,13 +17,30 @@ describe('fictReactPreset', () => {
1717
1818 const plugins = fictReactPreset ( )
1919
20- expect ( plugins ) . toHaveLength ( 1 )
20+ expect ( plugins ) . toHaveLength ( 2 )
2121 expect ( reactPluginMock ) . toHaveBeenCalledTimes ( 1 )
2222 expect ( reactPluginMock ) . toHaveBeenCalledWith (
2323 expect . objectContaining ( {
2424 include : [ / s r c \/ r e a c t \/ .* \. [ j t ] s x ? $ / ] ,
2525 } ) ,
2626 )
27+
28+ const depsPlugin = plugins [ 1 ] as { config : ( ) => Record < string , unknown > }
29+ expect ( depsPlugin . config ( ) ) . toEqual ( {
30+ resolve : {
31+ dedupe : [ 'react' , 'react-dom' ] ,
32+ } ,
33+ optimizeDeps : {
34+ include : [
35+ 'react' ,
36+ 'react-dom' ,
37+ 'react-dom/client' ,
38+ 'react-dom/server' ,
39+ 'react/jsx-runtime' ,
40+ 'react/jsx-dev-runtime' ,
41+ ] ,
42+ } ,
43+ } )
2744 } )
2845
2946 it ( 'passes through include/exclude/extra options' , async ( ) => {
@@ -45,4 +62,28 @@ describe('fictReactPreset', () => {
4562 } ) ,
4663 )
4764 } )
65+
66+ it ( 'allows disabling and overriding dependency optimization hints' , async ( ) => {
67+ const { fictReactPreset } = await import ( '../src/preset' )
68+
69+ const disabled = fictReactPreset ( {
70+ optimizeReactDeps : false ,
71+ } )
72+ expect ( disabled ) . toHaveLength ( 1 )
73+
74+ const customized = fictReactPreset ( {
75+ reactDedupe : [ 'react' ] ,
76+ reactOptimizeDepsInclude : [ 'react' , 'react/jsx-runtime' ] ,
77+ } )
78+ expect ( customized ) . toHaveLength ( 2 )
79+ const depsPlugin = customized [ 1 ] as { config : ( ) => Record < string , unknown > }
80+ expect ( depsPlugin . config ( ) ) . toEqual ( {
81+ resolve : {
82+ dedupe : [ 'react' ] ,
83+ } ,
84+ optimizeDeps : {
85+ include : [ 'react' , 'react/jsx-runtime' ] ,
86+ } ,
87+ } )
88+ } )
4889} )
0 commit comments