@@ -105,28 +105,58 @@ describe('build', () => {
105
105
) . rejects . toThrow ( 'Cannot find module' ) ;
106
106
} ) ;
107
107
108
- it ( 'should merge webpack custom config' , async ( ) => {
109
- const script = `module.exports = () => console.log("hello world")` ;
110
- await writeFileInFunctions ( script , 'index.js' ) ;
108
+ describe ( 'webpack custom config merge' , ( ) => {
109
+ it ( 'should merge plugins' , async ( ) => {
110
+ const script = `module.exports = () => console.log("hello world")` ;
111
+ await writeFileInFunctions ( script , 'index.js' ) ;
112
+
113
+ const webpackConfig = `
114
+ const webpack = require('webpack');
115
+ module.exports = { plugins: [new webpack.EnvironmentPlugin(['NODE_ENV'])] };
116
+ ` ;
117
+
118
+ const suffix = expect . getState ( ) . currentTestName . replace ( / \s + / g, '_' ) ;
119
+ const userWebpackConfig = await writeFileInBuild (
120
+ webpackConfig ,
121
+ `webpack/webpack_${ suffix } .js` ,
122
+ ) ;
123
+
124
+ const stats = await build . run ( functions , {
125
+ userWebpackConfig,
126
+ } ) ;
127
+ expect ( stats . compilation . errors ) . toHaveLength ( 0 ) ;
128
+ expect ( stats . compilation . options . plugins ) . toHaveLength ( 3 ) ;
129
+ expect (
130
+ stats . compilation . options . plugins . map (
131
+ ( plugin ) => plugin . constructor . name ,
132
+ ) ,
133
+ ) . toEqual ( [ 'IgnorePlugin' , 'DefinePlugin' , 'EnvironmentPlugin' ] ) ;
134
+ } ) ;
111
135
112
- const webpackConfig = `module.exports = { resolve: { extensions: ['.custom'] } }` ;
113
- const userWebpackConfig = await writeFileInBuild (
114
- webpackConfig ,
115
- 'webpack/webpack.js' ,
116
- ) ;
136
+ it ( 'should merge resolve extensions' , async ( ) => {
137
+ const script = `module.exports = () => console.log("hello world")` ;
138
+ await writeFileInFunctions ( script , 'index.js' ) ;
117
139
118
- const stats = await build . run ( functions , {
119
- userWebpackConfig,
140
+ const webpackConfig = `module.exports = { resolve: { extensions: ['.custom'] } }` ;
141
+ const suffix = expect . getState ( ) . currentTestName . replace ( / \s + / g, '_' ) ;
142
+ const userWebpackConfig = await writeFileInBuild (
143
+ webpackConfig ,
144
+ `webpack/webpack_${ suffix } .js` ,
145
+ ) ;
146
+
147
+ const stats = await build . run ( functions , {
148
+ userWebpackConfig,
149
+ } ) ;
150
+ expect ( stats . compilation . errors ) . toHaveLength ( 0 ) ;
151
+ expect ( stats . compilation . options . resolve . extensions ) . toEqual ( [
152
+ '.wasm' ,
153
+ '.mjs' ,
154
+ '.js' ,
155
+ '.json' ,
156
+ '.ts' ,
157
+ '.custom' ,
158
+ ] ) ;
120
159
} ) ;
121
- expect ( stats . compilation . errors ) . toHaveLength ( 0 ) ;
122
- expect ( stats . compilation . options . resolve . extensions ) . toEqual ( [
123
- '.wasm' ,
124
- '.mjs' ,
125
- '.js' ,
126
- '.json' ,
127
- '.ts' ,
128
- '.custom' ,
129
- ] ) ;
130
160
} ) ;
131
161
132
162
describe ( 'babel config file resolution' , ( ) => {
0 commit comments