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