@@ -89,5 +89,44 @@ describe('build', () => {
89
89
'.custom' ,
90
90
] ) ;
91
91
} ) ;
92
+
93
+ describe ( "babel config file resolution" , ( ) => {
94
+ const findBabelLoaderRule = rules => rules . find ( rule => rule . use . loader . includes ( "babel-loader" ) ) ;
95
+
96
+ it ( "should alter the default babelOpts when no valid babel config file is found" , async ( ) => {
97
+ setupFunction ( "" , "not-babel.config.js" ) ;
98
+
99
+ const stats = await build . run ( functions ) ;
100
+ const babelLoaderRuleOptions = findBabelLoaderRule ( stats . compilation . options . module . rules ) . use . options ;
101
+
102
+ expect ( babelLoaderRuleOptions . presets ) . toBeDefined ( ) ;
103
+ expect ( babelLoaderRuleOptions . plugins ) . toBeDefined ( ) ;
104
+ } ) ;
105
+
106
+ it ( "should not alter the default babelOpts when a valid babel config file is found in same directory as the functions directory" , async ( ) => {
107
+ setupFunction ( "" , "babel.config.js" ) ;
108
+
109
+ const stats = await build . run ( functions ) ;
110
+ const babelLoaderRuleOptions = findBabelLoaderRule ( stats . compilation . options . module . rules ) . use . options ;
111
+
112
+ expect ( babelLoaderRuleOptions . presets ) . toBeUndefined ( ) ;
113
+ expect ( babelLoaderRuleOptions . plugins ) . toBeUndefined ( ) ;
114
+ } ) ;
115
+
116
+ it ( "should not alter the default babelOpts when a valid babel config is found in directory above the functions directory" , async ( ) => {
117
+ setupFunction ( "" , "babel.config.js" ) ;
118
+
119
+ const functionsSubDir = path . join ( functions , "subdir" ) ;
120
+
121
+ fs . mkdirSync ( functionsSubDir ) ;
122
+ fs . writeFileSync ( path . join ( functionsSubDir , "index.js" ) , "" ) ;
123
+
124
+ const stats = await build . run ( functionsSubDir ) ;
125
+ const babelLoaderRuleOptions = findBabelLoaderRule ( stats . compilation . options . module . rules ) . use . options ;
126
+
127
+ expect ( babelLoaderRuleOptions . presets ) . toBeUndefined ( ) ;
128
+ expect ( babelLoaderRuleOptions . plugins ) . toBeUndefined ( ) ;
129
+ } ) ;
130
+ } )
92
131
} ) ;
93
132
} ) ;
0 commit comments